Technology · ssh / techDive
Kafka Replication Explained Part - 3
Understand how Kafka copies partitions across brokers, tracks in-sync replicas, elects new leaders after failures, and keeps data available when machines go down.

So far, the orders topic has survived every example because its partitions were assumed to exist. Now remove one machine.
Suppose partition P1 has a replication factor of 3. Broker 1 hosts its leader replica, while Brokers 2 and 3 host other replicas. An OrderCreated(order-123) event is written to P1—and then Broker 1 crashes.
Does P1 disappear with it? No. Kafka's answer is replication: other replicas already exist before the failure. Apache Kafka replicates at the topic-partition level specifically so another replica can take over when a server fails.

Why Kafka Replicates Partitions
If P1 has replication.factor=3, Kafka maintains three replicas total—not one leader plus three backups. The current leader is itself one of those replicas.
Conceptually:
Broker 1 → P1 LeaderBroker 2 → P1 ReplicaBroker 3 → P1 Replica
Replica placement can differ from partition to partition. The purpose is to keep live copies on multiple brokers so one broker failure does not automatically remove the partition.
This is different from consumer groups. Consumer groups answer, “Which consumer processes this partition?” Replication answers, “Which brokers hold copies of it?”
Leaders, Followers and the ISR
One replica is the partition leader. Producer writes for that partition go to the current leader. Follower replicas copy the leader's log so they can stay synchronized and potentially take over later. Kafka 4.3 also supports reads from followers in appropriate configurations, so “all reads always go to the leader” is no longer a safe universal rule.
Kafka also tracks an ISR, or in-sync replica set. A configured replica is not automatically current enough forever. If a follower dies or falls too far behind, Kafka can remove it from the ISR; replica.lag.time.max.ms contributes to that decision.
A replication factor of 3 might begin with:
Replica set: B1, B2, B3ISR: B1, B2, B3
If B3 falls behind, the configured replica set can still contain all three brokers while the ISR temporarily becomes:
ISR: B1, B2
So “configured replica” and “currently in sync” are not the same thing. Kafka's monitoring documentation likewise notes that ISR can shrink when a broker goes down and expand after its replicas catch up.
What Happens When the Leader Broker Fails?
Return to P1. Broker 1 is the leader and suddenly goes offline.
Kafka detects broker failure, and leadership for affected partitions moves to another eligible replica. The KRaft control plane manages partition-leadership metadata; clients do not elect the replacement leader themselves.
A simplified transition might be:
Before: B1 → Leader, B2 → Replica, B3 → ReplicaFailure: B1 → OfflineAfter: B2 → New Leader, B3 → Replica
The exact broker chosen is not guaranteed by this example.

Failover works because followers were replicating before Broker 1 failed. Kafka does not wait for a crash and then create a backup.
When Broker 1 returns, Kafka's operations documentation says it initially returns as a follower for its partitions. Leadership may later rebalance toward preferred replicas.
Why Kafka May Reject Writes Instead
Replication factor alone does not determine when a write is safe enough to acknowledge.
Kafka also has min.insync.replicas. With a producer using acks=all, the setting defines the minimum number of in-sync replicas required for the write to succeed. Apache gives the common example of replication factor 3 with min.insync.replicas=2.
If the ISR falls below that minimum, Kafka can reject the write instead of acknowledging it under weaker durability conditions. That is an availability-versus-durability trade-off.
Modern Kafka Also Has Eligible Leader Replicas
Older explanations often say a replacement leader must always come from the ISR. That is no longer complete.
Kafka 4.0 introduced Eligible Leader Replicas (ELR), and ELR is enabled by default for new clusters starting with Kafka 4.1. The KRaft controller can track replicas outside the ISR that are nevertheless considered safe leader candidates under ELR's rules. Current election logic checks the ISR first, then ELR where applicable.
Kafka can also permit unclean leader election as a last resort. Its current default is false, and Apache warns that enabling it may result in data loss.
Where KRaft Fits
Modern Kafka separates broker and controller responsibilities. Brokers store and serve partition data; KRaft controllers manage cluster metadata and control-plane decisions. Kafka 4.x no longer uses ZooKeeper mode.
The controller does not store OrderCreated as an application-data replica. The brokers holding P1 do that. KRaft manages the metadata describing which replica currently leads P1.
The Mental Model to Remember
Replication factor tells Kafka how many replicas of a partition to maintain. One is the current leader; followers replicate its log. Kafka tracks replica synchronization and eligibility, while the KRaft control plane manages leadership changes after failures.
The key idea is: failover works because replication happens before failure, not after it.
Replication does not make data loss impossible. Durability still depends on replica state, acknowledgement settings and election rules.
A later article in this series can answer the consumer-side follow-up: how committed offsets and delivery semantics determine where processing continues.

Conversation
Comments
Sign in to join the conversation.