liveBook · Manning

KRaft

As explained in Apache Kafka in Action

KRaft is Kafka's protocol for managing cluster metadata and internal coordination without an external coordination system.

Imagine a bank-transfer topic spread across several Kafka brokers. Its partitions need broker assignments and leaders, and those decisions must remain consistent when a broker fails. KRaft is Kafka’s Raft-based way to coordinate that cluster state without a separate ZooKeeper system. section 1.3 section 7.1

A KRaft coordination cluster elects an active controller. Controllers manage metadata such as partition assignments and leaders; the active controller monitors brokers and directs changes when the cluster changes. KRaft keeps coordination within Kafka, while the __cluster_metadata topic provides consistent metadata storage. This removes the need to operate ZooKeeper alongside Kafka and avoids its metadata-management bottlenecks. section 4.3.1 section 7.5

Choosing controller nodes

For local development, one controller-broker is enough, but it offers no controller failover. Three controller-brokers can survive one failure; five can survive two. Choose an odd-sized coordination cluster when availability matters. section 7.1

Figure 4.11 Kafka uses either a KRaft-based or a ZooKeeper-based coordination cluster. Both should consist of an odd number of nodes (usually three or five) and use a protocol to find a consensus.
A group of ovals with text

AI-generated content may be incorrect.

The diagram contrasts KRaft- and ZooKeeper-based coordination clusters and shows why controller-node count is a cluster-design choice. section 4.3.1

Kafka 3.3.0 made KRaft production ready; Kafka 3.5.0 deprecated ZooKeeper coordination, with ZooKeeper-backed support slated for removal in Kafka 4.0. For an existing ZooKeeper cluster, migration is a planned sequence: provision KRaft controllers with the same cluster ID, enable migration settings, verify metadata transfer, then move brokers to KRaft mode and test stability. Do not treat a development single-controller setup as a production failover configuration. section 7.1 section 7.5

How Apache Kafka in Action covers it

How deep it goes
Explains controller roles, failure tolerance, metadata storage, and migration steps, but does not detail Raft’s consensus algorithm.
Examples
Uses bank-transfer partitions and one-, three-, and five-controller configurations to illustrate coordination and failure tolerance.
What it assumes
Introduces brokers, topics, partitions, and leaders through a bank-transfer scenario before explaining cluster coordination.
What you can do after
Operate/configure it by choosing controller capacity and planning a verified migration from ZooKeeper-backed coordination.
How it connects
Connects Raft consensus and ZooKeeper replacement to Kafka brokers, controllers, partitions, leader elections, and cluster metadata.

Also explained in

Compare how 2 books explain KRaft →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Apache Kafka in Action. The section links point to the parts of the book it draws on.