hard Kafka Coordination: ZooKeeper to KRaft
Metadata coordination used to live in a second system; KRaft moves it into Kafka's own replicated log
Every Kafka broker needs the same picture of the cluster: which topics and partitions exist, who leads each
partition, which replicas are in-sync, and who is currently the controller. Historically Kafka kept that picture in
Apache ZooKeeper — a separate distributed coordination service the whole cluster depended on for
storage, controller election, and change notification. KRaft (Kafka Raft, KIP-500) removes that
dependency: a small quorum of dedicated controller nodes runs Kafka's own Raft implementation over a
replicated metadata log (__cluster_metadata), and every broker is simply a
follower of that log — the same fetch-and-apply mechanism a consumer already uses on any other topic. KRaft
reached general availability in Kafka 3.3 (KIP-833); ZooKeeper mode was deprecated in 3.5 and removed entirely in
Kafka 4.0.
Why ZooKeeper became the bottleneck
Under ZooKeeper, the controller's job was to keep its in-memory view of the cluster synced with what was written to ZK, and to push that view out to every broker. Three specific things scaled badly as clusters grew (per Kafka's own KIP-500 motivation and Confluent's account of it):
- Controller failover was linear in partition count. When the active controller died, the newly elected one had to re-read the metadata for every partition in the cluster from ZooKeeper before it could serve a single request — a bulk read whose cost grows with the size of the cluster, not a fixed cost.
- Broker shutdown/failover wrote metadata one partition at a time. For a broker hosting thousands of partitions, writing the updated leader/ISR state to ZooKeeper for each affected partition — plus propagating it back out to the rest of the cluster — could itself take seconds or more.
- ZooKeeper's watches fire one at a time. The controller's single-threaded event loop processed metadata-change notifications sequentially, which became a bottleneck long before partition counts reached the very large scale (hundreds of thousands to millions of partitions) that KRaft was designed to support.
Traced: partition-3's leader dies — the same event, two mechanisms
Topic orders, partition 3, is led by Broker B. Broker B crashes. What happens next depends entirely
on which coordination mechanism the cluster runs.
Pitfalls
- Treating migration as a flag flip. An existing ZK-mode cluster cannot jump straight to Kafka 4.0 — it must first complete the KIP-866 bridge migration (stand up a KRaft controller quorum, run it alongside ZK in dual-write mode so metadata is written to both, then finalize the cutover) before ZooKeeper can be removed.
- Confusing the two controller topologies. Under ZooKeeper, the controller is a role held by one of the existing brokers. Under KRaft, controllers are typically separate dedicated nodes forming their own quorum (or a small combined broker+controller node for tiny clusters) — sizing and HA planning built for the old topology don't carry over unmodified.
- Under-sizing the controller quorum. KRaft's quorum is still a Raft majority-vote system — it needs an odd number of nodes (3 or 5) to tolerate a failure, exactly like any other consensus system. A 2-node quorum is not more available than a 1-node one.
- Assuming KRaft removes consensus from Kafka. It doesn't — it replaces ZooKeeper's Zab-based consensus with Kafka's own Raft variant for exactly one job (metadata). You've swapped which consensus protocol runs, not eliminated the need for one.
Judgment layer: KRaft vs. an external coordinator
- Why KRaft wins at Kafka's scale. A general-purpose coordinator like ZooKeeper (or etcd/Consul) is a proven, reusable building block — but every user of it pays for a second system's full operational surface (its own config, security model, upgrade cycle, monitoring) and inherits its scaling ceiling. KRaft trades away that reusability for fit: because the metadata quorum is purpose-built for exactly Kafka's read/write pattern, brokers consume metadata the same way they already consume any topic (fetch, offset, replay) instead of learning a second, ZK-flavored access pattern (watches, znodes, sessions). One data structure, one operational model, for the whole system.
- When ZooKeeper-era caution still applies. KRaft has a far shorter production track record than ZooKeeper, which hardened Kafka (and much of the rest of distributed-systems infrastructure) for over a decade. A team running a large ZK-mode cluster should treat the KIP-866 migration as a deliberate, tested project — not something to rush purely for the "one less system" appeal — and should confirm its tooling (monitoring, admin scripts, third-party clients) has caught up to KRaft.
- The general trade-off this illustrates. Reuse a mature, general external coordinator vs. build a narrow, purpose-fit replication primitive into the system that needs it: the external option is battle-tested and shared across many use cases, but costs a second system plus an impedance mismatch at the interface; the built-in option removes that mismatch and scales with the host system's own primitives, at the cost of being new and single-purpose. Kafka's own partition replication (leader + ISR) was already this same pattern — KRaft just applies it to the cluster's metadata too.
Takeaways
- KRaft replaces ZooKeeper with a Raft-replicated metadata log inside Kafka; brokers become log followers
of
__cluster_metadata, not ZK watchers. - The concrete win is scale: controller failover and broker-shutdown metadata propagation stop being linear in partition count, because the new leader already holds the replicated log instead of bulk-reading it from an external store.
- KRaft GA'd in Kafka 3.3 (KIP-833); ZooKeeper was deprecated in 3.5 and removed in 4.0 — existing clusters migrate via the KIP-866 bridge, not a hard cutover.
- Prefer a purpose-built internal replication primitive over a general external coordinator once operating at a scale where the coordinator's overhead and impedance mismatch outweigh its maturity advantage.
Re-authored for this guide from Apache Kafka's KIP-500 ("Replace ZooKeeper with a Self-Managed Metadata Quorum"), KIP-833 ("Mark KRaft as Production Ready"), KIP-866 ("ZooKeeper to KRaft Migration"), and Confluent's "Why Replace ZooKeeper with Kafka Raft — The Log of All Logs." Diagrams hand-authored as SVG for this guide. See also: Kafka Internals — Partitions, Offsets & Consumer Groups; Why Consensus Is Hard — FLP, Quorums & Paxos vs Raft.
🤖 Don't fully get this? Learn it with Claude
Stuck on Kafka Coordination: ZooKeeper to KRaft? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.
Build the mental picture, not memorization.
I just read a lesson on **Kafka Coordination: ZooKeeper to KRaft** (System Design) and want to truly understand it. Explain Kafka Coordination: ZooKeeper to KRaft from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Socratic — adapts to where you're stuck.
Teach me **Kafka Coordination: ZooKeeper to KRaft** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Active recall exposes what you missed.
Quiz me on **Kafka Coordination: ZooKeeper to KRaft** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Intuition + hook + flashcards for long-term memory.
Help me remember **Kafka Coordination: ZooKeeper to KRaft** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.