Kafka Exception FencedLeaderEpochException
org.apache.kafka.common.errors.FencedLeaderEpochException
Retriable
Broker
The request contained a leader epoch which is smaller than that on the broker that received the request. This can happen when an operation is attempted before a pending metadata update has been received. Clients will typically refresh metadata before retrying.
Common Causes
- A follower or stale leader is still sending requests using an old leader epoch after a new leader election has occurred
- Consumer or producer cached stale metadata and is writing/reading from a broker that is no longer the leader for that partition
- Split-brain during controller failover: old controller still issuing LeaderAndIsr requests with a lower epoch than the new controller
Solutions
- This is retriable — the client will refresh metadata and retry against the new leader automatically; no manual action needed in most cases
- Force a metadata refresh on the client side if the error persists: restart the consumer or producer, or wait for the next metadata refresh cycle; `producer.flush()` does not refresh metadata
- Investigate controller logs for repeated rapid leader elections — may indicate broker instability, GC pauses, or network partitions
Example Stack Trace
org.apache.kafka.common.errors.FencedLeaderEpochException: The leader epoch in the request is older than the epoch on the broker.Diagnostic Commands
# Look for epoch fencing events in logs
grep 'FencedLeaderEpoch\|leader.epoch\|LeaderAndIsr' /path/to/kafka/logs/controller.log | tail -30
# Describe topic replicas and ISR status
kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic <topic> | grep -E 'Leader|Isr|Replicas'Related
Protocol error: FENCED_LEADER_EPOCH (code 74)
Related Broker exceptions: CorruptRecordException · LeaderNotAvailableException · NetworkException · NotEnoughReplicasAfterAppendException · NotEnoughReplicasException · NotLeaderOrFollowerException · TimeoutException · UnknownLeaderEpochException
Hitting
FencedLeaderEpochException in production? Conduktor Console gives you real-time visibility into clients, consumer groups, and broker health. Browse every Kafka exception or protocol error code.