conduktor.io ↗

Kafka Exception NotLeaderOrFollowerException

org.apache.kafka.common.errors.NotLeaderOrFollowerException
Retriable Broker

Broker returns this error if a request could not be processed because the broker is not the leader or follower for a topic partition. This could be a transient exception during leader elections and reassignments. For `Produce` and other requests which are intended only for the leader, this exception indicates that the broker is not the current leader. For consumer `Fetch` requests which may be satisfied by a leader or follower, this exception indicates that the broker is not a replica of the topic partition.

Common Causes

Solutions

Example Stack Trace

org.apache.kafka.common.errors.NotLeaderOrFollowerException: 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.

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 -5

Related

Protocol error: NOT_LEADER_OR_FOLLOWER (code 6)

Related Broker exceptions: CorruptRecordException · FencedLeaderEpochException · LeaderNotAvailableException · NetworkException · NotEnoughReplicasAfterAppendException · NotEnoughReplicasException · TimeoutException · UnknownLeaderEpochException

Hitting NotLeaderOrFollowerException in production? Conduktor Console gives you real-time visibility into clients, consumer groups, and broker health. Browse every Kafka exception or protocol error code.