Why does the order of "do the work" and "ack" matter?
Sketch your own answer first, then compare it with the one below.
A strong answer
The ack tells the broker to forget the message. If you ack first and crash before the work, the message is gone and the work never happens. If you work first and crash before the ack, the broker redelivers and the work happens again.
So the order picks which failure you accept: loss or repetition. The broker cannot tell a crash before the work from a crash after it, because both look like a missing ack.
Most systems choose repetition, then make the work safe to repeat.
Sources
- RabbitMQ documentation (2024). Consumer acknowledgements and publisher confirms.
- Martin Kleppmann (2017). Designing Data-Intensive Applications.