Knowledge Guide
HomeSystem DesignKafka

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.

Architecture comparison: under ZooKeeper a controller broker reads and writes cluster metadata to an external ZooKeeper ensemble and pushes updates to brokers by RPC; under KRaft a Raft-based controller quorum replicates a cluster metadata log that every broker fetches and replays like a normal consumer
Architecture comparison: under ZooKeeper a controller broker reads and writes cluster metadata to an external ZooKeeper ensemble and pushes updates to brokers by RPC; under KRaft a Raft-based controller quorum replicates a cluster metadata log that every broker fetches and replays like a normal consumer

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):

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.

Traced sequence comparing a partition leader failure under ZooKeeper (session timeout, watch event, controller writes to ZK, RPC push, and a slow bulk metadata reload if the controller itself fails) versus under KRaft (heartbeat timeout detected directly by the Raft leader, a record appended and replicated to the metadata log, and brokers replaying it exactly like consumers)
Traced sequence comparing a partition leader failure under ZooKeeper (session timeout, watch event, controller writes to ZK, RPC push, and a slow bulk metadata reload if the controller itself fails) versus under KRaft (heartbeat timeout detected directly by the Raft leader, a record appended and replicated to the metadata log, and brokers replaying it exactly like consumers)

Pitfalls

Judgment layer: KRaft vs. an external coordinator

Takeaways


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.

🎨 Explain it visually

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.
🤔 Walk me through it (interactive)

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.
🧪 Quiz me & fix my gaps

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.
🧠 Make it stick

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.

📝 My notes