Leader epoch — the vector clock that fixes truncation
Each record is stamped with a monotonic leader epoch; on restart, followers truncate at the precise epoch boundary instead of a stale High Water Mark, closing the divergence window that pre-KIP-101 HW-based truncation left open.
ISR explains commit on the happy path. But what happens at failover, when followers must reconcile divergent logs? Pre-KIP-101 used the High Water Mark and silently lost data — the leader epoch is the fix.
Scene 06
Leader epoch — the vector clock that fixes truncation
- Watch
- Try it
- Predict
- Capture
Leader B is at epoch e1. Producer writes m1, m2; follower A fetches them. Watch A's LEO catch up to 2 while its local HW stays at 0 — HW updates piggyback on A's NEXT fetch, so the follower's HW always lags the leader's by one round-trip.
Highlighted lines are the ones running in the diagram right now.
def onBecomeFollower():# local HW lags leader HW by one fetch RTT# — at restart it can be arbitrarily staleself.log.truncateTo(self.hw)self.leo = self.hw# resume fetching from the new leaderloop:resp = leader.fetch(fromOffset=self.leo)self.log.append(resp.records)self.leo += len(resp.records)
Where this sits in Build Kafka
Scene 06 of 13, in the Consensus act — Leader epoch is the vector clock that fixes truncation.. Why HW-based truncation could silently lose acked writes, and how KIP-101 closed the gap.
Up next. Rebalance — when consumers join or leave a group, partitions get reassigned. Eager rebalance stops the world; cooperative-sticky moves only the lanes that actually need to move.
Designs that use this
- Twitter / X TimelinePush or pull? Both. The canonical fanout problem.
- Uber / Lyft — Match Drivers and RidersMatch a rider to the closest acceptable driver in under 3 s. Geohash, S2, surge.
- Slack / DiscordChannels and history. Push or pull — and how a hot-channel fanout doesn't melt the gateway.
- WhatsApp / MessengerHundreds of millions of long-lived sockets, sub-second 1:1 + group delivery, E2E-encrypted, multi-device, multi-region active-active.