Course contentsShow
← System Design
Lesson 687 of 1,91918. Message Queues and BrokersFree lesson

Dead Letter Queues

Handling messages that fail processing repeatedly; isolation, inspection, and retry strategies.

Dead Letter Queues

What you'll learn: How to handle messages that repeatedly fail processing so they don't clog your system or get lost forever.


The Problem of Poisonous Messages

When using message queues with at-least-once delivery and acknowledgment mechanisms, sometimes a message just cannot be processed successfully—even after multiple retries. This could happen because:

  • The message payload is malformed or corrupt
  • It triggers a bug in your consumer code
  • It references data that no longer exists
  • The message format is incompatible with the current version of your consumer

Without a strategy, these "poisonous" messages would be redelivered endlessly, wasting resources and potentially blocking other valid messages.


What Is a Dead Letter Queue?

A Dead Letter Queue (DLQ) is a special holding queue where messages go after exhausting all retry attempts. Think of it as a hospital quarantine room—messages that are "sick" get isolated so they don't infect the healthy flow.

When a message fails processing multiple times (typically 3-5 attempts), the broker or consumer framework automatically moves it to the DLQ instead of redelivering it again.


DLQ Workflow

  1. Delivery attempt → Message fails processing
  2. Redelivery → Consumer nacks or doesn't acknowledge (negative acknowledgments)
  3. Retry counter increments after each failure
  4. Max retries reached → Message moved to DLQ
  5. Inspection → Engineers examine DLQ messages to diagnose issues
  6. Resolution → Fix code/data, then manually replay or discard messages

Retry Strategies

  • Exponential backoff: Wait longer between retries (1s, 2s, 4s...)
  • Max retry limit: Prevent infinite loops
  • Visibility timeout: Temporarily hide failed messages before retry (from SQS concepts)

Key Takeaway: Dead Letter Queues isolate repeatedly failing messages, preventing system degradation while preserving problematic messages for debugging and potential replay—a critical safety mechanism in production message processing.