Quick revision
The short answer
The preferred replica of a partition is the first replica in its assignment list, and topic creation spreads those first replicas evenly across brokers, so leadership is balanced when every partition is led by its preferred replica. After a rolling restart, partitions moved to other leaders while their preferred broker was down, and it came back only as a follower, so leadership stays skewed until a preferred leader election runs. With auto.leader.rebalance.enable=true (the default) the controller checks every 300 seconds and moves leaders back where a broker's imbalance exceeds 10 percent; by hand we run kafka-leader-election.sh --election-type PREFERRED.
What to remember
In this answer, we saw that the preferred replica is the first broker in a partition's assignment and that topic creation spreads preferred leaders evenly. A rolling restart moves leadership away from each restarted broker and does not give it back, so leadership piles up until a preferred leader election runs. The controller does that automatically every 300 seconds when imbalance exceeds 10 percent and the feature is enabled, we can run kafka-leader-election.sh --election-type PREFERRED by hand, and if the assignments themselves are unbalanced we need a reassignment instead.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The preferred replica of a partition is the first replica in its assignment list, and topic creation spreads those first replicas evenly across brokers, so leadership is balanced when every partition is led by its preferred replica. After a rolling restart, partitions moved to other leaders while their preferred broker was down, and it came back only as a follower, so leadership stays skewed until a preferred leader election runs. With auto.leader.rebalance.enable=true (the default) the controller checks every 300 seconds and moves leaders back where a broker's imbalance exceeds 10 percent; by hand we run kafka-leader-election.sh --election-type PREFERRED.
Why this question is asked
A broker leading 40 percent of the partitions takes 40 percent of the produce traffic and most of the consumer reads, so it runs hot while others sit idle, and it becomes the bottleneck for the whole cluster. This happens after almost every rolling restart unless something rebalances leadership. Interviewers ask about it because it is a frequent operational issue and because the answer separates two different kinds of imbalance, leadership and replica placement. In this answer, we will recap what the preferred replica is, see how the skew appears, see how automatic rebalancing works and why it may not have run, trigger an election by hand, and look at the case an election cannot fix.
1A Quick Recap of the Preferred Replica
Every partition has an assignment, an ordered list of the brokers that hold its replicas, for example [2, 5, 1]. The first broker in that list is the preferred replica, the one that should lead the partition when everything is healthy. Leadership matters because the leader handles all produce requests and, by default, all consumer fetches for that partition.
When a topic is created, Kafka's placement rotates the starting broker for each partition, so the first replicas, and therefore the preferred leaders, are spread evenly. With six brokers and 600 partitions, each broker is the preferred leader of about 100. As long as every partition is led by its preferred replica, leadership load is balanced.
Notice partition 1: its preferred replica is broker 3, but broker 5 leads it. That is the state a restart leaves behind.
2How a Rolling Restart Causes the Skew
When broker 3 is restarted, the controller moves leadership of its partitions to other ISR members. When broker 3 comes back, it rejoins as a follower and catches up, but nothing in the restart itself gives leadership back. Then broker 4 restarts, and its partitions move too, some of them to the same broker that already picked up broker 3's partitions.
Each step pushes leadership towards whichever brokers were up at the time, and the last brokers to be restarted, or the first in the replica lists, collect more and more of it. By the end of the rolling restart, one broker can lead 40 percent of the partitions, with CPU and network to match. The replicas are still evenly placed; only leadership is skewed.
- Broker 3 stopsits partitions get leaders on other brokers
- Broker 3 returns as followerleads nothing until an election
- Next broker restartsmore leadership piles onto the survivors
- Imbalance above 10 percent at the next check?YesController elects preferred leadersNoSkew stays
- Leadership balanced again
5 steps in order. Play them, or step through them one at a time.
Without a preferred leader election, a restart leaves leadership where the failover put it.
3Automatic Rebalancing and Why It May Not Have Run
Kafka repairs this on its own when auto.leader.rebalance.enable is true, which is the default. Every leader.imbalance.check.interval.seconds, 300 by default, the controller looks at each broker and computes its imbalance: the share of partitions for which it is the preferred replica but not the leader. If that share exceeds leader.imbalance.per.broker.percentage, 10 by default, the controller runs preferred leader elections for those partitions, as long as the preferred replica is alive and in the ISR.
So in the normal case the skew lasts at most a few minutes after the restart. If a broker still leads 40 percent long after, something stopped the automatic process: auto.leader.rebalance.enable may have been set to false, often deliberately, to avoid leadership moves during busy hours; the preferred replicas may not be back in the ISR yet, because they are still catching up; or the imbalance per broker may fall under the 10 percent threshold even though the cluster-wide picture looks bad. Checking the broker config and the ISR of the affected partitions tells us which.
4Triggering a Preferred Leader Election by Hand
We can run the election ourselves with kafka-leader-election.sh. It asks the controller to make the preferred replica the leader of each named partition, where that replica is alive and in the ISR. It is safe: it only moves leadership between in-sync replicas, the same kind of move a controlled shutdown makes.
Clients see each move as a quick leader change: one retriable error and a metadata refresh. On a large cluster, electing everything at once creates a burst of such moves, so operators sometimes run it in batches of topics during a quiet period.
5When an Election Cannot Fix It
A preferred leader election only helps if the preferred replicas themselves are evenly spread. If the replica assignments are unbalanced, for example because a broker was added and nothing was moved to it, or partitions were created with manual assignments that favour some brokers, then some broker is the preferred leader of too many partitions, and electing preferred leaders makes the skew permanent.
We check by counting, per broker, how many partitions list it first in their replicas. If those counts are uneven, the fix is a partition reassignment: generating a new, balanced assignment with kafka-reassign-partitions.sh or a balancing tool such as Cruise Control, and executing it with throttles so the data movement does not hurt production traffic. After the reassignment, a preferred leader election makes leadership match the new, balanced plan.
6Follow-up questions
Why might a team disable automatic leader rebalancing?
Each preferred leader election causes a short leader move for clients. Some teams prefer to control when that happens, for example after a deployment window, and run the election themselves. If they do, the election must be part of the restart runbook, or skew like this becomes the normal state.
Does leadership skew affect consumers as well as producers?
Yes. By default consumers fetch from leaders, so the broker leading 40 percent of partitions also serves 40 percent of reads. Follower fetching spreads reads to nearby followers, but produce traffic always goes to the leader.
How do we see leadership balance quickly?
The LeaderCount metric per broker shows how many partitions each leads, and PreferredReplicaImbalanceCount on the controller shows how many partitions are not led by their preferred replica. Graphing LeaderCount across brokers makes a skew like this obvious.
7Conclusion
In this answer, we saw that the preferred replica is the first broker in a partition's assignment and that topic creation spreads preferred leaders evenly. A rolling restart moves leadership away from each restarted broker and does not give it back, so leadership piles up until a preferred leader election runs. The controller does that automatically every 300 seconds when imbalance exceeds 10 percent and the feature is enabled, we can run kafka-leader-election.sh --election-type PREFERRED by hand, and if the assignments themselves are unbalanced we need a reassignment instead.
Open with
The preferred replica is the first broker in a partition's replica list. When a topic is created, Kafka rotates which broker comes first, so preferred leaders are spread evenly, and the cluster is balanced when every partition is led by its preferred replica.
Then, if they want more
During a rolling restart, each broker that stops loses its leaderships to other in-sync replicas, and when it comes back it is only a follower, so leadership piles up on whichever brokers stayed up. That explains one broker leading 40 percent and running at twice the CPU.
Kafka fixes this automatically when auto.leader.rebalance.enable is true, which is the default: every leader.imbalance.check.interval.seconds, 300 by default, the controller checks each broker, and if more than leader.imbalance.per.broker.percentage, 10 percent, of the partitions it should lead are led elsewhere, it moves them back, as long as the preferred replica is in the ISR.
If the skew persists, I would check whether that setting was disabled or whether replicas are still catching up. To do it by hand I would run kafka-leader-election.sh with --election-type PREFERRED and --all-topic-partitions, or with a JSON list of partitions.
One caveat: if the replica assignments themselves are unbalanced, an election cannot help, and the partitions need a reassignment, for example with Cruise Control, followed by a preferred election.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain what the preferred replica is, how Kafka moves leadership back automatically...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-internals/71941a6134/