Dead-letter queue
a queue for messages removed from normal delivery
What it is
A dead-letter queue holds messages that a messaging system moves away from the normal delivery path. One message may exceed an attempt limit because its consumer fails every time it receives it. Another may expire before it can be processed. Depending on the broker, messages can be rejected explicitly, routed through an exchange or moved into a subqueue. The policy defines which events are captured and how operators can inspect or send the messages again. The queue is a means of preserving evidence and controlling repetition after normal delivery has failed.
Each product gives the idea its own delivery semantics. Amazon SQS uses a source queue redrive policy with a maximum receive count. What the broker sees is how often a message was received, which can differ from the number of useful attempts made by an application. A worker can receive a message and crash before it begins processing. Azure Service Bus records a dead-letter reason and description and has conditions beyond repeated delivery. RabbitMQ can route dead letters through an exchange to queues selected by binding rules. Read the mechanism that applies before assuming that a name appearing in a diagram guarantees routing, retention or exactly-once processing.
It also helps to distinguish the queue from a log of business failures. The broker usually knows whether a client acknowledged or rejected a message, or whether a delivery or expiration limit was reached. A worker knows whether a customer cancelled the underlying request, whether the data violates an invariant or whether an external system completed a side effect just before timing out. The incident record needs enough context from both sides to explain what happened and what would be safe next.
Why it matters
Repeated processing of a persistently failing message consumes capacity from messages that could succeed. If every failure goes immediately back to the same queue, a group of invalid deliveries can continue taking worker slots and delaying legitimate work. A separate destination can limit that pressure. It gives an operator a place to see the messages, connect them to the source workflow and decide whether to repair the data, the producer or the consumer.
The evidence needs to outlive the failure long enough to make that decision. A team waiting hours for an operator may need a different retention window from one whose automated recovery runs in seconds. Some messages contain confidential information. A queue that stores expired work can accumulate customer data for longer than the ordinary path. Define the retention and access policy for the separate destination, and keep diagnostic details limited to what operators need.
A dead-letter move can also affect ordering. A consumer reading a sequence of updates may be able to continue with later changes after one invalid update is removed, or the skipped update may leave the later updates meaningless. An inventory decrement and its associated state transition are different from independent welcome emails. Decide at the domain boundary whether later work for the same entity may proceed, must wait, or can be reconciled from an authoritative source.
What it looks like in practice
Imagine background work that creates an export and emails a customer when the file is ready. An intermittent storage failure may merit retrying. A message from an older producer might request an export format the current worker no longer knows. Repeating the second message cannot make the format supported. Mark the distinction in the worker’s outcome reporting. Set a deliberate retry budget for errors expected to clear, and send a permanent failure to the review path with its job identifier, checked format and reason recorded where the operator can find them.
Test the complete route with a known invalid payload before relying on it in production. The operator should observe delivery attempts and see a dead-letter event with the expected metadata. Confirm that the retry counter means what the operator thinks it means. Then test an interrupted worker and a temporary downstream failure, so a valid job that would succeed later is not discarded after an overly strict limit. Monitor the count, oldest age and rate of new failures. A brief arrival of one bad message and a full stream suddenly changing schema require different responses.
When fixing the consumer, select a small set of messages to replay. Preserve identifiers and check whether the earlier attempt may have created the export, sent the email or written a completion row. Make repeated delivery produce the intended result without duplicate notices. Compare the result with the original request and watch the normal queue while retry traffic returns. A corrected worker can still be overwhelmed if an operator sends an entire backlog at full speed.
The Engineer ApS River job-queue case describes background jobs using PostgreSQL and the value of visible retries when slow work does not complete. It is a useful comparison for choosing what needs to be preserved on failure. The email and export workflow above is illustrative and describes a policy that can be designed for a broker with dead-letter support.
Where it goes wrong
Teams frequently configure retries and forget the review destination. A successful transfer then moves the issue out of the dashboards that people watch. Give the queue an owner and an alert with a next action. Inspect whether the same source and reason account for most messages before developing a new script to reprocess everything. Several unrelated causes may be mixed in the queue.
A replay that uses a new message identifier can bypass an application’s duplicate protection. A replay that preserves an old identifier can be suppressed by a broker if an application needs to perform an explicitly corrected operation. Review the system’s separate broker and business identifiers, then decide how to represent retries and repairs so a consumer can tell them apart. Record the operator action and its outcome.
Finally, verify that the destination can itself receive messages. Queue arguments, access permissions and retention settings can prevent delivery or shorten the time a diagnostic copy remains available. Test a message through the actual broker and inspect the target before a rollout. Keep the complete end-to-end outcome visible so failure at the review boundary remains detectable.
Further reading
- Amazon SQS dead-letter queues explains receive counts, retention and redrive policies.
- Azure Service Bus dead-letter queues describes reason codes and settlement.
- RabbitMQ dead-letter exchanges documents conditions and routing for dead-letter delivery.