Stackbook Logo
operations

Dead Letter Queue Handling

Intent

Isolate messages that repeatedly fail processing so that they neither block the pipeline nor get lost.

Problem

Poison messages that always fail can be retried forever, blocking queues and burning resources. Discarding them silently loses data, and leaving them in place stalls healthy traffic.

Forces

    Solution

    Dead Letter Queue Handling

    A dead letter queue is a holding area for messages that cannot be processed. It converts an infinite retry loop or silent drop into a visible, manageable backlog of exceptions.

    How it works

    The consumer attempts processing and, on failure, retries with backoff up to a limit. Transient errors such as timeouts are retried; permanent errors such as schema violations skip straight to the dead letter queue. The broker or consumer moves the message there with headers describing the failure reason, stack summary, original queue, and attempt count. An alert fires when depth or age crosses a threshold. After investigation, engineers fix the code or data and redrive the messages, or discard them with an audit record.

    Implementation steps

    1. Classify errors into transient and permanent categories
    2. Set a maximum delivery attempt count with exponential backoff
    3. Configure a dead letter destination per source queue
    4. Attach failure metadata to every dead lettered message
    5. Alert on depth, age of oldest message, and arrival rate
    6. Provide a tested redrive tool and a documented runbook

    Common pitfalls

    • Retrying permanent failures many times before diverting
    • Dropping the original headers and losing context for debugging
    • Redriving into the main queue while the bug still exists
    • Forgetting that dead letters can contain personal data and need retention limits

    Metrics to watch

    • Dead letter queue depth
    • Age of the oldest message
    • Arrival rate versus main queue throughput
    • Time to triage and resolve
    • Redrive success rate

    Example configuration

    {
      "QueueName": "orders",
      "RedrivePolicy": {
        "deadLetterTargetArn": "arn:aws:sqs:us-east-1:123456789012:orders-dlq",
        "maxReceiveCount": 5
      },
      "VisibilityTimeout": 60
    }
    

    Trade-offs and adoption

    Teams adopt this approach when asynchronous pipelines process messages with occasional bad data; message loss is unacceptable but blocking is too costly. It is a poor fit when messages are disposable telemetry where loss is acceptable, or when processing is synchronous and errors can be returned to the caller. The central tensions are retry persistence vs pipeline throughput; automation of redrive vs manual review; retention length vs data protection. The main benefits are that it delivers: healthy traffic keeps flowing despite poison messages; no silent data loss; failures become inspectable and replayable; provides a clear operational signal. The main costs to budget for are: the queue becomes a graveyard if nobody owns it; replay can duplicate effects without idempotency; messages may hold sensitive data needing protection; ordering guarantees can be broken by diversion. Governance typically looks like this: named team owns triage with defined service level for resolution. Expect adoption cost to be low: broker feature plus runbooks and alerts, and a best fit for any team using message brokers or event streams. Critics point out that DLQs often become unmonitored dumping grounds, and that replaying messages without idempotency can cause duplicate side effects. Treat these concerns as design inputs, and revisit the decision as traffic, team size, and failure history change.

    Key takeaways

    • Bound retries and classify errors
    • Preserve payload and failure context
    • Assign an owner and alert on age and depth
    • Make consumers idempotent before enabling redrive

    ✓ When to Use

    • •Asynchronous pipelines process messages with occasional bad data
    • •Message loss is unacceptable but blocking is too costly
    • •Consumers can fail on malformed or unexpected payloads
    • •Operations need an audit trail of failed work

    ✗ When Not to Use

    • •Messages are disposable telemetry where loss is acceptable
    • •Processing is synchronous and errors can be returned to the caller
    • •No team will own and process the dead letter queue

    Pros

    • +Healthy traffic keeps flowing despite poison messages
    • +No silent data loss
    • +Failures become inspectable and replayable
    • +Provides a clear operational signal

    Cons

    • −The queue becomes a graveyard if nobody owns it
    • −Replay can duplicate effects without idempotency
    • −Messages may hold sensitive data needing protection
    • −Ordering guarantees can be broken by diversion

    Cost Profile

    Infrastructure

    Operational

    Cognitive

    Failure Modes

      Alternatives

        Related Patterns

          Competency Domains

          reliability opsdata statesecurity compliance