Monedula
Kafka guide contents

Markdown

Part VI · Reference

Kafka Improvement Proposal

KIP-101: leader epochs decide where a replica truncates

Cluster and operations · Shipped · since Kafka 0.11 · status checked November 2026

KIP-101 changed how a Kafka replica cleans up its log after a leader change. Instead of cutting its log back to its own high watermark, a returning replica asks the new leader where their histories diverge, using leader epochs, and removes only the records past that point. That fixed cases where Kafka lost committed records or ended up with replicas holding different data.

Proposal
KIP-101, Alter Replication Protocol to use Leader Epoch rather than High Watermark for Truncation
Status
Shipped Since Kafka 0.11 (2017), completed by KIP-279 in Kafka 2.0.
Area
Cluster and operations
Return → log truncation. The network heals. broker-1 returns with LEO 4, ahead of the leader's LEO 2 - a divergent log. Using leader epochs it learns epoch 0 ended at offset 2 on the new leader and TRUNCATES there (offsets 2,3 discarded: the log_truncate moment), then refetches from the leader. Open this step in the full playground

Why it was needed

A follower learns the high watermark one round after the leader, so its own value is often slightly behind. Truncating to it on restart could throw away committed records; if the leader then failed too, those records were gone. In other sequences two replicas ended up with different records at the same offset.

What it changes

Every batch carries the epoch of the leader that wrote it, and every replica keeps a small file mapping each epoch to its start offset. A replica coming back sends OffsetsForLeaderEpoch for its latest epoch, the leader answers with where that epoch ended in its own log, and the replica truncates exactly there. KIP-279 (Kafka 2.0) extended the exchange so replicas walk back until they find an epoch they share.

Where it stands

Shipped in Kafka 0.11 and completed by KIP-279 in Kafka 2.0. It is the basis of truncation in every current Kafka version and needs no configuration.

What comes next

Stable. Eligible Leader Replicas (KIP-966) builds on the same guarantees to elect safe leaders when the ISR is empty.

See it in the simulator

Sources

All Kafka KIPs