Home / Kafka / Brokers and partitions
Kafka: NotLeaderOrFollowerException: the broker is not the current leader
org.apache.kafka.common.errors.NotLeaderOrFollowerExceptionFor 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.A client sent a request to a broker that is no longer the leader of the partition, usually during a leader election or broker restart. Clients refresh metadata and retry automatically, so occasional warnings are normal; persistent ones point to unstable brokers.
Common causes
- A broker restarted or a partition reassignment moved leadership.How to confirm: Broker logs show controlled shutdown, restarts or reassignment around the time of the warnings.
- Brokers fall out of the cluster repeatedly (session timeouts, long GC), causing frequent leader elections.How to confirm: The UnderReplicatedPartitions and leader election rate metrics spike repeatedly.
How to fix it
Usually no action: the client retries. Make sure retries are not disabled and the delivery timeout covers a leader election.
| Setting | Default | Note |
|---|---|---|
retries | 2147483647 | |
delivery.timeout.ms | 120000 |
If it is constant, stabilize the brokers: check GC, disk and network, and why brokers lose their session.
Where the message comes from
Errors.javainapache/kafkaat4.3.2- Message checked in Kafka 4.3.2. Older clients report NotLeaderForPartitionException instead.