Replica Recovery Guarantees in Kafka - srivalligade04/ConfluentExamPreparationNotes GitHub Wiki

Replica Recovery Guarantees in Kafka

1. Log-Based Replication

  • Kafka uses write-ahead logs for each partition.
  • Followers replicate the leader’s log sequentially, ensuring consistency.

2. High Watermark (HW)

The High Watermark is the highest offset in a Kafka partition that has been replicated to all in-sync replicas (ISR). It represents the point up to which data is considered committed and safe to be read by consumers.

  • The HW marks the last offset replicated to all ISR replicas.
  • Only messages below the HW are considered committed and are visible to consumers.
  • During recovery, replicas truncate their logs to the HW to avoid divergence.

Why It Matters

  • Producers can send messages beyond the HW, but those messages are not considered committed until replicated to all ISR members.
  • Consumers can only read messages up to the HW, ensuring they only see durable data.
  • Followers use the HW to truncate uncommitted data during recovery.

3. Follower Recovery Process

When a follower broker restarts:

  • It contacts the leader for each partition it hosts.
  • It compares its log with the leader’s log.
  • If it has extra (uncommitted) messages, it truncates them.
  • It fetches missing messages from the leader to catch up.
  • Once caught up, it is added back to the ISR.

4. Leader Recovery

If a leader fails and restarts:

  • It becomes a follower unless re-elected.
  • It follows the same recovery process to rejoin the ISR.

image