CMD Guide
HomeSystem DesignMicroservices Patterns

Event Delivery Semantics & Dead Letter Queues

What “delivered” guarantees — and poison that cannot be processed

Networks drop packets; consumers crash mid-handler; brokers redeliver. Async messaging must define both the delivery contract and what happens when a message never succeeds. This page is the operations-minded core: ack timing, the three semantics, a charge-card redelivery trace, and DLQ discipline.

Delivery semantics legend and a dead-letter-queue flow with retries
Delivery semantics legend and a dead-letter-queue flow with retries

The three semantics

SemanticGuaranteeTypical useCost
At-most-onceMay lose; never duplicateMetrics, best-effort logsLoss under crash
At-least-onceNo silent loss; may duplicateDefault for business eventsIdempotent consumers required
Exactly-once (effectively)Effect onceLedger-ish paths inside a txn boundaryUsually = at-least-once + dedupe; broker EOS does not cover arbitrary side effects (SMS, HTTP)

Ack-before vs ack-after processing

When you ackCrash windowResulting semantic
Ack before processingCrash after ack → message goneAt-most-once (loss possible)
Ack after successful processingCrash after process before ack → redeliveryAt-least-once (duplicate possible)

Two Generals framing: the broker and consumer can never be simultaneously certain of delivery over an unreliable network without an unbounded protocol. Practical systems pick loss or duplication and design for it — almost always duplication + idempotency for money-adjacent work.

Worked trace: charge-card redelivery

Queue message: ChargeCard{paymentId=P1, amount=40.00, idempotencyKey=K1}.

  1. Consumer receives message, charges card successfully, then crashes before ack.
  2. Broker redelivers after visibility timeout / uncommitted offset.
  3. Without idempotency: second charge → customer billed twice.
  4. With idempotency store keyed by K1: second attempt returns original success; one capture.

Same pattern for Kafka: process then commit offset; crash between process and commit → reprocess after rebalance.

Ordering

Global total order is expensive and rarely needed. Prefer per-entity order (Kafka partition key = orderId / rideId). Unrelated entities can proceed in parallel. Single-queue FIFO with one consumer is a scalability ceiling.

Retries, DLQs, and ordering — the hidden trade

Sidelining a message breaks the very per-key ordering you partitioned for: a replayed DLQ message for orderId=O arrives after every later event for O. Concretely: events e1, e2, e3 for O sit on one partition; e1 poisons and is parked to the DLQ after N attempts; e2 and e3 process normally; replaying e1 later means the consumer sees e2, e3, e1 — any consumer applying deltas or last-writer-wins without a version/sequence guard regresses state. Two survival strategies:

Retry-topic tiers (retry-5m, retry-30m) have the same property: they trade ordering for main-topic liveness.

Kafka vs classic queue (ops differences)

Dead Letter Queues — mechanism and ops

A poison message (bad schema, permanent business reject, handler bug) that fails forever will either block a partition/consumer or burn retry budget. After max-receive-count / max attempts, move to a DLQ (side queue or topic) so the main path keeps flowing.

When NOT to force at-least-once

Drill ladder

  1. Q: Ack-before-process: what semantic? A: At-most-once (crash loses work).
  2. Q: Why is broker "exactly-once" not enough for email send? A: Side effect outside the broker txn; duplicates still possible at the mail API unless deduped.
  3. Q: DLQ depth rising after a deploy — first actions? A: Inspect sample payloads/errors; roll back or fix consumer; do not mass-replay until fixed; check if schema change broke compat.

Takeaways


Re-authored for this guide. Cross-link Idempotency & Exactly-Once Is a Myth, Kafka internals, Transactional Outbox. Diagram hand-authored.

🤖 Don't fully get this? Learn it with Claude

Stuck on Event Delivery Semantics & Dead Letter Queues? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Event Delivery Semantics & Dead Letter Queues** (System Design) and want to truly understand it. Explain Event Delivery Semantics & Dead Letter Queues from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Event Delivery Semantics & Dead Letter Queues** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Event Delivery Semantics & Dead Letter Queues** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Event Delivery Semantics & Dead Letter Queues** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes