Name the ways a consumer can end up processing the same message twice without any crash.
Sketch your own answer first, then compare it with the one below.
A strong answer
A slow consumer is the main one. If processing takes longer than the ack timeout, the broker redelivers while the first attempt is still running, and both finish.
Others include a lost ack, where the consumer finished but the ack never reached the broker. A producer that retries a send that did succeed leaves two copies in the queue. A rebalance or failover can hand the same message to a second consumer. A replay deliberately repeats history.
So duplicates are routine, not rare. That argues for an idempotent consumer, not for hoping the timeouts are tuned right.
Sources
- RabbitMQ documentation (2024). Consumer acknowledgements and publisher confirms.
- Amazon Web Services documentation (2024). Amazon SQS visibility timeout.
- Martin Kleppmann (2017). Designing Data-Intensive Applications.