RabbitMQ
Dead Letter Exchanges (DLX)
Capture messages that fail, expire, or overflow instead of losing them or looping forever.
A Dead Letter Exchange is where RabbitMQ sends messages that cannot be delivered normally. A message is dead-lettered in three situations: it is rejected/nacked with requeue=false, it exceeds its TTL, or the queue exceeds its length limit. Configuring a queue with x-dead-letter-exchange reroutes such messages to the DLX, which delivers them to a dead-letter queue for inspection, alerting, or retry.
An undeliverable-mail office: letters that bounce, expire, or overflow the mailbox are not thrown away but collected in a dead-letter room where staff investigate, fix the address, and re-send.
Key Concepts
1
This is the foundation of robust error handling. A poison message (one that always fails) would otherwise loop forever if requeued; sending it to a DLX after N attempts isolates it for a human or a separate recovery process. The original message is preserved along with headers describing why and how often it was dead-lettered.
2
A common pattern combines DLX with TTL to build delayed retries: messages sit in a wait queue with a TTL, then dead-letter back to the work queue after the delay.
3
What the interviewer is probing.
What the interviewer is probing.
4
1. "What sends a message to a DLX?" *Probing:* the triggers. *Stalls:* "A failure." *Moves up:*
rejection with requeue false, TTL expiry, or exceeding the queue length limit.
1. "What sends a message to a DLX?"
5
2. "Why is a DLX essential?" *Probing:* the operational argument. *Stalls:* "Tidiness." *Moves
up:* without it a failing message is either lost or loops forever — the DLX makes failure visible
and recoverable.
2. "Why is a DLX essential?"
6
3. "How do you build a delayed retry with it?" *Probing:* the pattern. *Stalls:* "A sleep."
*Moves up:* a wait queue with a TTL whose DLX points back at the work queue, so the message returns
after the delay.
3. "How do you build a delayed retry with it?"
7
4. "What must you add to avoid an infinite retry loop?" *Probing:* the engineering. *Stalls:*
"Nothing." *Moves up:* a retry count in the headers with a cap, after which it goes to a parking
queue for human review.
4. "What must you add to avoid an infinite retry loop?"