Dead-letter queues and poison messages
Park the messages that will never succeed so the rest keep flowing, then fix and replay them.
15 min readPoison messages
A poison message fails every time it is processed: malformed JSON, a reference to a row that was deleted, an input that triggers a bug. In a plain queue it is redelivered forever, consuming worker time and retry capacity. In an ordered log it is worse: the consumer cannot move its offset past it, so every message behind it in that partition waits. This is head-of-line blocking, and one bad message can stall a whole partition for hours.
The dead-letter queue
A dead-letter queue (DLQ) is where a message goes after it has failed a set number of times, typically 3 to 5. SQS does this with a redrive policy and a maxReceiveCount; RabbitMQ with a dead-letter exchange. Kafka has no built-in DLQ, so the consumer catches the failure, publishes the message to a dead-letter topic with error details in headers, and commits the offset to move on. Either way the main flow continues and the bad message is kept, not lost.
Operating a DLQ
A DLQ nobody looks at is just a slower way to lose data.
- Alert when the DLQ is non-empty or growing; every message there is a failed user action
- Store the original payload, the error, attempt count and timestamps with each message
- Give the DLQ longer retention than the source queue (SQS allows up to 14 days) so you have time to act
- Build a redrive tool: fix the bug, then replay the messages back to the main queue
- Triage by cause: bugs get fixed and redriven, genuinely bad data gets discarded with a record
Retry topics for slow retries
On a log, waiting minutes between retries inside the consumer blocks the partition. A common pattern routes failures through delay tiers: main topic, then retry-1m, retry-10m, and finally the DLQ, each with its own consumer that waits until the message is due. The main partition keeps flowing. The trade-off is ordering: a message for key K that goes to a retry topic will be processed after newer messages for K, so use this only where per-key order does not matter or versions protect you.
Key takeaways
- One poison message can block a partition or consume retries forever
- After a few failed attempts, move the message to a DLQ with its error context
- Alert on DLQ depth and build a redrive path: a DLQ is a to-do list, not a bin
- Retry topics keep partitions moving at the cost of per-key ordering
Sign in to track lessons and earn badges.