In a Kafka cluster with several brokers, someone must keep track of partition assignments, leaders, and the broker acting as controller. Older Kafka deployments use a separate ZooKeeper ensemble for this coordination. The ensemble stores cluster metadata and helps the brokers agree on a consistent state; it does not store the messages in Kafka topics. section 4.3.1 section 7.2
ZooKeeper exposes a hierarchical store of ZNodes that clients can create, read, and modify. Its key property is agreement: when clients compete to change a ZNode, they observe one consistent result. ZooKeeper Atomic Broadcast (ZAB) reaches consensus through agreement by a majority of ZooKeeper nodes. An ensemble usually has three or five nodes. section 7.2 section 4.3.1
Electing a controller
Suppose the controller fails. If the controller ZNode is absent, brokers try to write their own IDs to it. One succeeds and becomes the new controller. ZooKeeper also tracks connected clients, helping Kafka detect failed brokers. The controller can then reassign partitions and select new leaders to keep the cluster available. section 7.2 section 4.3.1
Figure 7.2 Before KRaft, a Kafka cluster consisted of multiple brokers and a ZooKeeper ensemble consisting usually of three or five ZooKeeper nodes. The controller was simply one of the brokers. If the controller failed, another broker took over these tasks.
The diagram separates the Kafka brokers from their ZooKeeper ensemble and shows that the controller is a broker, not a ZooKeeper node. section 7.2
For an existing ZooKeeper-based cluster, two operational concerns matter:
- Secure the connection. ZooKeeper holds metadata, ACLs, and potentially SASL-SCRAM credentials; traffic is unencrypted by default. Kafka supports TLS connections to ZooKeeper from version 2.5, and mutual TLS is recommended. Keep clients from accessing ZooKeeper directly, and watch encryption-related latency because ZooKeeper is latency-sensitive. section 13.2.6
- Plan a move to KRaft. ZooKeeper is a separate system to maintain, and its general-purpose metadata model can become a bottleneck. KRaft brings coordination into Kafka; ZooKeeper-based cluster management is slated for removal in Kafka 4.0. Migration calls for provisioning KRaft controllers, configuring migration mode, verifying metadata transfer, and transitioning brokers. section 4.3.1 section 7.2 section 7.5


