Skip to content
Veltoryx Technologies
FreeLesson 1.3Beginner5 min readUpdated 31 October 2026

Kafka Architecture & KRaft Consensus

Discover how modern Apache Kafka operates without ZooKeeper using KRaft quorum controllers, metadata logs, and leader consensus.

For over a decade, running Apache Kafka required running two distinct distributed systems: the Kafka brokers and an external Apache ZooKeeper ensemble. ZooKeeper stored cluster metadata, elected the active controller, and tracked broker health.

Starting with Apache Kafka 4.0, ZooKeeper has been completely removed. Modern Kafka runs entirely on KRaft (Kafka Raft Metadata Mode), an event-driven consensus protocol built directly inside Kafka.

In this lesson, you will learn why Kafka evolved away from ZooKeeper and how KRaft enables clusters to scale to millions of partitions with near-instantaneous failover.

01The Problem with the Legacy ZooKeeper Architecture

In Kafka versions 2.x and 3.x, cluster coordination relied on an external ZooKeeper ensemble:

Metadata Architecture Evolution: ZooKeeper vs Modern KRaft
Fig. 1 · Metadata Architecture Evolution: ZooKeeper vs Modern KRaft

This dual-system architecture created three major architectural bottlenecks:

  1. Dual Metadata State and Asynchronous Sync: Metadata was duplicated across both ZooKeeper and the active Kafka controller broker. When a partition leader failed, ZooKeeper notified the controller through asynchronous watchers, the controller updated its local state, and it then pushed individual RPC updates to every other broker. If a cluster hosted hundreds of thousands of partitions, this update process took several minutes.
  2. Cluster Scale Limits (The 200,000 Partition Wall): Because ZooKeeper stored every topic, partition, and replica state as an in-memory tree of z-nodes, ZooKeeper memory consumption and watcher storms capped cluster capacity to roughly 200,000 partitions.
  3. Operational Friction and Split-Brain Vulnerabilities: Operators had to maintain two different software stacks, tune two JVM garbage collectors, manage two sets of TLS certificates, and debug complex split-brain scenarios where Kafka and ZooKeeper disagreed on cluster membership.

02How KRaft Operates

KRaft (Kafka Raft) treats cluster metadata as an internal event stream, applying Kafka's own core strength—an immutable append-only log—to manage its own internal state.

Under KRaft, metadata is written to a special single-partition internal topic named @metadata.

The Controller Quorum

Instead of relying on ZooKeeper, a small set of Kafka nodes (typically 3 or 5) form a Controller Quorum running a specialized implementation of the Raft consensus algorithm:

  • Active Controller (Leader): Exactly one controller node is elected as the active metadata leader by the quorum. All cluster administrative operations—creating topics, altering configs, expanding partitions, and handling broker registrations—are handled exclusively by this leader.
  • Standby Controllers (Followers): The remaining controller nodes continuously replicate the @metadata log from the leader and maintain an identical in-memory copy of cluster metadata.
  • Sub-Second Failover: If the active controller crashes, the standby controllers already have the entire cluster state loaded in memory. They conduct a Raft election and elect a new leader in tens of milliseconds, eliminating the multi-minute recovery delays of the ZooKeeper era.

03Broker Roles in a KRaft Cluster

In a KRaft-based cluster, each node defines its responsibilities using the process.roles configuration in server.properties:

properties
# config/kraft/server.properties
# Node identity
node.id=1

# Defines whether this process is a dedicated broker, a controller, or both
process.roles=broker,controller

# Listeners for client traffic and internal Raft controller communication
listeners=PLAINTEXT://localhost:9092,CONTROLLER://localhost:9093
controller.listener.names=CONTROLLER

# The fixed list of controller quorum voters: id@host:port
controller.quorum.voters=1@localhost:9093,2@localhost:9095,3@localhost:9097

# Local directory where partition logs and the metadata log are stored
log.dirs=/var/lib/kafka/data

Depending on your environment, you configure nodes in one of two modes:

  • Combined Mode (process.roles=broker,controller): A single JVM process performs both data storage and controller quorum duties. This is ideal for local development, test environments, and smaller production deployments.
  • Isolated Mode (process.roles=broker or process.roles=controller): Nodes are strictly separated. Dedicated controller nodes handle metadata consensus without competing for disk I/O or memory with client traffic, while dedicated broker nodes serve high-volume producer and consumer requests. This is standard in large enterprise clusters.

04How Brokers Receive Metadata Updates

In ZooKeeper, the active controller had to push RPC metadata updates to every broker individually.

Under KRaft, the model shifts from push to pull:

  1. The Active Controller appends a metadata record (for example, PartitionChangeRecord) to the @metadata partition log.
  2. Every broker node maintains an active fetch request to the controller, continuously tailing the @metadata log just like an ordinary Kafka consumer.
  3. Because brokers pull metadata sequentially, every broker applies state changes in the exact same deterministic order, completely preventing metadata drift.

05In the interview

  • How does a KRaft controller quorum handle network partitions? A KRaft quorum requires a majority of controllers to make progress (for example, 2 out of 3, or 3 out of 5). If a network partition leaves a minority group disconnected, that group cannot elect a leader or commit metadata changes, preventing split-brain corruption.
  • Can you still run ZooKeeper with Apache Kafka 4.x? No. ZooKeeper support was deprecated in Kafka 3.0 and completely removed in Apache Kafka 4.0. All Kafka 4.x deployments run on KRaft.

06Check your understanding

Quiz · 4 questions

0 of 4 answered

  1. 1. What is the primary architectural mechanism KRaft uses to store cluster metadata?

  2. 2. Why were controller failovers slow in legacy ZooKeeper-based Kafka clusters?

  3. 3. What node role setting allows a single Kafka node to act as both a data broker and a quorum controller?

  4. 4. What is the minimum recommended number of controller nodes for high availability in a production KRaft cluster?