Every few months, a design review reaches the same moment. Someone asks, "We'll just turn on exactly-once, right?" The room relaxes, because surely the broker will take care of duplicates.
Here is my take after working on payment and inventory flows: exactly-once delivery is the wrong goal for application code. It isn't a feature you switch on. At best it is a property of a narrow pipeline, and it stops at the first side effect you actually care about. The goal worth designing for is at-least-once delivery plus idempotent processing . That combination is boring and testable, and it keeps working when the network, the broker, or your own process misbehaves. They will.
This post explains why, then shows a small pattern I use, with four PostgreSQL-backed tests that make the trade-offs concrete.
Full source and tests: github.com/1995mars/motdev-samples/tree/main/idempotent-consumer
Why the broker can't promise what you want
Picture a consumer's loop: receive a message, apply its effect, acknowledge it.…