What it is
A dead letter queue (DLQ) is a separate queue where a broker or consumer puts messages that could not be processed after a set number of attempts. The main queue stays moving; the failed messages are kept, with their content intact, for someone to inspect, fix and send back (redrive).
Why it exists
With at-least-once delivery, a failed message is simply not acknowledged and comes back to be tried again. That is the right behaviour for a transient error and the wrong one for a poison message: a malformed payload, a reference to a record that does not exist, a bug triggered by one specific input. It fails on every delivery, so unlimited retries never end. Each attempt costs consumer time and, in many brokers, holds an in-flight slot until it times out. In ordered consumption (a FIFO message group, a stream partition) it is worse: the consumer cannot move past the message, so everything behind it waits. A delivery limit plus a DLQ ends the loop without throwing the message away.
How it works
Counting deliveries. The broker counts how often each message has been delivered: SQS calls the limit maxReceiveCount in a redrive policy, Azure Service Bus MaxDeliveryCount (10 by default), RabbitMQ quorum queues a delivery limit with a dead letter exchange as the target. When a message's delivery fails and the count has reached the limit, it is moved to the DLQ instead of being made visible again.
Consumer-side dead-lettering. Log-based systems like Kafka have no per-message delivery count. The consumer catches the error, publishes the record to a dead letter topic (often after a few retry topics with increasing delays) and commits its offset to move on. Frameworks and Kafka Connect provide this as configuration.
Classifying errors. Good consumers do not leave every failure to the delivery counter. Permanent errors (validation failures, unparseable payloads, missing references) can go to the DLQ on the first attempt. Transient errors (timeouts, 503s, throttling) deserve retries with backoff, and during a known outage it is better to pause consumption (a circuit breaker on the consumer) than to burn through delivery attempts.
Redrive. After fixing the cause, messages are moved back to the source queue (SQS and Service Bus have built-in redrive or move operations) or replayed by a job. Redriven messages are late and may already have been partly processed, so consumers must be idempotent, and the redrive should be rate-limited.
When to use it
- Any queue consumer whose processing can fail for reasons a retry will not fix. In practice: almost every production queue.
- Ordered streams, where one stuck message would otherwise stall a whole partition.
- Integrations with external systems that occasionally reject specific payloads.
When not to
- Do not use the DLQ as the retry mechanism for outages; that is what backoff, retry topics and circuit breakers are for.
- Do not add a DLQ that nobody monitors: it only delays and hides data loss.
- For at-most-once telemetry where failed messages are worthless anyway, dropping may be the honest choice.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Low delivery limit (e.g. 3) | Poison messages leave fast, little wasted capacity | Short outages push valid messages into the DLQ |
| High delivery limit | Rides out longer transient failures | Poison messages loop longer and cost more capacity |
| Dead-letter permanent errors on first failure | No wasted retries | Needs reliable error classification in the consumer |
| Retry topics with delays before the DLQ | Backoff without blocking the main topic | More topics, more moving parts, reordering |
| Automatic redrive | No manual work | Messages cycle during an unfixed outage and real poison loops anyway |
Alternatives
- Drop after N attempts: simpler, acceptable only when the messages have no value after failing.
- Parking-lot table: write failed messages to a database table with the error, which is easier to query and edit than a queue.
- Skip-and-log in stream processing: commit past the bad record and log it, with an alert; cheap but relies on logs as storage.
- Pause and alert: stop consuming when failures pass a threshold, for systems where order matters more than progress.
Failure modes
- Infinite loop: no delivery limit; poison messages consume capacity forever and, in ordered queues, block everything behind them.
- Capacity collapse: failed deliveries hold in-flight slots for the visibility timeout; a high failure rate turns plenty of capacity into a growing backlog while workers look idle.
- Outage flood: a dependency blip shorter than one alert cycle dead-letters thousands of valid messages.
- Silent DLQ: no alert on depth or age; messages expire there unseen.
- Retention expiry: in some brokers (SQS standard queues, for example) a message's expiry is based on its original enqueue time, so a DLQ with the same or shorter retention can delete messages soon after they arrive. Give the DLQ longer retention than the source.
- Redrive storm: replaying a large DLQ at full speed overloads the consumer or the dependency that just recovered.
- Lost context: dead letters without the error, stack trace or attempt count make diagnosis guesswork.
In production
Attach a DLQ to every important queue and alert when it is non-empty or when its oldest message passes an age threshold. Record the failure reason with each message (headers or attributes). Classify errors in the consumer, retry transient ones with exponential backoff and jitter, and size the limit so delivery attempts × timeout outlast a normal dependency blip. Keep the DLQ's retention longer than the source's. Redrive only after fixing the cause, at a limited rate, into idempotent consumers, and track how many redriven messages fail again.
Common misconceptions
- "The DLQ is where failures are handled." It is where they wait. Handling means an alert, a fix and a redrive.
- "A DLQ protects against a bad deploy." It parks individual messages; a consumer that fails most messages still collapses throughput. Roll back.
- "More retries are always safer." For poison messages they are pure waste, and in ordered queues they stall everything.
- "Everything in the DLQ is broken." After an outage, most of it may be perfectly valid.
Interview angle
Whenever you add a queue, add "with a delivery limit and a DLQ, alerted on depth and age" in the same sentence. Interviewers then ask how you tell transient from permanent failures, how you would handle a poison message in an ordered stream (retry topics, dead letter topic, skip with alert), what happens to the DLQ during an outage, and how you redrive safely. Mentioning that unacknowledged failures hold in-flight capacity, and that DLQ retention must outlast the source queue's, shows operational experience.
Model assumptions
The simulation is a simplified model, not a benchmark. The Order Service publishes 20 messages per second (Poisson). Two workers with 8 slots each take about 100 ms per message (lognormal, cv 0.3). A failed delivery is not acknowledged: the message stays in flight, and keeps its worker slot, until its 1 s visibility timeout expires; then it goes back to the front of the queue. "Retry forever" is a delivery limit of 1,000, which no message reaches in a step. The engine's failure rate is a per-delivery probability, so a retried message may succeed; a true poison message (failing every time) is shown as a scripted packet loop. The outage is modelled as every delivery failing for 3 s. The redrive job is a worker consuming the dead letter queue directly, standing in for moving messages back to the source queue. Message accounting: each message ends in one outcome, counted once: delivered (first successful acknowledgement), dead-lettered (moved to a dead letter queue after its last delivery) or dropped (it ran out of deliveries with no dead letter queue connected, or a subscription was full or down when its copy arrived). Redelivered (a delivery that came back after its timeout) and duplicates (a message processed again after it had already been processed) are not outcomes: they count extra deliveries of messages that are counted once above. The Redelivered, Dead-lettered and Dropped tiles show these counts. Numbers show behaviour and orders of magnitude only.