Dead letter queue

On this page 7

A dead letter queue (DLQ) is a separate queue that receives messages a system could not process or deliver after defined conditions are met, typically an exhausted number of delivery attempts or an expired lifetime. In reliability engineering for automation, it acts as a quarantine area: problematic messages leave the main flow, so healthy traffic keeps moving, while nothing is silently lost.

The term comes from postal services, where undeliverable letters were sent to a dead letter office for examination. In message brokers, event pipelines and workflow engines, the DLQ plays the same role and is a core building block of fault-tolerant asynchronous processing.

How messages end up in a dead letter queue

A consumer receives a message from a source queue and tries to process it. When processing fails, the broker makes the message available again, and a delivery counter increases. Once the counter exceeds the configured threshold, the broker moves the message to the DLQ instead of delivering it again, usually together with metadata about why it was moved.

The classic target of this mechanism is the poison message: a message that fails every time because of malformed content, an unexpected schema version or a business rule it violates. Without a DLQ, such a message is redelivered endlessly, consumes worker capacity and, in ordered queues, can block every message behind it.

ConditionWhat happensTypical cause
Delivery limit exceededThe receive count passes the maximumRepeated processing exceptions
Explicit rejectionThe consumer rejects without requeueingInvalid content detected by validation
Time to live expiredThe message ages out before consumptionConsumers offline or too slow
Queue length limitThe oldest messages overflowProducer faster than consumers
Routing failureNo destination matches the messageMisconfigured routing or filter rules
Conditions that send a message to a dead letter queue

Dead letter queues in common messaging systems

Most brokers support dead-lettering, but configuration and terminology differ. Some attach the DLQ through a policy on the source queue, others provide it as a built-in subqueue, and some streaming platforms leave it to the consuming application.

PlatformMechanismKey setting
Amazon SQSA redrive policy pointing to another queueMaximum receive count between 1 and 1,000
Azure Service BusA built-in dead-letter subqueue per entityMaximum delivery count, 10 by default
RabbitMQA dead letter exchange set by policy or argumentDeath reasons recorded in a header
Google Pub/SubA dead-letter topic on the subscriptionMaximum delivery attempts from 5 to 100
Apache KafkaNo broker feature, implemented by consumers or connectorsA dedicated error topic
Dead-letter support across messaging platforms

Two configuration details are frequently overlooked. The DLQ retention period should be longer than that of the source queue, because the original timestamp often counts toward expiry. A FIFO source queue also needs a FIFO dead letter queue of the same type.

How a dead letter queue relates to retries and idempotency

A DLQ is the final stage of a retry policy, not a replacement for it. Retries with exponential backoff handle transient faults; the DLQ catches what retries cannot fix. The two must be tuned together, because the delivery threshold defines how many attempts a message receives before it is parked.

ConceptRoleRelation to the dead letter queue
Retry policyDecides how often and when to try againHands over messages when attempts run out
Exponential backoffSpreads retries over growing intervalsGives transient faults time to clear before dead-lettering
Retry queueHolds messages for a delayed new attemptPrecedes the DLQ in tiered designs
IdempotencyMakes repeated processing safeRequired before messages are redriven
Error logRecords failure detailsDescribes failures but does not keep the payload for replay
Dead letter queue and neighboring reliability concepts

Idempotency matters most at the reprocessing step. A message that partly succeeded before failing will run again when it is redriven, so consumers must recognize already applied effects, for example through a stored message identifier or a business key.

Operating a dead letter queue

A DLQ only improves reliability if someone watches it and acts on its contents. The minimum practice is an alert when the queue depth rises above zero or above a small baseline, followed by triage that groups messages by failure reason.

FindingActionReason
Bug in consumer codeDeploy a fix, then redriveMessages are valid and should complete
Temporary outage now resolvedRedrive in controlled batchesAvoids overloading the recovered service
Malformed or invalid payloadCorrect at the source or discard with a recordReprocessing would fail again
Obsolete business eventArchive and removeApplying it late could corrupt current data
Threshold set too lowRaise the delivery limit or visibility timeoutHealthy but slow messages were parked
Triage decisions for dead-lettered messages

Redrive, also called replay, moves messages back to the source queue or a dedicated reprocessing queue. It should happen only after the root cause is fixed, otherwise the messages fail again and return to the DLQ in a loop.

Common mistakes with dead letter queues

Most DLQ problems are organizational rather than technical: the queue is configured correctly, but nobody owns it or the reprocessing path is unsafe. The following mistakes appear repeatedly in production systems.

  • Treating the DLQ as a black hole: without alerts and ownership, failed orders or payments accumulate unnoticed until a customer complains.
  • Losing failure context: moving a message without the error reason, attempt count and source makes triage slow and guesswork-driven.
  • Auto-retrying from the DLQ forever: a consumer that drains the DLQ back into the source queue recreates the infinite loop the DLQ was meant to stop.
  • Ignoring ordering: redriven messages arrive after newer messages, which can overwrite current state with stale data.
  • Forgetting data protection: payloads in a DLQ still contain personal or financial data and need the same access controls and retention rules.

The idea in brief

Think of a sorting center where most parcels move smoothly, but a few have unreadable labels. Instead of letting those parcels circle the conveyor belt forever and block others, workers put them on a separate shelf for problem parcels, where someone can look at them later.

A dead letter queue is that shelf for digital messages. It keeps the main system flowing and makes sure failed items are set aside, not thrown away. The shelf is only useful, however, if someone checks it regularly and decides what to do with each item.

A practical scenario

A logistics company processes shipment status events from partner carriers through a message queue, with about 50,000 events a day. The consumer retries each event up to five times with backoff, and the redrive policy sends it to a DLQ after the fifth failed receive. An alarm notifies the integration team whenever the DLQ holds more than 20 messages.

One morning a carrier begins sending a new date format, and several hundred events land in the DLQ while all other carriers continue unaffected. The team inspects the samples, updates the parser and redrives the parked events in batches of 500. Because the consumer stores processed event IDs, the few events that had partly succeeded are skipped without duplicates, and tracking pages show correct statuses within the hour.