On this page
Kafka Improvement Proposal
KIP-595: Raft for the Kafka metadata quorum
KIP-595 is the consensus protocol inside KRaft. The controllers elect one leader by majority vote, the leader appends metadata records to a log, and a record counts as committed once a majority has it. It is Raft, adapted to Kafka: followers pull the log with fetch requests, just as follower replicas do for topic partitions.
- Proposal
- KIP-595, A Raft Protocol for the Metadata Quorum
- Status
- Shipped Shipped with KRaft; production-ready since Kafka 3.3.
- Area
- Cluster and operations
- Proposal page
- KIP-595 on the Apache Kafka wiki
Why it was needed
Replacing ZooKeeper (KIP-500) needed a way for several controllers to agree on one ordered history of metadata changes and to survive the loss of a minority of them. Kafka already had a replicated log, but its leader election depended on a controller, which is exactly what was being built. The quorum needed to elect its own leader.
What it changes
Each controller is a voter. When the leader stops sending, a voter raises the epoch and asks for votes; it wins only with a majority and only if its log is at least as up to date as each voter that grants a vote. The leader appends records, followers fetch them, and the high watermark moves when a majority has the record. A voter that was down catches up by fetching, or by loading a snapshot if it is far behind.
Where it stands
Implemented as the core of KRaft. It has run production clusters since Kafka 3.3 and is the only metadata mode since Kafka 4.0. The voter set was static at first; KIP-853 in Kafka 3.9 made it changeable at runtime.
What comes next
Stable. Improvements arrive as smaller KIPs on top: changing the voter set at runtime (KIP-853), automatic joining of new controllers in Kafka 4.2, and unregistering controllers in Kafka 4.4 (KIP-1312).
See it in the simulator
- Kafka KRaft controller failover and metadata log catch-up (Controller failover & metadata catch-up) Step 10: Active c0 dies; c1 elected Open at this step: Kafka KRaft controller failover and metadata log catch-up
- Kafka KRaft controller failover and metadata log catch-up (Controller failover & metadata catch-up) Step 8: c2 replays the log Open at this step: Kafka KRaft controller failover and metadata log catch-up
- Kafka KRaft controller failover and metadata log catch-up (Controller failover & metadata catch-up) Step 3: Standbys replicate Open at this step: Kafka KRaft controller failover and metadata log catch-up