On this page
Kafka Improvement Proposal
KIP-447: exactly-once v2, one producer per app instead of per partition
KIP-447 made exactly-once stream processing cheap enough to use widely. Before it, an app needed one transactional producer for every input partition it read, so that a zombie instance could be fenced. KIP-447 fences zombies with the consumer group generation instead, so one producer per app instance is enough. Kafka Streams calls this mode exactly_once_v2.
- Proposal
- KIP-447, Producer scalability for exactly once semantics
- Status
- Shipped Since Kafka 2.5 (2020), in Kafka Streams since 2.6; called exactly_once_v2 since 3.0.
- Area
- Producers and transactions
- Proposal page
- KIP-447 on the Apache Kafka wiki
Why it was needed
An exactly-once app reads records, processes them, writes the results and commits its input offsets in one transaction. If an instance stalls and the group gives its partitions to another instance, the old one must not be able to commit anymore. KIP-98 fenced it through the transactional.id, which had to be tied to the input partition. An app reading 1,000 partitions ran 1,000 producers, each with its own connections, buffers and coordinator state.
What it changes
The producer now sends the consumer group metadata (group id, generation and member id) along with the offsets it commits inside the transaction, through sendOffsetsToTransaction. The group coordinator rejects a commit from a member whose generation is stale, so the zombie is fenced by the consumer group rather than by the transactional.id. Each app instance needs a single transactional producer, whatever the number of partitions.
How to use it
- In Kafka Streams, set processing.guarantee=exactly_once_v2 (needs brokers on 2.5 or newer).
- In a hand-written consume, process, produce loop, pass consumer.groupMetadata() to producer.sendOffsetsToTransaction().
Where it stands
Shipped in Kafka 2.5 for brokers and clients, and in Kafka Streams 2.6 as exactly_once_beta. Kafka 3.0 renamed it exactly_once_v2 and deprecated the original per-partition mode, which Kafka 4.0 removed. It is the standard way to run exactly-once Kafka Streams apps.
What comes next
Exactly-once v2 is complete. The ongoing transaction work is on the broker side: KIP-890 changed the transaction protocol so each transaction bumps the producer epoch, which closes the remaining gaps where a late write from an old transaction could slip into a new one.
See it in the simulator
- Kafka processing.guarantee=exactly_once_v2 end to end (exactly_once_v2 end-to-end) Step 8: zombie fenced Open at this step: Kafka processing.guarantee=exactly_once_v2 end to end
- Kafka processing.guarantee=exactly_once_v2 end to end (exactly_once_v2 end-to-end) Step 7: commit · output + offsets Open at this step: Kafka processing.guarantee=exactly_once_v2 end to end
Sources
- KIP-447: Producer scalability for exactly once semantics
- KIP-732: Deprecate eos-alpha and replace eos-beta with eos-v2