Kafka Exception ProducerFencedException
org.apache.kafka.common.errors.ProducerFencedException
Non-retriable
Transactions
This fatal exception indicates that another producer with the same transactional.id has been started. It is only possible to have one producer instance with a transactional.id at any given time, and the latest one to be started "fences" the previous instances so that they can no longer make transactional requests. When you encounter this exception, you must close the producer instance.
Common Causes
- A new producer instance was initialized with the same transactional.id, causing the broker to bump the producer epoch and fence all older instances with the same ID
- Producer application restarted (crash, rolling deploy) and created a new transactional producer before the old one was cleanly shut down
- Two independent application instances were accidentally configured with the same transactional.id, creating a conflict
Solutions
- Ensure transactional.id is unique per logical producer stream and that only one producer instance with that ID is active at a time — treat fencing as a correctness signal, not a bug
- On receiving PRODUCER_FENCED, do not retry with the same producer instance — create a new KafkaProducer with initTransactions() to get a fresh epoch
- Audit your deployment to guarantee no duplicate transactional.id values exist across instances; use a registry or naming convention based on partition assignment
Example Stack Trace
org.apache.kafka.common.errors.ProducerFencedException: There is a newer producer with the same transactionalId which fences the current one.Diagnostic Commands
# Inspect transaction-state topic health
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic __transaction_state | grep -E 'Leader|Isr|Replicas'
# Look for producer epoch events in logs
grep 'ProducerFencedException\|producer fenced\|epoch' /var/log/app/*.log | tail -20Related
Protocol error: PRODUCER_FENCED (code 90)
Related Transactions exceptions: ConcurrentTransactionsException · InvalidTxnStateException
Hitting
ProducerFencedException in production? Conduktor Console gives you real-time visibility into clients, consumer groups, and broker health. Browse every Kafka exception or protocol error code.