Q20 · How do you handle high-volume write workloads?
Back to 24 Architecture Questions.
The question is not “shard everything”. The axis it turns on: how much durability and ordering the write can give up. Every knob on the write path trades throughput against a guarantee somebody has to name: the acknowledgment point buys durability with caller latency, batching buys throughput with delay, and ordering is usually bought for no reason at all.
What the answer should contain
The acknowledgment point is the durability dial. Ack after quorum fsync: the write survives the loss of a node; the caller pays the round-trips. Ack after the WAL append: crash-safe on one node, node-loss is a risk. Ack from memory: maximum throughput, and the data dies with the process. Clickstream can ack from memory; money acks after quorum; most things live in between, and the choice must be written down per data class.
Batching is where throughput actually comes from. Group commit, batched flushes, size or time windows: the cost of a write is mostly fixed overhead, so amortizing it across a batch is the first-order win. The price is added latency, bounded by the batch window.
Ordering: buy per-key, refuse global. Almost every workload needs “events for this key, in order” (so partition by key), and almost none need a global sequence. Global ordering caps throughput at one serialization point for no business-visible benefit. If someone demands it, make them name the decision that breaks without it.
Shape the storage for writes. Append-only inserts beat in-place updates on hot tables; partition by time or key so no single structure takes all writes; index minimally, because every index is a write tax. The schema is a write-path decision, not just a read-path one.
Bound the intake. Bounded queues, reject early, and never use the disk as an unbounded buffer: “disk full, and the queue kept accepting” is the worst failure mode to discover during the load event that caused it. Backpressure, rejecting work early instead of queueing it without a bound, is part of the write design.
Idempotency is still on the ticket. Batching and retries multiply duplicates: every acked path must be replayable, and at-least-once is the honest delivery model all the way down.
Ideas worth mentioning out loud
- “High-volume writes trade three things against each other: durability, ordering, latency. The data class picks the trade: clickstream buys throughput, money buys durability.”
- The write amplifiers are the silent killers: indexes, synchronous replicas, fsync per record. Removing one is worth more than adding a shard.
- Test the ack point claim by killing the process: whatever the vendor slide says, the crash test decides what was durable.
Follow-ups to expect
- Is disabling fsync ever acceptable? For data you are willing to lose: telemetry, caches, intermediate state. Name the class, and never let money ride on it.
- How big should a batch be? The latency floor decides: big enough to amortize, small enough that the added wait stays under the latency that class tolerates.
- What about write-heavy and read-heavy at once? Split the paths: the write shape and the read shape stop sharing structures.
Red flags in an answer
- Maximum durability applied uniformly, including throwaway data.
- Global ordering with no named decision that needs it.
- An unbounded write buffer; the disk used as a spool of hope.
- Heavy indexes on the hot ingest table.
- No idempotency on a path that retries.
Sources
- Write-Ahead Logging (WAL), PostgreSQL documentation: the middle rung of the durability ladder, from the engine that implements it, with the cost of fsync stated as the reason it is not free.
- Apache Kafka documentation, producer configuration, Apache Software Foundation: the ack-point dial in its rawest form, acks 0, 1, and all, with the durability and throughput consequences of each stated per configuration knob.