Leader and Follower Partitions in Kafka
A beginner-friendly guide to how Kafka protects your data from machine failures, by copying every partition and choosing one copy to run the show.
Imagine a company with one main office and two backup offices in different cities, each keeping an exact copy of every important file. Only the main office actually handles customer requests day to day, while the backup offices quietly stay updated in case disaster strikes. If the main office ever burns down, one of the backups instantly steps in and takes over, and customers barely notice the difference. This is almost exactly how Kafka protects the data inside its partitions, using a system of leaders and followers. In this guide we will build up the whole picture slowly, defining every new word the first time it appears.
1Why a Single Copy of Data Is Not Enough
Before learning the solution, it helps to feel the risk it protects against.
Machines fail, and it is not rare
Kafka stores data in partitions, which are ordered, append-only sequences of events that live on individual machines called brokers. Every broker is, at the end of the day, a physical or virtual computer, and computers fail. Disks wear out, power supplies die, network cables get unplugged, and software occasionally crashes. In a large cluster with many brokers, some kind of failure is not a rare, unlucky event, it is something that will eventually happen as a matter of routine operation.
If a partition’s data existed on only one broker, a single failure would mean that data is gone, along with every producer trying to write to it and every consumer trying to read from it. For a system that businesses rely on to move orders, payments, and critical alerts, this level of fragility is unacceptable.
Imagine keeping the only copy of an important family photo album in a single house. If that house floods, the photos are lost forever. Most people instinctively keep copies elsewhere, precisely because they know that trusting a single location is too risky for something they cannot afford to lose.
The answer: keep copies, and organise them
Kafka’s answer to this risk is to keep multiple copies of every partition on different brokers, and to organise those copies so that everyone, including producers, consumers, and the brokers themselves, always agrees on which copy is currently in charge. This is where the ideas of leader and follower partitions come in.
2What Are Leader and Follower Partitions?
The core idea in one sentence, then in plain words.
A short definition
When a Kafka partition is copied onto several brokers, each copy is called a replica. Among these replicas, exactly one is chosen to be the leader, and the rest are called followers. The leader is the only replica that handles requests from producers and consumers directly. The followers do nothing but quietly copy every new event the leader receives, staying ready to take over if they are ever needed.
In everyday terms, the leader is the active, working copy of a partition, and the followers are standby copies, always watching and updating themselves, but never doing any of the actual work unless called upon.
Leadership belongs to the partition, not the broker
It is important to notice that “leader” and “follower” describe roles for a specific partition, not a permanent label for an entire broker. A single broker might be the leader for some partitions while simultaneously being a follower for other partitions belonging to different topics. Leadership is spread out across the cluster so that no one broker carries the entire workload alone.
The number of replicas a partition has, including the leader, is called its replication factor. A replication factor of three means one leader and two followers, spread across three different brokers.
3The Leader’s Job in Detail
A closer look at what makes the leader special.
Handling every read and write
The leader replica is the single point of contact for a partition. When a producer sends a new event, it goes to the leader. When a consumer wants to read events, it also asks the leader. This might sound like it creates a bottleneck, but remember that leadership is spread across many partitions and many brokers, so the overall cluster can still handle enormous amounts of traffic in parallel, even though any single partition only has one active leader at a time.
Deciding the official order of events
Because all writes to a partition go through one leader, the leader is also what decides the exact order in which new events are appended. This is precisely why Kafka can guarantee strict ordering within a single partition. If multiple replicas could all accept writes at once, there would be no single, agreed-upon sequence, and different readers might see events in different orders, which would break many of the guarantees Kafka is built to provide.
Think of a single microphone at a public meeting. Even if fifty people want to speak, only whoever holds the microphone can be heard by everyone at once, which keeps the conversation orderly. The leader replica is that microphone for its partition.
4The Follower’s Job in Detail
Quiet, essential work that most people never see happening.
Constantly copying the leader
A follower’s only job is to continuously fetch new events from the leader and append them to its own copy of the partition, in the exact same order the leader received them. This process is called replication. A healthy follower is always trying to stay as close as possible to whatever the leader currently has, so that it could take over with almost no missing data if it ever needed to.
Followers normally stay out of the spotlight
In the most common Kafka setup, followers do not respond to ordinary producer or consumer requests at all. They exist purely as a safety net, quietly replicating in the background. Some Kafka configurations do allow certain read requests to be served by nearby followers for performance reasons in specific situations, but the default and most common behaviour is that all reads and writes go through the leader alone.
A follower is like an understudy actor in a theatre production, watching every rehearsal and performance closely, learning every line and cue perfectly, ready to step on stage at a moment’s notice, even though audiences never see the understudy unless something goes wrong with the lead.
sequenceDiagram
participant P as Producer
participant L as Leader Replica
participant F1 as Follower Replica 1
participant F2 as Follower Replica 2
P->>L: Send new event
L->>F1: Replicate event
L->>F2: Replicate event
F1-->>L: Copy saved
F2-->>L: Copy saved
L-->>P: Acknowledge success
5In-Sync Replicas: Who Is Actually Caught Up
Not every follower is equally ready to take over at any given moment.
What “in-sync” means
A follower that has recently and reliably kept up with the leader’s latest events is called an in-sync replica. Kafka keeps a running list of which replicas currently qualify as in-sync for each partition, often called the in-sync replica set, or ISR for short. A follower can temporarily fall out of this list if it becomes slow, disconnected, or otherwise unable to keep pace with the leader.
Why this list matters so much
Only replicas in the in-sync list are considered safe candidates to become the new leader if the current leader fails. Promoting a replica that has fallen far behind would risk silently losing recent events, since that replica’s copy of the partition would be missing data the old leader already had. By only promoting from the in-sync list, Kafka protects against this kind of silent data loss during a leadership change.
Think of a relay race team where only runners who have been actively training and keeping pace with the team are allowed to be called in as a substitute. A runner who has been away and out of practice would not be trusted to step in mid-race, even if they are still officially part of the team.
Having three replicas does not automatically mean three replicas are always eligible to become leader at any given moment. Only the replicas currently in the in-sync set are eligible, and that set can shrink temporarily if a follower falls behind.
6What Happens When a Leader Fails
The moment where all this preparation actually pays off.
The leader broker becomes unreachable
The broker hosting the leader replica crashes, loses network connectivity, or is shut down for maintenance without a graceful handover.
The failure is detected
The cluster’s coordination system notices that the leader is no longer responding within the expected time.
A new leader is chosen
One of the replicas currently in the in-sync set is selected to become the new leader for that partition.
The cluster is informed
Every broker in the cluster updates its own understanding of who now leads that partition.
Producers and consumers reconnect
Clients that were talking to the old leader automatically discover the new leader and redirect their requests to it, usually within moments.
The old leader rejoins as a follower
If the failed broker comes back online later, it typically rejoins as a follower for that partition, catching up on anything it missed.
flowchart LR
subgraph Before[Before Failure]
L1[Leader: Broker 1]
F1a[Follower: Broker 2]
F1b[Follower: Broker 3]
end
subgraph After[After Failure]
L2[New Leader: Broker 2]
F2a[Follower: Broker 3]
X[Broker 1 unreachable]
end
Before -.failure & promotion.-> After
This entire process, from noticing the failure to a new leader actively serving requests, typically completes within seconds. Producers and consumers designed with Kafka’s client libraries handle this transition automatically, without any manual intervention.
7Who Decides Who the Leader Is?
Leadership decisions are not made randomly; they follow a coordinated process.
The role of the controller
Every Kafka cluster has a small group of nodes, called controllers, responsible for tracking the overall state of the cluster, including which broker leads which partition. When a broker fails, the controllers are responsible for noticing this and choosing a replacement leader from the eligible in-sync replicas, then informing every other broker of the change.
In modern Kafka clusters, this controller responsibility is handled by Kafka’s own built-in coordination system, using a consensus approach that lets a small group of controller nodes reliably agree on cluster-wide facts like partition leadership, even if some of them are temporarily unavailable.
Preferred leaders and balance
When a topic’s partitions are first created, Kafka assigns a preferred leader for each one, aiming to spread leadership duties evenly across all the brokers in the cluster. Over time, as failures and recoveries happen, leadership can drift away from this ideal, evenly balanced arrangement, with some brokers quietly ending up as leader for more partitions than others. Kafka provides tools to rebalance leadership back toward this preferred, even distribution when needed.
Think of a school assigning one class monitor per classroom at the start of term, trying to spread the responsibility fairly among students. If a monitor is absent one day, someone else temporarily takes over, but the school may later restore the original, fair arrangement once things settle down.
8Acknowledgements and How Sure a Producer Can Be
The leader-follower system directly shapes how safely a producer’s data is saved.
Three common levels of care
When a producer sends an event to the leader, it can choose how much confirmation it wants before considering the send successful. This setting is often called the acknowledgement level. At the lightest level, the producer does not wait for any confirmation at all, which is fast but risky if the leader fails immediately afterward. At a middle level, the producer waits until the leader itself has saved the event. At the strictest level, the producer waits until enough in-sync followers have also confirmed they have saved a copy.
| Acknowledgement level | What is confirmed | Trade-off |
|---|---|---|
| No acknowledgement | Nothing; the producer does not wait | Fastest, but risk of silent data loss |
| Leader only | The leader has saved the event | Balanced, but data can still be lost if the leader fails before followers catch up |
| All in-sync replicas | The leader and enough followers have saved the event | Safest, at the cost of a little extra time |
Why this connects back to leaders and followers
This whole system of confirmation only works because followers are constantly replicating from the leader. If a producer asks for the strictest level of safety, it is really asking Kafka to confirm that the leader-follower replication has already happened for that specific event, before telling the producer it can move on.
Critical data, such as payment events, generally deserves the strictest acknowledgement level. Less critical data, such as casual click tracking, can often use a lighter level for better speed, since the occasional lost event may not matter much there.
9Minimum In-Sync Replicas
A setting that gives teams direct control over the safety versus availability trade-off.
Setting a floor for safety
A topic can be configured with a minimum in-sync replicas setting, which defines how many replicas, including the leader, must be in-sync for the leader to keep accepting writes with the strictest acknowledgement level. If the number of in-sync replicas ever drops below this floor, perhaps because too many followers have fallen behind or failed, the leader will refuse writes at that safety level rather than risk silently under-protecting the data.
Balancing safety and availability
Setting this minimum too low weakens the safety Kafka can guarantee, since fewer confirmed copies exist before a write is accepted. Setting it too high, close to or equal to the full replication factor, can make the partition unavailable for strict writes more often, since it takes very little trouble for the in-sync count to dip below a high threshold. Most teams settle on a middle ground, commonly requiring two in-sync replicas out of three total.
Think of a school rule requiring at least two teachers to be present before a field trip can proceed safely. If only one teacher is available that day, the trip is postponed rather than risking student safety, even though this means occasional inconvenience in exchange for a firm safety guarantee.
10Choosing the Right Replication Factor
Deciding how many total copies of a partition to keep.
Common choices
A replication factor of one means no protection at all, since there is only a single copy with no followers. This is sometimes used for quick local testing but is considered unsafe for any real production use. A replication factor of three, meaning one leader and two followers, is the most common choice in production, offering solid protection while keeping storage and network costs reasonable. Some highly critical systems may choose even higher replication factors for extra safety, at the cost of additional storage and network traffic.
Example: A Payments Topic
A bank handling transaction events might choose a replication factor of three or more, paired with a strict acknowledgement level and a sensible minimum in-sync replicas setting, accepting a little extra cost and latency in exchange for very strong protection against data loss.
Example: A Development Environment
A developer testing Kafka on a laptop, with no real risk of important data loss, might comfortably use a replication factor of one, since simplicity matters more than durability in that setting.
Using a replication factor of one in production is a common and costly mistake. It removes the entire safety net this chapter has described, turning any single broker failure into permanent, unrecoverable data loss for that partition.
11Advantages and Trade-offs of This Design
No design is free of cost, even one this well proven.
Advantages
- Protects data against individual broker failures
- Keeps strict ordering guarantees, since only one leader accepts writes
- Allows automatic, fast recovery without manual intervention
- Lets teams tune the safety versus speed trade-off per topic
- Spreads leadership responsibility evenly across a cluster
Disadvantages / Trade-offs
- Extra replicas mean extra storage and network usage
- Stricter safety settings can add a small amount of latency
- A leader can still be a momentary bottleneck for a very busy single partition
- Misconfigured replication settings can create a false sense of safety
12Monitoring Leaders and Followers
A healthy-looking cluster can still be quietly at risk if replication is not watched closely.
Under-replicated Partitions
The count of partitions where at least one follower has fallen out of the in-sync set. Anything above zero deserves prompt attention.
Offline Partitions
Partitions with no available leader at all, meaning they cannot currently serve reads or writes. This is a serious, urgent alert.
Leader Election Rate
How often new leaders are being chosen. A sudden spike often signals broker instability somewhere in the cluster.
Replication Lag
How far behind each follower is compared to its leader, showing how close that follower is to being ready to take over.
If a team can only watch one thing closely, under-replicated partitions is usually the best choice. It is an early sign that a partition’s safety net is weaker than intended, well before any actual data loss occurs.
13Best Practices and Common Mistakes
Practical lessons for keeping leaders and followers working safely.
Best practices
Use a replication factor of at least three in production
This offers real protection while keeping costs reasonable for most workloads.
Match acknowledgement level to data importance
Use the strictest level for critical data, and a lighter level where occasional loss is acceptable in exchange for speed.
Set a sensible minimum in-sync replicas value
Balance strong safety against how often the partition might become temporarily unavailable for strict writes.
Watch replication metrics continuously
Track under-replicated and offline partitions as core health signals, not as an afterthought.
Rebalance leadership periodically
Restore leadership to its preferred, evenly distributed arrangement after failures and recoveries settle down.
Mistakes beginners often make
Having a high replication factor does not help if the acknowledgement level and minimum in-sync replicas settings are too loose, since a producer might not wait for enough copies to actually confirm the write.
A slowly growing lag between a leader and its followers can quietly shrink the in-sync set over time, until a failure reveals that fewer safe copies existed than the team assumed.
Letting leadership drift permanently onto a small number of brokers after repeated failures can overload those machines and reduce the cluster’s overall resilience.
14Frequently Asked Questions
No. In standard Kafka behaviour, only the leader accepts writes. Followers exist to replicate what the leader has already accepted, not to accept new writes themselves.
Yes. Leadership can shift due to failures, maintenance, or rebalancing, and Kafka is designed to handle this smoothly and automatically, without requiring manual action for every single change.
If every replica, including all followers, becomes unavailable at the same time, the partition has no leader and cannot serve reads or writes until at least one replica comes back online, since there is no remaining copy to promote.
It adds some extra network and storage overhead, since more copies must be maintained, but Kafka is designed to handle this efficiently, and the added safety is generally well worth the modest cost for important data.
Under normal, safe configurations, only in-sync replicas are eligible to become leader, precisely to avoid promoting a replica that is missing recent data.
This typically happens within seconds, since the coordination system is specifically designed to detect failures and promote a new leader quickly, minimising disruption to producers and consumers.
No, not with standard Kafka client libraries. They are built to automatically detect when leadership has changed and redirect their requests to the new leader without any manual reconfiguration.
15Summary and Key Takeaways
Leader and follower partitions are how Kafka protects data against the everyday reality that machines eventually fail. Every partition is copied across several brokers as replicas, with exactly one replica chosen as the leader to handle all reads and writes, while the rest quietly replicate as followers, ready to step in. Kafka tracks which followers are truly caught up as in-sync replicas, and only promotes from that trusted group if the leader ever fails, protecting against silent data loss during the handover. Settings like acknowledgement level, replication factor, and minimum in-sync replicas let teams tune exactly how much safety they want, at the cost of a little extra time or resources. Together, this system lets Kafka keep working smoothly and automatically, even as individual machines come and go.
Key Takeaways
- Every partition can have multiple replicas — copies spread across different brokers to protect against failure.
- One leader, many followers — the leader handles all reads and writes, while followers quietly replicate in the background.
- In-sync replicas are the trusted, caught-up copies — only these are eligible to become the new leader if needed.
- Failover happens automatically — a new leader is chosen within seconds, and clients reconnect without manual help.
- Acknowledgement levels control how much safety a producer demands — trading speed against protection against loss.
- Minimum in-sync replicas sets a safety floor — refusing risky writes if too few copies are currently caught up.
- Sensible replication choices matter — a replication factor of three or more is the common, trusted standard for production data.