The Three Guarantees
| Guarantee | Meaning | How you get it | Risk |
|---|---|---|---|
| At-most-once | Each message delivered zero or one time | Producer acks=0, or consumer commits before processing | Loss |
| At-least-once | Each message delivered one or more times | acks=all + retries, consumer commits after processing | Duplicates |
| Exactly-once | Each message's effect happens once | Idempotent producer + transactions + read_committed (inside Kafka), idempotent or transactional sinks outside | More complexity and some latency |
Step 1: Idempotent Producer (Per-Partition Exactly Once)
The broker tracks each producer's id and per-partition sequence numbers, so retries do not create duplicates inside one producer session and partition. See the producer reliability lesson.
Step 2: Transactions (Atomic Writes to Many Partitions and Topics)
A transaction lets a producer write to several partitions and topics (and commit consumer offsets) so that either all become visible or none.
Step 3: Consumers Must Read Committed Data
isolation.level | Behaviour |
|---|---|
read_uncommitted (default) | Sees everything, including records of aborted transactions |
read_committed | Sees only committed transactional records and non-transactional records. May wait for open transactions to finish (higher end-to-end latency) |
Consume-Transform-Produce: Exactly-Once Pipeline
The classic use: read from topic A, compute, write to topic B, and record the input offset in the same transaction. After a crash, either both the output and the offset commit happened, or neither.
processing.guarantee=exactly_once_v2 and it handles transactions, offsets and fencing.
Zombie Fencing
If an application instance is paused (long GC or network partition) and a replacement starts with the same transactional.id, the old instance is a zombie. When the new one calls initTransactions(), the broker bumps the producer epoch, and the zombie's later writes are rejected with ProducerFencedException. This is why the transactional.id must be stable and unique per logical worker (for example derived from the input partition or the pod name).
Transaction Settings
| Setting | Meaning |
|---|---|
transactional.id | Identity of the producer across restarts |
transaction.timeout.ms (producer, default 60 s) | A transaction not completed in this time is aborted by the broker |
transaction.max.timeout.ms (broker) | Upper limit for the producer timeout |
transaction.state.log.replication.factor, transaction.state.log.min.isr | Replication of the internal transaction topic. Use 3 and 2 in production |
What Exactly-Once Does Not Cover
| Pipeline | Realistic guarantee |
|---|---|
| Kafka to Kafka with transactions or Kafka Streams EOS | Exactly-once |
| Kafka to database with an idempotent upsert | Effectively exactly-once |
| Kafka to HTTP call or email | At-least-once. Send an idempotency key |
| Database to Kafka (outbox, CDC) | At-least-once into Kafka, deduplicate downstream by event id |
Conclusion
At-least-once with idempotent handlers is the practical default. Exactly-once inside Kafka uses idempotent producers, transactions with sendOffsetsToTransaction, stable transactional.ids and read_committed consumers. It does not make external side effects exactly-once.

