Course contentsShow
← Software Engineering
Lesson 1363 of 1,93340. Event-Driven ArchitectureFree lesson

Dead Letter Queues and Error Handling

Learn to handle poison messages, implement retry logic with backoff, and route failed messages to dead letter queues.

Dead Letter Queues and Error Handling

You'll learn how to handle messages that repeatedly fail processing, preventing them from blocking your system indefinitely.

What Are Poison Messages?

In event-driven systems, sometimes a message causes your consumer to crash or fail repeatedly. Maybe it's malformed, references data that no longer exists, or triggers an unhandled edge case. These are called poison messages—they're toxic to your system and can clog up your message queue if not handled properly.

Retry Logic with Backoff

Before giving up on a message, implement retries with exponential backoff:

  1. First failure: retry immediately
  2. Second failure: wait 1 second
  3. Third failure: wait 2 seconds, then 4, then 8...

This pattern gives transient issues (network hiccups, temporary service outages) time to resolve without hammering downstream systems.

Think of it like knocking on a door: if no one answers, you don't keep pounding every second—you wait progressively longer between attempts.

Dead Letter Queues (DLQs)

After exhausting retries (say, 5 attempts), move the failed message to a Dead Letter Queue—a special queue for messages that couldn't be processed. This prevents the poison message from blocking healthy messages behind it.

The DLQ serves as:

  • A holding area for investigation
  • An audit trail of failures
  • A source for manual reprocessing after fixing bugs

Your monitoring system should alert when messages land in the DLQ, signaling something needs attention.

The Complete Flow

  1. Consumer receives message
  2. Processing fails → retry with backoff
  3. After N failures → route to DLQ
  4. Alert engineers
  5. Investigate, fix issue, optionally replay from DLQ

Key Takeaway: Dead letter queues and retry logic with exponential backoff prevent poison messages from taking down your entire event-driven system, giving you visibility into failures while keeping healthy messages flowing.