On this page
Kafka Improvement Proposal
KIP-98: exactly once with the idempotent producer and transactions
KIP-98 gave Kafka two things. The idempotent producer lets the broker spot a retried batch and drop the copy, so a lost acknowledgement no longer means a duplicate. Transactions let a producer write to several partitions and commit or abort them together, so a read_committed consumer sees all of it or none.
- Proposal
- KIP-98, Exactly Once Delivery and Transactional Messaging
- Status
- Shipped Since Kafka 0.11 (2017). Idempotence is on by default since Kafka 3.0.
- Area
- Producers and transactions
- Proposal page
- KIP-98 on the Apache Kafka wiki
Why it was needed
Before KIP-98, a producer that sent a batch and never heard back had two bad choices. Retry, and risk writing the same records twice if the first write had in fact succeeded. Or give up, and risk losing them. Stream processing made it worse: an app that reads, processes and writes could crash between writing its output and committing its input offsets, and on restart it would produce the same output again.
What it changes
Every idempotent producer gets a producer id, and every batch it sends to a partition carries a sequence number. The broker remembers the last sequence numbers per producer and partition, so a retry of a batch it already has is acknowledged without a second write. Transactions build on that: a transactional.id ties the producer to a transaction coordinator, the producer marks which partitions it writes to, and commit or abort writes a marker into each of them. Consumers with isolation.level=read_committed only read up to the last stable offset, so they never see records of an open or aborted transaction.
How to use it
- Idempotence needs nothing on Kafka 3.0 or newer: enable.idempotence=true and acks=all are the defaults.
- For transactions, set transactional.id on the producer and wrap sends in beginTransaction() and commitTransaction(); set isolation.level=read_committed on the consumers that must not see aborted data.
Where it stands
Shipped in Apache Kafka 0.11 in 2017 and part of every release since. KIP-679 made idempotence the producer default in Kafka 3.0. Transactions stay opt-in, because they need a transactional.id and read_committed consumers.
What comes next
The design keeps evolving through follow-up KIPs. KIP-447 made exactly-once stream processing scale, and KIP-890 hardened transactions on the broker side against hanging and zombie transactions: part one shipped in Kafka 3.6, and part two, a new transaction protocol that bumps the producer epoch on every transaction, is on once a cluster finishes its upgrade to Kafka 4.0.
See it in the simulator
- Kafka idempotent producer dedup vs a plain producer (Idempotent dedup vs duplicate) Step 3: Lost ack → p-idem re-sends seq 0 → DEDUPED (no second write) Open at this step: Kafka idempotent producer dedup vs a plain producer
- Kafka transaction commit vs abort with read_committed (Transactional write: commit vs abort) Step 7: abort · range skipped Open at this step: Kafka transaction commit vs abort with read_committed
- Kafka idempotent producer: retrying NOT_ENOUGH_REPLICAS (Idempotence retry) Step 4: broker-2 back - the in-flight retry commits exactly once Open at this step: Kafka idempotent producer: retrying NOT_ENOUGH_REPLICAS
Sources
- KIP-98: Exactly Once Delivery and Transactional Messaging
- KIP-679: Producer will enable the strongest delivery guarantee by default