Kafka Error INVALID_PRODUCER_EPOCH
Error code 47 · Non-retriable Producer
Producer attempted to produce with an old epoch.
Common Causes
- Two producer instances sharing the same transactional.id are running concurrently — the newer one fenced the older one by bumping the epoch
- Producer was considered dead by the broker (transaction.timeout.ms exceeded) and a new epoch was assigned; the old instance then tried to produce
- Rolling restart or failover created a brief period where two instances of the same transactional producer were active simultaneously
Solutions
- Ensure only one producer instance per transactional.id is active at any time; use leader election or distributed locks to enforce singleton producers
- Increase transaction.timeout.ms to give producers more time before being fenced, but keep it below transaction.max.timeout.ms on the broker
- After fencing, the old producer must be closed and a new instance created — the fenced producer cannot recover and must not be retried
Diagnostic Commands
# Look for producer epoch events in logs
grep 'INVALID_PRODUCER_EPOCH\|InvalidProducerEpoch\|producer epoch\|fenced' /var/log/kafka/server.log | tail -30
# Inspect transaction-state topic health
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic __transaction_state | grep -E 'Leader|Isr|Replicas'Related APIs
This error can be returned by: AddOffsetsToTxn · AddPartitionsToTxn · EndTxn · InitProducerId · Produce · WriteTxnMarkers
Debugging Kafka errors? Conduktor Console gives you real-time visibility into your cluster. Explore all errors in the Error Decoder.