LOAD-BEARINGfree
High-level designTier 6 · unit 4 of 10 · 14 min read

Queues, logs and delivery guarantees

Asynchrony — "take the request now, do the work in a moment" — is the main tool for decoupling services and surviving traffic bursts. Two infrastructure shapes provide it, they get conflated constantly, and the difference changes your architecture. Then we'll tackle the delivery-guarantee question whose honest answer surprises almost everyone.

Queue vs log: post office vs newspaper archive

A message queue (SQS, RabbitMQ) is a post office: each message is delivered to one consumer and deleted once acknowledged. Multiple workers compete for messages — perfect for distributing work: resize these images, send these emails. Once processed, a message is gone.

An event log (Kafka, Kinesis) is a newspaper archive: an ordered, durable, replayable sequence. Nothing is deleted on read — each consumer just remembers its own bookmark (offset). The consequences are transformative: many independent consumer groups can read the same events (analytics, search indexing, and fraud detection all consuming the same order stream, none aware of the others), and a brand-new consumer can replay history from the beginning — build a new feature next year and backfill it from everything that ever happened. One caveat to tattoo somewhere: ordering is guaranteed within a partition only, never across partitions.

Delivery guarantees: the honest version

  • At most once — fire and forget. Fast; messages can vanish. Fine for metrics where a lost data point is noise.
  • At least once — retry until acknowledged. Nothing is lost, and duplicates are guaranteed to occur: worker processes a message, crashes just before acknowledging, message gets redelivered, work happens twice. This is what real systems actually provide.
  • Exactly once — the honest answer: as a transport-level, end-to-end guarantee, it does not exist. The crash-before-ack window above cannot be closed by the transport, ever. What does exist: at-least-once delivery plus idempotent consumers — duplicates arrive but change nothing. (Kafka's advertised "exactly-once semantics" is real but bounded: it holds within Kafka's own read-process-write loop. The moment your consumer calls an external API or a normal database, you're back in at-least-once land.)

The engineering conclusion, worth stating as a rule: every consumer must be idempotent. Three ways to get there: deduplicate on a message ID ("seen 8471 before? skip"); make the operation naturally idempotent (set status to shipped, don't increment a counter); or let a unique constraint reject the duplicate at the storage layer — Tier 3's "push invariants down" principle, riding again.

Ordering vs hot partitions: the standard tension

Kafka orders within a partition, so to keep one user's events ordered, partition by user ID — all their events land in one partition, sequenced. But partitioning by key means key volume determines partition load: one enormous key (the celebrity again) creates a hot partition while others idle. Ordering pulls toward key-partitioning; balance pulls away; every event-driven design negotiates between them, and there's no free resolution — only a chosen point.

Backpressure and poison messages: the operational half

When consumers fall behind producers, the queue grows — and an unbounded backlog is an outage on a payment plan (an hour of lag means every user waits an hour). The metric that catches it early is consumer lag — how far behind consumers are running. In most event-driven systems it is the earliest warning signal; alert on it like you alert on errors.

And then there's the poison message: one malformed message that crashes its consumer, gets redelivered (at-least-once, doing its job), crashes it again — forever — while everything queued behind it waits. The fix is standard equipment: after N failed attempts, shunt it to a dead letter queue for human inspection, and let the line move. A queue without a DLQ is a queue with a self-destruct button waiting for one bad payload.

The trap

Adding a queue to "make it faster." A queue doesn't reduce work — it relocates it and makes completion asynchronous. If the user must wait for the result anyway (their payment confirmation, their search results), a queue added a hop, a failure mode, and a new thing to monitor, and delivered nothing. Queues earn their place when the caller genuinely doesn't need to wait — or when you're smoothing a burst into a steady drain. Otherwise they're complexity cosplay.

The tradeoff sheet

Problem solved
A producer whose work must not be lost and must not wait for a consumer that is slow, unavailable, or bursty.
Rejected, and why
A synchronous call is simpler and correct when the work is fast and the caller can wait. A database table polled by a worker is a queue you already know how to operate.
The trade
Ordering guarantees shrink to per-partition, delivery becomes at-least-once, and every consumer now owes idempotency. The system also becomes harder to reason about end to end.
First to break at 10x
Consumer lag. At 10x, partition count caps parallelism and repartitioning a live topic is disruptive, so the number you chose on day one is the ceiling you meet later.
What it does to the bill
A broker cluster with retention-driven storage, plus cross-AZ traffic on every produce and consume. Retention is the dial that quietly dominates.
Day-2 operations
Alert on consumer lag and on dead-letter depth. An unwatched dead-letter queue is silent data loss with a dashboard nobody opened.

The nuance

“Exactly-once delivery does not exist.”

Exactly-once *delivery* across a network boundary genuinely does not — that part is a theorem, not an opinion. Exactly-once *processing* is achievable inside a closed system that controls both the offset and the state store, which is what Kafka transactions and Flink checkpointing provide. The distinction matters commercially: vendors advertise the second and readers hear the first.

Going deeper

  • The Log: What every software engineer should know about real-time data’s unifying abstraction Jay Kreps, 2013
    The essay that reframed the log from an implementation detail into the thing the rest of the architecture hangs off.