SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
  • Message Queues
  • Pub/Sub
  • Message Brokers
  • Delivery Semantics
  • Dead Letter Queues
  • Kafka Deep Dive
  • Retries with Backoff
  • RabbitMQ and SQS
  • Event Streaming vs Message Queues
  • Message Ordering
  • Task Queues, Workers and Scheduled Jobs
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/APIs and Communication/Asynchronous Communication

Dead Letter Queues

A safe place for messages that keep failing, so they do not block everyone else.

⏱ 10 min readIntermediateHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A dead letter queue (DLQ) is a side queue for messages that could not be processed, even after several retries.

  • Without it, one bad message can fail again and again, and block the good ones behind it.
  • With it, the bad message is moved aside, and the rest of the line keeps moving.
  • People (or a repair job) look at the DLQ, fix the cause and send the messages back.

02Concept: What is it?

Some messages can never succeed. The data may be broken, a field may be missing, or a bug may crash the code. Retrying them forever wastes work. A poison message is one that fails every time.

The main queue and its dead letter queue
πŸ“€Producer
→↓
πŸ“¬Main queue
→↓receive
πŸ‘·Consumerfails on bad message
→↓after N tries
πŸ’€Dead letter queueparked for a human
After too many failed tries the message is moved to the DLQ. The main queue is free again.
No DLQ
  • A poison message is retried forever
  • It can block messages behind it
  • Workers waste time and money
  • Nobody notices the real problem
With a DLQ
  • Failed messages move aside after a retry limit
  • The main queue keeps flowing
  • Failures are saved, not lost
  • An alarm tells people to look

03Real-Life Example

🍡The Undeliverable Mail Office
A postman cannot find the house for one letter. He tries a few times. He does not walk around all day with that one letter while the rest of the mail waits. He drops it at the undeliverable mail office. Staff there check the address, fix it or send it back.
Post office
Dead letter queue
A letter with a bad address
Poison message
Postman tries 3 times
Retries with a limit
Undeliverable mail office
Dead letter queue
Staff fix the address
Fix the bug or the data
Put it back in the mail
Redrive to the main queue
  1. 1
    Message arrives
    Consumer tries to process it.
  2. 2
    It fails
    The consumer does not ack. The message returns to the queue.
  3. 3
    Retry with backoff
    Try again after 2s, then 4s, then 8s.
  4. 4
    Retry limit reached
    For example after 5 receives.
  5. 5
    Move to the DLQ
    An alarm fires. The main queue keeps moving.
  6. 6
    Fix and redrive
    Repair the bug, then send the messages back.

04Why Do We Need It?

🚧No blocking
One bad message cannot stop the good ones.
πŸ›ŸNothing is lost
Failed messages are saved so you can study and replay them.
πŸ””Early warning
A growing DLQ is a clear signal that something is wrong.
πŸ§ͺEasy debugging
You can look at the exact message that failed.
πŸ’°Saves resources
No endless retries burning CPU and money.
πŸ“‹Audit trail
Important messages (like payments) are never silently dropped.
A dead letter queue turns β€œstuck forever” into β€œparked safely, with an alarm”.

05Where Do We Use It?

πŸ’³Payments
A failed charge message must never vanish.
πŸ“§Email and SMS
Bad addresses and blocked numbers.
🧾Order processing
Orders with missing or invalid data.
πŸ”ŒIntegrations
A partner API that is down or rejects data.
πŸ“ŠData pipelines
Records with a wrong format.
πŸ””Webhook delivery
Endpoints that keep returning errors.

Most queue and broker products have this idea built in (for example Amazon SQS redrive policies, RabbitMQ dead-letter exchanges, Google Pub/Sub dead letter topics). Exact settings differ by product.

06Types / Parts / How It Works

Why do messages fail?

ReasonKindRetry helps?
Partner API is down for a minuteTemporaryYes. Retry later with backoff.
Database is busy or timed outTemporaryYes.
Message has invalid JSON or a missing fieldPermanent (poison)No. It will never work. Send to the DLQ at once.
Bug in the consumer codePermanent until fixedNo. Fix the code, then redrive.
Business rule fails (customer not found)PermanentUsually no.

Retry with exponential backoff

Wait longer after each failure. This gives a struggling service time to recover. Add a little random delay (jitter) so many consumers do not retry together.

Waiting time before each retry
Retry 1: wait 2s
Retry 2: wait 4s
Retry 3: wait 8s
Retry 4: wait 16sthen the DLQ
Exponential backoff: each wait is double the last one.

Where the DLQ fits

Normal path
πŸ“¬Main queue
πŸ‘·Consumer
→↓fails N times
Failure path
πŸ’€DLQ
πŸ””Alarm
πŸ§‘β€πŸ”§Human
Normal flow Failure flow
VisualizerPoison message, retries and the DLQTurn the DLQ off to see the consumer get stuck. Turn it on, change retries and backoff, then fix and redrive.
Dead letter queue
Wait between retries
Main queue (one consumer, first message that is ready goes first)
βœ‰οΈ 1
0 failed/tries
ready
βœ‰οΈ 2
0 failed/tries
ready
☠️ 3
0 failed/tries
ready
βœ‰οΈ 4
0 failed/tries
ready
βœ‰οΈ 5
0 failed/tries
ready
βœ‰οΈ 6
0 failed/tries
ready
βœ‰οΈ 7
0 failed/tries
ready
πŸ‘·Consumerworking
βœ…0 done
πŸ’€ Dead letter queue
no failed messages
Clock
0s
Processed
0
of 7
Waiting
7
In the DLQ
0
Message 3 is a 'poison' message: it always fails (bad data, or a bug). Press Play and watch what each setup does with it.

07How to Use It / Steps / Implementation

  1. 1
    Create a DLQ for each important queue
    Give it a clear name, like orders-queue-dlq.
  2. 2
    Set a retry limit
    For example 3 to 5 receives before the message moves. Not too low (temporary errors) and not too high (endless loops).
  3. 3
    Use exponential backoff with jitter
    Give temporary problems time to clear.
  4. 4
    Skip retries for clearly permanent errors
    Invalid data goes straight to the DLQ.
  5. 5
    Keep the message and the error reason
    Store the original message, the error, the time and the number of tries.
  6. 6
    Alarm on DLQ depth
    Even 1 message in a payments DLQ may deserve an alert.
  7. 7
    Fix the cause, then redrive
    Send messages back to the main queue. Consumers must be idempotent, because a message may be processed again.
  8. 8
    Set a long retention on the DLQ
    So messages do not expire before someone looks.
πŸ’‘Check the DLQ regularly
A DLQ that nobody watches is just a place where problems quietly pile up. Add an alarm and an owner.

08Key Terms to Know

TermMeaning in easy words
Dead letter queue (DLQ)A queue for messages that could not be processed
Poison messageA message that fails every time it is tried
Retry limitHow many tries before a message is moved to the DLQ
BackoffWaiting longer between retries
JitterRandom extra delay so retries do not all happen together
RedriveMoving messages from the DLQ back to the main queue
Transient errorA temporary problem that may go away
Permanent errorA problem that retrying will not fix
Queue depthHow many messages are waiting
AlarmAn automatic alert when a number crosses a limit

09Pros, Cons and Trade-offs

βœ… Pros
  • Failing messages never block good ones
  • Failures are kept for study and replay
  • Clear signal that something is wrong
  • Saves compute from endless retries
⚠️ Cons
  • Needs monitoring and an owner
  • Messages in the DLQ are delayed until someone acts
  • Redriving can cause duplicates, so idempotency is needed
  • Ordering can be broken (a moved message is processed later)
  • Another queue to configure and secure
ChoiceWe gainWe lose
Few retriesFast move to DLQ, quick signalMay give up on a temporary error
Many retriesRides out longer outagesSlow failure, more load
Auto redriveLess manual workMay loop if the bug is not fixed
Manual redriveSafe and controlledNeeds a person

10Common Problems and Mistakes

Common mistakes

  1. No DLQ at all. A poison message loops forever.
  2. A DLQ with no alarm. Messages sit there for weeks.
  3. Retry limit too low. A short outage sends good messages to the DLQ.
  4. Retries with no wait. A tight loop hammers a service that is already struggling.
  5. Redriving before the bug is fixed. Everything fails and returns to the DLQ.
  6. DLQ retention shorter than the main queue. Messages expire before you can look at them.
  7. Losing the error reason. You cannot tell why it failed.
  8. Ignoring order. For ordered work, a parked message may block or break later steps.
πŸ”Redrive loops
Messages go back, fail, and return to the DLQ.
🌊DLQ flood
A partner outage sends thousands of messages to the DLQ at once.
πŸ”Sensitive data
The DLQ holds real user data. Protect it like the main queue.

11Real-World Examples

☁️Amazon SQS
A queue can be set to move a message to a DLQ after a maximum number of receives. A redrive option moves them back.
πŸ‡RabbitMQ
Queues can name a dead-letter exchange for rejected or expired messages.
🌐Google Pub/Sub
A subscription can forward undeliverable messages to a dead letter topic.
🧡Kafka
No built-in DLQ. Teams often write failed records to a separate β€œdead letter” topic.
πŸ“Note
General descriptions. Settings and names differ by product and version, so check the official docs.
Mini case: a bad order message
πŸ“¬1,000 ordersin the queue
→↓
πŸ‘·Consumer999 OK, 1 fails
→↓1 bad
πŸ’€DLQ1 message
→↓alarm
πŸ§‘β€πŸ”§Engineerfixes and redrives
One malformed order is parked. The other 999 orders are processed.

12Related Topics to Read Next

Message Queues→

The queue that a DLQ protects.

Delivery Semantics→

Retries cause duplicates, so you need idempotent consumers.

Message Brokers→

Brokers provide DLQ features.

Idempotency→

Makes redrive safe.

Webhooks→

Failed webhook deliveries are often retried and then parked.

Reliability→

A DLQ is a tool to keep a system dependable.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • βœ”DLQ: a side queue for messages that keep failing.
  • βœ”Why: a poison message must not block the rest, and must not be lost.
  • βœ”Flow: fail β†’ retry with backoff (+ jitter) β†’ limit reached β†’ DLQ β†’ alarm β†’ fix β†’ redrive.
  • βœ”Do not retry permanent errors like invalid data. Move them at once.
  • βœ”Keep: the message, the error and the number of tries. Use long retention.
  • βœ”Redrive only after the fix, with idempotent consumers.
  • βœ”Alarm on DLQ depth and oldest message age.
  • βœ”One line: β€œA DLQ turns β€˜stuck forever’ into β€˜parked safely, with an alarm’.”
← Previous
Delivery Semantics
Next β†’
Kafka Deep Dive