In distributed systems, the "Exactly-Once" delivery guarantee is an expensive abstraction that is often impossible to achieve at scale. Most systems provide At-Least-Once delivery, meaning a message may be delivered multiple times due to network retries, timeouts, or leader failovers. The Idempotent Receiver pattern ensures that processing a message more than once results in the same system state as processing it exactly once.
Some operations are inherently idempotent and require no special logic.
UPDATE user SET status = 'ACTIVE' (Multiple calls result in the same state).DELETE FROM orders WHERE id = 123.Operations that change state incrementally must be made idempotent via explicit tracking.
UPDATE accounts SET balance = balance + 100.POST /orders (Multiple calls could create duplicate orders).The sender attaches a unique identifier (e.g., a UUID or a deterministic hash of the payload) to every request.
Leveraging the database's ability to enforce uniqueness.
order_id in an orders table. A retry will trigger a "Unique Constraint Violation," which the receiver catches and treats as a success.Common in stream processing (Kafka/TCP). The receiver tracks the last processed sequence number. Any message with a number \le the high-water mark is discarded.