How should retries and poison messages be handled?
Retrying immediately in a tight loop amplifies outages. Instead:
- Classify errors: retry transient ones (timeouts, 503, deadlocks) and stop retrying permanent ones (schema violations, 400-class errors).
- Retry with exponential backoff and jitter, and cap attempts.
- Use delayed retry queues or scheduled redelivery so the broker, not the consumer, holds the delay.
- After the cap, route to a dead-letter queue with the error and attempt count, and alert.
max-attempts: 5
backoff: "1s, 5s, 30s, 5m"
Ensure the consumer is idempotent, since retries can process the same message twice. Watch out for the head-of-line problem: a message that always fails can block a partition if retried in place, so move it aside quickly. Also add circuit breakers for downstream calls so retries do not pile onto a service that is already failing, and load-test the retry path.