Felpfe Inc.
Close this search box.
call 24/7

+484 237-1364‬

Close this search box.

ZooKeeper Unleashed: How Kafka Maintains Order in the Jungle


In the wild, dynamic world of distributed systems, Apache Kafka relies on an unassuming yet powerful creature to keep things running smoothly: Apache ZooKeeper. In this blog post, we delve deep into ZooKeeper, illustrating its role in Kafka, explaining its functioning, and exploring how it helps in maintaining order and reliability in the Kafka ecosystem.

Part 1: ZooKeeper’s Role in Kafka

Apache ZooKeeper provides a distributed configuration service, synchronization service, and naming registry for large distributed systems. Let’s explore how Kafka leverages these features.

1. Kafka and ZooKeeper: A Tale of Synchronization and Order

Kafka uses ZooKeeper to manage service discovery for Kafka brokers that form the Kafka cluster. ZooKeeper sends changes of the topology to Kafka, so each node in the cluster knows when a new broker joined, a Broker crashed, or a Broker left the cluster.

Here’s a simple bash command to start a ZooKeeper server:

zookeeper-server-start.sh $KAFKA_HOME/config/zookeeper.properties

This command initiates a ZooKeeper server based on the properties specified in the zookeeper.properties file in the Kafka configuration directory.

2. Tracking Controller Status in Kafka

In a Kafka cluster, one of the brokers serves as the controller, which takes care of administrative tasks such as keeping track of the brokers and partitions. ZooKeeper aids in electing a controller and tracking its status.

3. Maintaining Topic Configuration and Access Control Lists (ACLs)

ZooKeeper keeps the configuration details of topics and ACLs. Every change in these configurations is stored in the ZooKeeper.

4. Kafka Consumers and ZooKeeper

Kafka consumers leverage ZooKeeper for group management, i.e., tracking which topics each consumer group is consuming and which partition of the topic is consumed by which consumer.

Part 2: Getting Acquainted with ZooKeeper Commands

Let’s explore some basic ZooKeeper commands that can help us interact with the ZooKeeper ensemble.

5. Starting and Stopping the ZooKeeper Service

You can start the ZooKeeper service using the following command:

zookeeper-server-start.sh $KAFKA_HOME/config/zookeeper.properties

And stop it using:


6. Interacting with ZooKeeper using the CLI

ZooKeeper provides a command-line interface to interact with the service:

zookeeper-shell.sh localhost:2181

This command starts a ZooKeeper CLI session connected to the ZooKeeper service running on localhost port 2181.

7. Creating and Deleting Nodes in ZooKeeper

With the ZooKeeper shell, we can create a znode (an element in the ZooKeeper data model):

create /my_node my_data

This command creates a new znode named my_node containing my_data.

To delete a node, we use:

delete /my_node

8. Fetching Data and Setting Data for a Znode

To get data from a znode:

get /my_node

This command fetches the data from my_node.

To set data for a znode:

set /my_node new_data

This sets the data of my_node to new_data.

9. Checking the Status of a Znode

We can check the status of a znode:

stat /my_node

This command returns the status of my_node.

10. Watching Changes to a Znode

We can watch changes to a znode:

get /my_node watch

If my_node changes, we will receive a notification.


Apache ZooKeeper, as the faithful gatekeeper and organizer for Apache Kafka, plays a critical role in ensuring order within the distributed system. From maintaining synchronization to tracking statuses, managing configuration, and enabling service discovery, ZooKeeper truly “keeps the zoo in order.”

Understanding ZooKeeper’s role and functionalities within Kafka equips you with a deeper comprehension of Kafka’s operation, leading to better implementation and troubleshooting. Remember, just like in a jungle, understanding every creature – or in this case, component – is key to surviving and thriving. Happy exploring!

About Author
Ozzie Feliciano CTO @ Felpfe Inc.

Ozzie Feliciano is a highly experienced technologist with a remarkable twenty-three years of expertise in the technology industry.

Stream Dream: Diving into Kafka Streams
In “Stream Dream: Diving into Kafka Streams,”...
Talking in Streams: KSQL for the SQL Lovers
“Talking in Streams: KSQL for the SQL Lovers”...
Stream Symphony: Real-time Wizardry with Spring Cloud Stream Orchestration
Description: The blog post, “Stream Symphony:...
Kafka Chronicles: Saga of Resilient Microservices Communication with Spring Cloud Stream
“Kafka Chronicles: Saga of Resilient Microservices...
Tackling Security in Kafka: A Comprehensive Guide on Authentication and Authorization
As the usage of Apache Kafka continues to grow in organizations...
1 2 3 58
90's, 2000's and Today's Hits
Decades of Hits, One Station

Listen to the greatest hits of the 90s, 2000s and Today. Now on TuneIn. Listen while you code.