A message has failed processing five times in a row. What should happen to it, and why not retry forever?
Sketch your own answer first, then compare it with the one below.
A strong answer
It should move to a dead-letter queue after a set number of attempts. Most brokers can do this by a configured limit: in SQS it is the max receive count on the redrive policy.
Retrying forever has two costs. First, the message occupies consumer time on every attempt. A message that fails in 50 ms and is redelivered at once burns 20 attempts a second. Second, in an ordered queue it can block the messages behind it.
The dead-letter queue keeps the message for a person or a repair job. It only helps if somebody looks, so alarm on anything arriving there, keep the original body with the last error, and give it a longer retention than the source queue.
Also separate failures by kind. A validation error will never succeed, so it can be dead-lettered at once. A timeout from a dependency might heal, so it gets more attempts spaced further apart.
Sources
- Amazon Web Services documentation (2024). Using dead-letter queues in Amazon SQS.
- Martin Kleppmann (2017). Designing Data-Intensive Applications.