Replication in Depth: Leaders, ISR, High Watermark and Failure Scenarios

Apache Kafka 18 min min read Updated: Nov 17, 2026 Advanced
Replication in Depth: Leaders, ISR, High Watermark and Failure Scenarios
Advanced Topic 1 of 4

The Basic Model

  • Each partition has one leader and several followers on other brokers
  • All writes and reads (by default) go to the leader
  • Followers act like consumers: they fetch from the leader and append to their own log
  • The ISR is the set of replicas (including the leader) that are caught up. A follower that lags more than replica.lag.time.max.ms (default 30 s) is removed from the ISR
text Partition orders-0, replication factor 3: Leader b1: [0][1][2][3][4][5][6][7] LEO (log end offset) = 8 Follow b2: [0][1][2][3][4][5][6] LEO = 7 Follow b3: [0][1][2][3][4][5] LEO = 6 High watermark (HW) = smallest LEO among the ISR = 6 Consumers can read only up to offsets BEFORE the HW (records 0..5). Records 6 and 7 are not yet "committed".
TermMeaning
LEO (log end offset)Offset after the last record in a replica's log
High watermarkOffset up to which all ISR members have the data. Consumers see only records below it
Committed recordA record replicated to all current ISR members
Leader epochA number that increases with each leader change, used to avoid divergence between logs after failovers

What acks=all Really Means

With acks=all the leader waits until every replica in the current ISR has the record. The safety question is: what if the ISR has shrunk to just the leader? That is why min.insync.replicas exists.

SettingValueEffect
replication.factor3Three copies
min.insync.replicas2A write with acks=all is rejected unless at least 2 replicas (leader included) are in the ISR
Producer acksallWait for the ISR
text All 3 brokers healthy: ISR={b1,b2,b3} -> write acknowledged after all 3 have it. b3 dies: ISR={b1,b2} -> still >= 2, writes OK, durable on 2 machines. b2 also dies: ISR={b1} -> below 2: producer gets NotEnoughReplicas, writes STOP. Availability is sacrificed to avoid a single copy of new data.
Trade-off: replication.factor=3 with min.insync.replicas=2 survives one broker failure with no data loss and continued writes. It is the standard production choice.

Leader Failure Walk-Through

  1. Broker b1 (leader of orders-0) crashes
  2. The controller notices (heartbeat or session loss) and picks a new leader from the ISR, for example b2
  3. b2 becomes leader with a new leader epoch. Clients refresh metadata (they get NOT_LEADER errors, then reconnect to b2)
  4. Records already acknowledged with acks=all exist on b2, so nothing acknowledged is lost
  5. Records that b1 had written but never replicated were not acknowledged (with acks=all). The producer retries them and idempotence prevents duplicates
  6. When b1 returns, it becomes a follower, truncates any records beyond the new leader's history (using the leader epoch) and catches up, then rejoins the ISR

Unclean Leader Election

If all ISR members are gone, the partition is offline. Kafka offers a choice:

unclean.leader.election.enableBehaviourConsequence
false (default, recommended)Wait for an ISR replica to returnPartition stays unavailable but no committed data is lost
trueAllow an out-of-sync replica to become leaderAvailable again quickly but committed records can be lost and consumers may see offsets go backwards
Choose by data type: For payments and orders keep it false. For low-value metrics where availability matters more than a few lost events, true can be acceptable on that specific topic.

Preferred Leaders and Balance

  • The first replica in the replica list is the preferred leader. With auto.leader.rebalance.enable=true (default) the controller moves leadership back to preferred leaders periodically after failures
  • Spread leaders evenly so that no single broker serves most traffic
  • Check with kafka-topics.sh --describe and use kafka-leader-election.sh --election-type preferred --all-topic-partitions to rebalance manually

Rack Awareness

text # broker config: broker.rack=us-east-1a (one value per availability zone) # Kafka then places replicas of a partition in different racks/zones: orders-0: leader b1 (zone a), follower b4 (zone b), follower b5 (zone c)

With 3 zones and replication factor 3, the cluster survives the loss of a whole zone. Consumers can also read from a nearby follower (client.rack with replica.selector.class=RackAwareReplicaSelector) to save cross-zone network cost.

Under-Replicated and Offline Partitions

MetricMeaningAction
UnderReplicatedPartitions > 0Some followers are out of the ISR (broker down, slow disk or network)Find the broker or the replica that lags
UnderMinIsrPartitionCount > 0ISR below min.insync.replicas. Producers with acks=all failUrgent: restore brokers
OfflinePartitionsCount > 0No leader availableUrgent: bring back an ISR replica
IsrShrinksPerSec / IsrExpandsPerSec frequentISR flappingNetwork, GC pauses or overloaded brokers
bash bin/kafka-topics.sh --bootstrap-server $BS --describe --under-replicated-partitions bin/kafka-topics.sh --bootstrap-server $BS --describe --under-min-isr-partitions bin/kafka-topics.sh --bootstrap-server $BS --describe --unavailable-partitions

Settings Summary for No Data Loss

WhereSetting
Topicreplication.factor=3, min.insync.replicas=2
Brokerunclean.leader.election.enable=false, default.replication.factor=3, offsets.topic.replication.factor=3
Produceracks=all, enable.idempotence=true, retries on, handle callback errors
ConsumerCommit offsets after processing
OperationsRack awareness, alerts on under-replicated partitions, tested broker failure drills

Conclusion

Followers fetch from leaders, and the ISR plus the high watermark define which records are committed. With replication factor 3, min.insync.replicas=2, acks=all and no unclean elections, acknowledged records survive a broker failure.

Quick Summary: ISR + HW define committed; RF=3, minISR=2, acks=all; no unclean election; rack aware.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators