Course contentsShow
← Cloud and Infrastructure
Lesson 2743 of 2,98959. Queueing and Async PatternsFree lesson

Dead Letter Queues for Failed Messages

Implement dead letter queues to handle messages that fail processing repeatedly and prevent them from blocking the main queue.

Dead Letter Queues for Failed Messages

What You'll Learn

You'll learn how to implement dead letter queues to automatically isolate messages that fail processing repeatedly, preventing them from clogging your main queue and disrupting healthy traffic.

The Problem: Poison Messages

Imagine a restaurant kitchen where one order keeps coming back because it's impossible to prepare (maybe requesting an ingredient that doesn't exist). If the kitchen keeps trying to make it, other orders pile up behind it. You need a separate "problem orders" bin to investigate later.

In distributed systems, some messages fail processing due to data corruption, incompatible formats, or logic errors. Without intervention, these "poison messages" get reprocessed endlessly, consuming resources and blocking healthy messages behind them—especially in FIFO queues.

How Dead Letter Queues Work

A dead letter queue (DLQ) is a separate queue that automatically receives messages after they exceed a configured retry threshold (the maxReceiveCount). Here's the flow:

  1. Message fails processing and returns to main queue
  2. Consumer retries (visibility timeout expires, message reappears)
  3. After N failed attempts, message automatically moves to DLQ
  4. Main queue continues processing healthy messages
  5. Engineers investigate DLQ messages separately

Implementation Strategy

Configure your main queue with:

  • Redrive policy: Points to the DLQ and sets maxReceiveCount (typically 3-5 attempts)
  • DLQ retention: Longer than main queue (e.g., 14 days vs 4 days) for investigation
  • Monitoring: Alerts when DLQ depth grows, indicating systematic problems

The DLQ should have the same security, encryption, and compliance settings as your main queue but without its own redrive policy (to prevent infinite loops).

Key Takeaway: Dead letter queues act as quarantine zones for problematic messages, automatically isolating failures after a configured retry limit to protect your main processing pipeline's throughput and enable separate investigation and remediation workflows.