Day 96: RabbitMQ: DLQs, retries, idempotent consumers
What happens when processing a message fails
A Dead Letter Queue (DLQ) is where messages go after they fail processing repeatedly (or are rejected, or expire) — instead of being lost or retried forever, they land somewhere a human or automated process can inspect and decide what to do.
Message fails processing
-> requeued with incremented retry count
-> after N retries, routed to dead-letter-exchange
-> lands in orders.dlq for manual/automated inspectionPrefetch limits how many unacknowledged messages a consumer can hold at once — without it, a fast publisher can flood a slow consumer with more messages than it can handle, exhausting its memory. Priority queues let some messages jump ahead of others (e.g. a paid customer's request over a free-tier one).
Idempotent consumers, revisited
Retries mean at-least-once delivery (Phase 7, Day 46) — a message might be processed twice if an ack is lost after processing but before acknowledgment. An idempotent consumer (tracking processed message IDs, or making the operation itself naturally idempotent) makes this safe rather than trying to eliminate duplicates outright, which Day 46 already established is generally not achievable.
Key terms
- Dead Letter Queue (DLQ)
- Where repeatedly-failed or rejected messages are routed for inspection instead of being lost or retried forever.
- Prefetch
- Limits how many unacknowledged messages a consumer holds at once, preventing overload.
Why does a consumer need to be idempotent even with a well-configured retry + DLQ setup?