Scrivio Interview library
InternalsIntermediate6 min read · updated 12 November 2026

How do transactional producers fence zombie instances, and why did Kafka add the EOS v2 (exactly_once_v2) mode for Kafka Streams and consume-transform-produce applications?

Every transactional.id has an epoch stored by the transaction coordinator. When a producer calls initTransactions() with an id, the coordinator bumps the epoch and aborts any open transaction of the previous holder, so an old instance that wakes up later is rejected as fenced. In the original design, fencing a zombie consumer-producer required one transactional producer per input partition; KIP-447 lets the broker fence using the consumer group metadata sent with sendOffsetsToTransaction, so one producer per thread is enough, which is what Kafka Streams' exactly_once_v2 and Spring Kafka's EOSMode.V2 use.

Why this question is asked

Exactly-once processing in Kafka depends on stopping zombies: instances that were considered dead, replaced by a new instance, and then come back to life and keep writing. Interviewers ask this internals question to see whether we understand how transactions stay correct during failures and rebalances, and why the second version of exactly-once was needed. In this answer, we will recap transactional producers, see how epochs fence a zombie with the same transactional.id, look at why the original consume-transform-produce design needed a producer per partition, and then see how KIP-447 removed that need and what it means for Kafka Streams and Spring Kafka.

1A Quick Recap of Transactional Producers

A transactional producer is configured with a transactional.id, a name that stays the same across restarts of the same logical producer. On startup it calls initTransactions(). The broker that acts as its transaction coordinator, chosen by hashing the transactional.id, records the producer's id and an epoch for that transactional.id in the internal __transaction_state topic.

Each transaction then registers the partitions it writes to, writes records, optionally adds consumer offsets with sendOffsetsToTransaction, and ends with commitTransaction() or abortTransaction(). The coordinator writes commit or abort markers into every partition involved, and read_committed consumers use those markers to show only committed data.

2How Epochs Fence a Zombie

Suppose instance A runs with transactional.id payments-1, epoch 4. It stalls in a long garbage-collection pause, the orchestrator decides it is dead, and starts instance B with the same transactional.id. B calls initTransactions(). The coordinator aborts any transaction A had open, bumps the epoch to 5 and gives it to B.

Now A wakes up and tries to send records or commit with epoch 4. The broker sees that the epoch is older than the current one and rejects the request; A gets a ProducerFencedException (or a closely related fencing error, depending on version) and must close. Only one producer per transactional.id can ever be active, and the newest always wins.

Step throughFencing by transactional.id epoch
Instance A (zombie)CoordinatorInstance B
initTransactions(payments-1) -> epoch 4
long GC pause; considered dead
initTransactions(payments-1)
abort A's open transaction, epoch -> 5
epoch 5
commitTransaction() with epoch 4
rejected: producer fenced

7 messages in order. Play them, or step through them one at a time.

The newest epoch wins; the zombie can no longer commit.

3Why the Original Design Needed a Producer per Partition

Fencing by transactional.id works only if the zombie and its replacement use the same id. In a consume-transform-produce application, the work that moves between instances is an input partition. When a rebalance moves partition orders-3 from instance A to instance B, it is B that must fence A's leftover work on orders-3.

So in the original exactly-once design (EOS v1), the transactional.id had to be tied to the input partition, for example group-orders-3. Each instance created one transactional producer for every input partition it owned. An application reading 100 partitions needed 100 producers in total, each with its own connections, buffers and coordinator state, and every rebalance closed and created producers. Kafka Streams worked this way with processing.guarantee=exactly_once, and Spring Kafka's older ALPHA mode did the same. It was correct but expensive, which made exactly-once hard to use at scale.

EOS v1 compared with EOS v2
AspectEOS v1EOS v2 (KIP-447)
ProducersOne per input partitionOne per thread / consumer
transactional.id tied togroup + topic + partitionthe instance or thread
Zombie fenced bytransactional.id epochconsumer group generation
Broker version0.11 and later2.5 and later
Kafka Streams settingexactly_once (removed in 4.0)exactly_once_v2

4How KIP-447 Fences With Group Metadata

KIP-447, delivered in Kafka 2.5, changed what proves a zombie is a zombie. Instead of relying only on the transactional.id, the producer now sends the consumer's group metadata with its offsets: producer.sendOffsetsToTransaction(offsets, consumer.groupMetadata()). That metadata includes the group id, the member id and the generation, a number the group coordinator increments on every rebalance.

When the transaction tries to commit offsets for orders-3, the group coordinator checks the generation. If a rebalance has happened since A got the partition, A's generation is old, and the offset commit is rejected, which fails A's whole transaction. A also learns that it lost the partition and stops processing it. B, which now owns orders-3 in the new generation, can commit normally. The consumer group itself, which already knows exactly who owns which partition, does the fencing.

Java
// One producer per consumer thread is now enough
producer.beginTransaction();
producer.send(outputRecord);
producer.sendOffsetsToTransaction(offsets, consumer.groupMetadata()); // carries member id + generation
producer.commitTransaction();
// A zombie from an older generation: the offset commit is rejected and the transaction fails

Notice that this needs a fetch-side rule too: a consumer must not read a partition's data while an earlier owner's transaction on it might still commit. KIP-447 makes the new owner's offset fetch wait until pending transactional offsets for that partition are resolved, so it never starts from a stale position.

5What It Means for Kafka Streams and Spring Kafka

Kafka Streams turns this on with processing.guarantee=exactly_once_v2, available since Kafka 3.0 (it was called exactly_once_beta before). The older exactly_once and exactly_once_beta values were deprecated and are removed in Kafka 4.0, so v2 is the only exactly-once mode today. Each stream thread uses a single producer for all its tasks.

Spring Kafka offers the same through its listener containers. When the container factory has a KafkaTransactionManager and the container's EOSMode is V2, the container begins a transaction for each delivery, sends offsets with the consumer's group metadata, and commits. Since Spring Kafka 3.0, V2 is the only mode and the default, so check your version only if you maintain an older application. The practical effect is that exactly-once now costs a producer per consumer thread rather than per partition, which makes it realistic for applications reading hundreds of partitions.

YAML
spring:
kafka:
producer:
transaction-id-prefix: tx-ledger- # enables a KafkaTransactionManager in Spring Boot
consumer:
isolation-level: read_committed
enable-auto-commit: false

6Follow-up questions

If KIP-447 fences by group generation, does the transactional.id still matter?

Yes. It still identifies the producer to the transaction coordinator, lets a restarted producer abort its own unfinished transaction, and fences a duplicate instance that uses the same id. It just no longer has to encode the input partition, so it can be stable per application instance or thread.

What happens to records written by the fenced zombie?

They belong to a transaction that is aborted, either by the coordinator when the new producer initialises or when the commit is rejected. read_committed consumers skip them. They stay in the log until retention removes them, but they never become visible to correct readers.

What changed in Kafka 4.0 around transactions?

Kafka 4.0 removed the old EOS v1 modes from Kafka Streams and began rolling out KIP-890, a server-side defence that bumps the epoch on every transaction to close some edge cases with hanging transactions. Check your version for whether it is enabled on your cluster.

7Conclusion

In this answer, we saw that transactional producers are fenced by an epoch per transactional.id: a new producer with the same id bumps the epoch and the old one can no longer commit. In consume-transform-produce applications, the original design needed a producer per input partition so that the same id followed the partition across rebalances. KIP-447 lets the broker fence zombies using the consumer group generation sent with sendOffsetsToTransaction, so one producer per thread is enough, which is what exactly_once_v2 in Kafka Streams and EOSMode.V2 in Spring Kafka use.

What to say in the interviewAbout 80 seconds aloud

Open with

Each transactional producer has a transactional.id, and the transaction coordinator keeps an epoch for it. When a producer calls initTransactions, the coordinator aborts any open transaction for that id and bumps the epoch, so if the old instance comes back from, say, a GC pause and tries to write or commit with the older epoch, the broker rejects it as fenced.

Then, if they want more

For consume-transform-produce, the work that moves between instances is an input partition, so in the original design the transactional.id had to be tied to the partition: one producer per input partition, so the new owner could fence the old owner with the same id. That meant hundreds of producers and a lot of churn on every rebalance.

KIP-447, in Kafka 2.5, changed this. The producer now sends the consumer's group metadata, including the generation, with sendOffsetsToTransaction, and the group coordinator rejects offset commits from an older generation. So the group itself fences zombies, and one producer per consumer thread is enough.

Kafka Streams uses this with processing.guarantee exactly_once_v2, and the old v1 modes are gone in Kafka 4. In Spring Kafka, a container with a KafkaTransactionManager uses EOSMode V2, which is the only mode since 3.0. The result is much lower resource use, which makes exactly-once practical at scale.

About this answer

Last updated
12 November 2026
Versions it names
Kafka 3.0, Kafka 4.0, Kafka 2.5
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How do transactional producers fence zombie instances, and why did Kafka add the EOS v2...": https://scrivio-interview-library.netlify.app/spring-boot/kafka/0acc4c6e8a/