Skip to content
Kafka Is Fun

Lesson 4 of 5

Preferred Leader Election

1 min read

Overview

Each partition has a preferred replica: the first one in its replica list (for a list of 1,5,9, node 1 is preferred). When a broker restarts it becomes a follower for all its partitions, so leadership can end up unbalanced. By default the cluster restores leadership to the preferred replicas automatically (auto.leader.rebalance.enable=true, checked every leader.imbalance.check.interval.seconds). You can also run the election yourself with kafka-leader-election.sh. The design page says the aim is to balance leadership so that each node leads a proportional share of the partitions.

Key configuration

Settings and commandproperties
auto.leader.rebalance.enable=true — default
leader.imbalance.check.interval.seconds=300 — default
bin/kafka-leader-election.sh --bootstrap-server localhost:9092 --election-type preferred --all-topic-partitions

Production tip

Check yourself

What does preferred leader election do?

Sources

Checked against Kafka 4.2 documentation on Oct 2026. Draft: not yet reviewed by a Kafka specialist. Releases move on, so confirm against the current documentation before you act on a number.

Try it in the simulator

Guided scenarios for this module — the simulator opens with the exercise already running.

Prefer a picture? Open the live cluster in 3D and watch records move between producer, brokers and consumers.

Browse all troubleshooting entries