advanced

RabbitMQ dead-letter exchange

Route rejected, expired, or overflowed messages to a dead-letter exchange so failures are inspectable and recoverable.

A dead-letter exchange (DLX) receives messages that are rejected, expire by TTL, or overflow max-length limits. Configure `x-dead-letter-exchange` and optional `x-dead-letter-routing-key` on the source queue so failures land in an inspectable destination instead of disappearing.

DLX enables retry pipelines, quarantine queues for poison messages, and operational dashboards on failure volume. Preserve original routing metadata and add headers like `x-death` reason counts when designing replay tooling.

On interviews: diagram main queue → DLX → inspection queue, explain the three dead-letter reasons, and describe how you would replay after a bug fix.

Common pitfalls: DLX without consumers so failures accumulate silently; replaying without fixing root cause; losing context headers during re-publish; same DLX for retries and final quarantine without separation.

The trade-off is flexibility versus complexity—know when the simpler path is enough.

Checklist:

  • Attach DLX to queues with failure paths.
  • Monitor dead-letter depth and age.
  • Separate retry DLX from final quarantine.
  • Preserve metadata for diagnosis and replay.