





- Brokers register their presence with ZooKeeper when they start; ZooKeeper maintains a dynamic registry of active brokers.
- ZooKeeper coordinates election of the Kafka controller (a special broker process). The controller assigns partition leaders and triggers leader elections among replicas when failures occur. ZooKeeper mediates controller election and stores the necessary metadata so the controller decision is consistent across the cluster.
- Topic configurations (number of partitions, replication factor, and other topic settings) are stored in ZooKeeper so all brokers share the same metadata view.
- ZooKeeper acts as a notification hub: when a broker fails, restarts, or when topics change, ZooKeeper notifies interested brokers and clients so they can react and reconfigure.

- Maintain a dynamic registry of active brokers so the cluster knows its members and can make partition assignments reliably.
- Mediate controller election and, through the controller, assist in leader election for partitions to ensure a single authoritative leader per partition for reads and writes.
- Store topic metadata and configuration centrally so all brokers observe consistent settings (partitions, replication factors, topic configs).
- Serve as an event/notification system that informs brokers about cluster state changes (broker failure, topic changes), enabling coordinated responses.

Operational notes
- ZooKeeper quorum: Kafka depends on a ZooKeeper ensemble for certain control plane operations. The ensemble is available as long as a majority of ZooKeeper nodes are up; if the quorum fails, critical operations (for example, electing a new controller) cannot complete.
- Offset storage history: Older Kafka consumer clients stored offsets in ZooKeeper. Since the 0.9 consumer API and later, offsets are stored in an internal Kafka topic named
__consumer_offsets, reducing direct dependency on ZooKeeper for offset storage while ZooKeeper continued to manage cluster metadata in those releases.
Note: Kafka is evolving. Newer Kafka architectures (the KRaft mode introduced as part of KIP-500: Replace ZooKeeper with a Kafka based metadata quorum and production-ready in later releases) remove the ZooKeeper dependency by integrating the metadata quorum into Kafka itself. Whether your cluster uses ZooKeeper or KRaft depends on the Kafka version and deployment choices.
- Stand up a local ZooKeeper ensemble and a small Kafka cluster (3 ZooKeeper nodes, 3 Kafka brokers).
- Observe broker registration with ZooKeeper and the controller election:
- Start ZooKeeper:
bin/zookeeper-server-start.sh config/zookeeper.properties - Start Kafka:
bin/kafka-server-start.sh config/server.properties - Inspect ZooKeeper znodes:
bin/zookeeper-shell.sh localhost:2181 ls /
- Start ZooKeeper:
- Create a topic and observe leader assignment and partition replicas:
- Create topic:
bin/kafka-topics.sh --create --topic test-topic --partitions 3 --replication-factor 2 --bootstrap-server localhost:9092 - Describe topic:
bin/kafka-topics.sh --describe --topic test-topic --bootstrap-server localhost:9092
- Create topic:
- Simulate a broker failure and watch Kafka/ZooKeeper handle controller and leader changes (stop one broker, then describe the topic again).