Topic 117 / Core
Dead-letter queues and poison messages
Chapter 7.3 · Event-Driven Architecture and Delivery Guarantees
What and why
Idempotent consumers (→ 116) make retries safe, but safety doesn't guarantee success — some messages will never process no matter how many times they're retried: a malformed payload, a reference to a deleted record, a bug in the consumer itself. A poison message is one that fails every retry; a dead-letter queue (DLQ) is a separate holding queue it's routed to after a bounded number of failed attempts, so it stops blocking the main queue and gets a deliberate follow-up. Builds on: → 116.
Diagram
message fails → retry 1 → retry 2 → retry 3 (backoff → 152) → still failing
│
▼
dead-letter queue → alert (→ 201, 202)
│
fix & replay or discard with reason
How it works
- Processing fails; the consumer retries with backoff (→ 152) rather than giving up immediately — most failures are transient and succeed on retry.
- A retry counter, carried on the message or tracked by the broker, caps the number of attempts.
- Once the cap is reached, the message moves to the DLQ instead of retrying forever or being silently dropped — the main queue keeps flowing for every message behind it.
- The DLQ is monitored (→ 201, 202): any depth above zero should alert, since every message there represents a case nobody has resolved yet.
- A human or an automated job inspects DLQ entries and decides fix-and-replay (correct the issue, then re-publish) or discard-with-reason (the message was genuinely invalid) — and records that decision.
Practical example
(illustrative). An order-processing consumer configured for 3 retries with backoff (1 s, 2 s, 4 s) receives a message referencing a since-deleted product ID. It fails all 3 attempts and lands in the DLQ. The 500 valid orders queued behind it are processed normally in the meantime — the DLQ is what stops one unfixable message from stalling everything behind it.
When to use it
- Use for any consumer where some fraction of messages will eventually fail regardless of retries — which is most production consumers.
- Avoid relying on the DLQ as the primary error path for predictable, fixable validation errors — reject clearly at the point of entry instead, before the message is even queued.
- Failure scenarios: an unmonitored DLQ fills silently while the business impact (an order never shipped, a payment never settled) goes unnoticed until a customer complains; replaying a DLQ message without fixing the root cause just returns it to the DLQ, or half-applies a now-stale effect.
- Simpler alternative: for low-volume, non-critical consumers, logging the failure loudly and alerting without a separate queue may be enough.
Practice
(pattern — implement minimal, spot the misuse; 20 min, lab Kafka).
Configure a consumer with a 3-attempt cap that routes exhausted messages to a topic-dlq
topic carrying the original payload plus a failure reason. Feed it one message that always
fails and nine that succeed; confirm exactly one message reaches the DLQ with its reason
attached, while the nine valid ones complete without being blocked. Done when the DLQ holds
exactly the one poison message and the nine valid ones completed.
Key takeaway
A dead-letter queue turns "this message would retry forever" into "this message is isolated and someone decides" — without stalling everything behind it. Done when you can: set a sane retry cap and explain what must happen to a DLQ message before it's safe to replay. Used next in → 118 (outbox relays need the same exhausted-message handling), → 152 (the backoff strategy feeding the retry cap).
References
None — this topic makes no external claims.
Exercise: Build a consumer that survives the same payment event delivered three times, out of order with its cancellation, and prove the final state is correct.
Source directory