Exactly Once Delivery
Exactly-once delivery is the strongest message delivery semantic, guaranteeing that each message is processed precisely one time — neither lost (at-most-once) nor processed multiple times (at-least-once) — even in the presence of producer retries, consumer failures, and network partitions.
Exactly-once delivery is the strongest message delivery semantic, guaranteeing that each message is processed precisely one time — neither lost (at-most-once) nor processed multiple times (at-least-once) — even in the presence of producer retries, consumer failures, and network partitions.
True exactly-once delivery requires coordination at both the producer and consumer levels, and is significantly harder to achieve than the two weaker semantics it supersedes.
At-most-once delivery is the simplest: the producer sends without retrying, so messages can be lost on network failure but are never duplicated. At-least-once delivery adds producer retries and consumer-side offset commits after processing, ensuring no message is lost but allowing duplicates if a crash occurs between processing and committing. Exactly-once combines idempotent production with transactional commit to close the duplication window.
In Kafka, exactly-once semantics (EOS) are implemented through two mechanisms working together. On the producer side, enable.idempotence=true gives each producer a unique PID and assigns monotonically increasing sequence numbers to each message per partition. The broker deduplicates retried messages using these sequence numbers. On the consumer-producer side (for stream processing), Kafka transactions (transactional.id) allow an atomic operation: read from source partitions, process, write to output partitions, and commit offsets — all as a single atomic unit. Either all succeed or all are rolled back.
The cost is latency: transactional commits require additional broker round-trips. For most applications, Idempotent Consumer design achieves the same practical outcome — deduplicated side effects — without the Kafka transaction overhead, by tracking processed Message Deduplication keys at the application level.