Saltar al contenido principal

How Fast Can You Promise? Group Commit and the Durability Dial

· 11 min de lectura
Clustron Team
Ingeniería de Sistemas Distribuidos

A durable write is a promise that the value will still be there after the machine that accepted it dies. Keeping that promise means the data has to reach something that outlives process memory — a disk whose contents survive a crash, or enough other nodes that no single loss takes the only copy — before the client hears "yes." The word "before" is the whole cost. A value sitting in RAM, or even in the operating system's page cache, is not durable: a power cut or a kernel panic takes it, and the client was told it was safe. To actually keep the promise, the server has to force the data past those volatile layers to stable storage, and that force operation — fsync, FlushFileBuffers, a replicated ack — is one of the slowest things the server ever does.

How slow matters enormously. A flush to a real disk is often a millisecond or more, because it waits for the device to confirm the bytes are physically persisted, not merely handed off. A millisecond does not sound like much until you divide: a write path that performs exactly one flush per write, and waits for it before acknowledging, is capped at roughly a thousand durable writes a second per flushing thread, and adding cores does not help, because the cores are not computing — they are all blocked on the same slow device. The server looks idle and performs terribly, and the CPU graph that should be the bottleneck is flat.

The tempting escape is to stop flushing — acknowledge the write as soon as it is in memory and let the disk catch up whenever. Throughput soars, and the durability promise silently becomes a lie: every acknowledged-but-unflushed write is one crash away from vanishing, which is precisely the acknowledged-then-lost data that durability existed to prevent. Group commit is the way to have the throughput without telling the lie.

One flush, many writes​

The insight behind group commit is that a flush is a fixed, enormous cost that does not get much more expensive when it carries more data. Flushing one write costs a millisecond; flushing a hundred writes batched together costs almost the same millisecond, because the dominant cost is the round-trip to the storage device, not the volume of bytes. So the server stops flushing per write. Instead, incoming writes are appended to an in-memory buffer and their clients are held — not yet acknowledged. A commit thread flushes the whole accumulated buffer with a single force operation, and the instant that flush returns, it acknowledges every write in the batch at once. One expensive operation just made a hundred writes durable, so the per-write share of the flush cost dropped by a hundredfold, and durable throughput rises from a thousand writes a second toward the device's real streaming bandwidth.

Nothing about the promise weakened. Every client was still told "yes" only after its write was physically on stable storage — the flush genuinely completed before any ack in the batch went out. The batch did not trade durability for speed; it amortized a fixed cost over many writes, which is a different thing entirely. The writer never sees a faster-but-weaker guarantee; it sees the same guarantee, delivered to many writers for the price of one flush.

Four writes, one flush — each client is held until the batch is durable, then all four are acked togetherW1W2W3W4held, not yet ackedin-memorybufferone fsync≈ 1 msflush returns → durableack all 4naive path: one flush per write = 4 separate milliseconds, cores blocked on the device the whole timegroup commit: per-write flush cost falls as the batch grows, and every ack still follows a real flush

The latency the batch adds, and how to bound it​

Group commit is not free either, and the cost lands on latency rather than durability. A write that arrives at the start of a batch window has to wait for the window to fill and for the flush to complete before it is acknowledged, so its individual latency is slightly worse than if it had been flushed alone the instant it arrived. The server is deliberately making each write wait a little so that many writes can share one flush — trading a small, bounded latency increase for a large throughput gain.

The dial that controls this is how long the server is willing to wait before flushing. Flush too eagerly — after every write, or after a microsecond — and batches stay tiny and the amortization never happens. Wait too long and latency balloons for no extra throughput once the batch is already large. The good designs make the window adaptive and self-tuning: flush as soon as either a size threshold or a short time threshold is hit, and under heavy load let the duration of the previous flush set the next window, because while one flush is in flight every newly arriving write is free to join the next batch at no extra cost. The result is that light load gets low latency (small batches, quick flushes) and heavy load gets high throughput (large batches, flushes always full) from the same mechanism, which is exactly the load-dependent behavior you want.

// Writers append and then wait on the batch they joined.
long myBatch = log.Append(record); // buffered in memory, not yet durable
await commits.WaitForDurable(myBatch); // held until this batch's flush returns
return Ack.Durable; // only now is the promise kept

// A single commit thread amortizes the flush across whatever has accumulated.
while (running) {
var batch = log.TakePending(); // everything buffered since the last flush
if (batch.IsEmpty) { await log.Arrived(); continue; }
storage.Flush(batch); // ONE force to stable storage for the whole batch
commits.MarkDurable(batch.HighWaterMark); // releases every held writer in the batch at once
// next window = however long that flush took; arrivals meanwhile ride the next batch free
}

The same trick without a disk​

The reason group commit belongs in a distributed-store discussion, not just a database one, is that the identical amortization governs the replicated write path even when durability is defined by replicas rather than by a disk. When a write's durability means "acknowledged by a quorum of replicas," each replica is doing its own local persistence, and a coordinator that sends one replication message per write pays the per-message overhead every time. Batching replication — shipping a run of log records to each replica in one message and collecting one combined ack — amortizes the network and the remote flush exactly as local group commit amortizes the disk. It is why the operation log is streamed, not dripped: the log is append-structured precisely so a contiguous range can be flushed and shipped as a unit.

It also composes with the availability mechanisms around it. A quorum write can batch its per-replica traffic, and even a hinted handoff to a stand-in benefits from the same batched flush on the node holding the hints. The durability promise is kept at the granularity of the batch everywhere in the path — local disk, replica stream, hint store — and the batch is the unit that makes an expensive guarantee affordable at scale.

Wrap-up​

A durable write is only durable once it has survived the loss of its accepting machine, and making that true per write — one flush, one replication round-trip — is so slow it caps throughput at a few thousand writes a second regardless of hardware. The wrong fix is to drop the flush and quietly downgrade an acknowledged write to a hope. Group commit is the right one: buffer writes, flush the whole batch with a single expensive operation, and acknowledge every write in the batch only after that flush returns, so per-write cost collapses while the promise stays exactly as strong. The price is a small, bounded latency added to each write, controlled by an adaptive flush window that gives low latency under light load and full batches under heavy load. And the same amortization runs through the replicated path, which is why the write log is append-structured and streamed in runs. Keep the promise honest; pay for it once per batch instead of once per write.