Kafka Error NOT_LEADER_OR_FOLLOWER
Error code 6 · Retriable Broker
For requests intended only for the leader, this error indicates that the broker is not the current leader. For requests intended for any replica, this error indicates that the broker is not a replica of the topic partition.
Common Causes
- Metadata is stale on the client — it cached the old leader and is sending requests to a broker that is no longer the leader after a failover
- Partition reassignment moved the partition to different brokers but the client has not refreshed its metadata cache yet
- Consumer fetching with 'replica.selector.class' (rack-aware fetch) sending to a follower that lost its assignment
Solutions
- Lower 'metadata.max.age.ms' (e.g. 60000ms) on producers/consumers so metadata refreshes more frequently after leader changes
- After a broker rolling restart or partition reassignment, force client reconnection or wait for the default metadata refresh cycle to complete
- Check that all brokers in the cluster are healthy and reachable; a broker stuck in recovery can cause repeated leader-not-available / not-leader cycles
Diagnostic Commands
# Check for under-replicated partitions
kafka-topics.sh --describe --bootstrap-server localhost:9092 --under-replicated-partitions
# Verify broker connectivity and API versions
kafka-broker-api-versions.sh --bootstrap-server <broker>:9092 2>&1 | head -5Related APIs
This error can be returned by: DescribeLogDirs · EndTxn · Fetch · InitProducerId · Produce · WriteTxnMarkers
Debugging Kafka errors? Conduktor Console gives you real-time visibility into your cluster. Explore all errors in the Error Decoder.