What is the difference between a leader and follower replica in Kafka?
Learn the difference between leader and follower replicas in Kafka, how ISR and leader election work, and why they deliver fault tolerance and HA.
Expected Interview Answer
In Kafka, each partition has one leader replica that handles all reads and writes, while the follower replicas passively copy the leader's data to stay in sync and provide fault tolerance.
Producers and consumers only interact with the leader for a partition; followers do not serve client traffic under default settings, they continuously fetch records from the leader to remain part of the in-sync replica (ISR) set. If the broker holding the leader fails, the controller promotes an in-sync follower to become the new leader, so no acknowledged data is lost and the partition stays available. This leader-follower design is how Kafka achieves durability and high availability without every broker having to handle every request.
- Provides fault tolerance if a broker fails
- Keeps a single source of truth for ordering per partition
- Enables automatic failover via leader election
- Balances load by spreading partition leaders across brokers
- Guarantees durability through in-sync replica tracking
AI Mentor Explanation
Think of the leader replica as the on-strike batter who actually faces every ball and scores the runs, while follower replicas are the non-striker and the dugout batters watching every delivery closely. Only the striker interacts with the bowler, but the others track the exact score so that if the striker gets out, one of them walks in already knowing the situation and continues the innings without losing a single run.
Step-by-Step Explanation
Step 1
Partition creation
When a topic is created with a replication factor, each partition is assigned one leader and N-1 follower replicas across different brokers.
Step 2
Leader handles clients
All produce and consume requests for that partition are routed to the leader broker, which owns the authoritative log.
Step 3
Followers fetch
Follower replicas continuously send fetch requests to the leader and append the same records to their own copy of the log.
Step 4
ISR tracking
Followers that keep up with the leader within replica.lag.time.max.ms stay in the in-sync replica (ISR) set.
Step 5
Failover
If the leader broker fails, the controller elects a new leader from the ISR so the partition stays available with no acknowledged data loss.
What Interviewer Expects
- Clear statement that leader serves reads/writes and followers replicate
- Understanding of the in-sync replica (ISR) concept
- Knowledge of how leader election provides failover
- Awareness that ordering is guaranteed per partition by the leader
- Mention of replication factor and broker distribution
Common Mistakes
- Saying followers also serve client reads by default (they do not, unless follower fetching is enabled)
- Confusing replicas with partitions
- Forgetting that only in-sync followers can be promoted to leader
- Assuming replication happens across partitions rather than across brokers for the same partition
Best Answer (HR Friendly)
“In Kafka, one copy of the data called the leader does all the actual reading and writing, and the other copies called followers keep an identical backup. If the leader's server crashes, a follower is instantly promoted to take over, so nothing is lost and the system keeps running.”
Code Example
# Show partition layout: Leader, Replicas and Isr columns
kafka-topics.sh --bootstrap-server localhost:9092 \
--describe --topic orders
# Example output:
# Topic: orders Partition: 0 Leader: 1 Replicas: 1,2,3 Isr: 1,2,3
# Topic: orders Partition: 1 Leader: 2 Replicas: 2,3,1 Isr: 2,3,1Follow-up Questions
- What is the in-sync replica (ISR) set and why does it matter?
- How does Kafka elect a new leader when a broker fails?
- What is an unclean leader election and when would you allow it?
- Can followers serve consumer reads, and how is that configured?
- How does replication factor relate to fault tolerance?
MCQ Practice
1. In a default Kafka setup, which replica serves producer writes for a partition?
By default all reads and writes for a partition go through its leader replica; followers only replicate.
2. Which replicas are eligible to become the new leader during failover?
Only in-sync replicas (ISR) can be promoted, guaranteeing no acknowledged data is lost during a clean election.
3. What keeps a follower in the in-sync replica set?
A follower stays in the ISR as long as it fetches and catches up to the leader within the configured lag time.
Flash Cards
What does a leader replica do? — Handles all reads and writes for its partition and owns the authoritative log.
What does a follower replica do? — Passively fetches and copies the leader's records to provide redundancy and enable failover.
What is the ISR? — The in-sync replica set: replicas that are fully caught up with the leader and eligible for promotion.
What happens when a leader broker fails? — The controller elects a new leader from the ISR, keeping the partition available with no acknowledged data loss.