Apache ZooKeeper with out a client
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache ZooKeeper is a high-performance coordination service for distributed applications. It exposes common services - such as naming, configuration management, synchronization, and group services - in a simple interface so you don't have to write them from scratch. You can use it to reliably coordinate large distributed systems.
What is Apache ZooKeeper?
Apache ZooKeeper is an open-source server which enables highly reliable distributed coordination. Originally a subproject of Hadoop, ZooKeeper has graduated to become a top-level project of its own. It is designed to be a robust, scalable, distributed coordination system that can be integral to distributed applications.
How Does ZooKeeper Work?
ZooKeeper runs in a cluster where one node is elected as a leader and the others are followers. The leader handles all write requests to prevent conflicting writes and ensure consistency, while read requests can be handled by any node. The ZooKeeper service itself is replicated over several servers. Each ZooKeeper server keeps an in-memory image of the state, along with a transaction log and snapshots in a persistent store.
Technical Details of ZooKeeper
Data Model
ZooKeeper manages its data in a hierarchical namespace, much like a file system or a tree data structure. Each node in the tree is called a znode. Each znode can store data and have children. It is possible to set watches on znodes. A ZooKeeper client can get updates on changes to a znode.
Znodes
Znodes maintain a stat structure that includes version numbers for data changes, ACL changes, and timestamps to enforce ordering. There are two types of znodes:
- Persistent Znodes: these are not deleted when the client disconnects.
- Ephemeral Znodes: these are deleted when the client that created them disconnects.
Consistency
Clients interact with a single ZooKeeper server, and each client maintains a TCP connection through which it communicates with its server. If a client falls over to another server, it will synchronize with the new server.
Sessions
Client sessions are supported by ZooKeeper, where client interaction with the cluster is through a session. Sessions help in maintaining soft state across client interactions with different servers.
Example Use Case: Configuration Management
ZooKeeper can be used for managing configuration information. For instance, in a distributed system, nodes can read their configuration from a configuration file. If there is any change in configuration, rather than changing it manually on every node, the change can be made once at the ZooKeeper service, and all nodes will get updated configuration.
Table: Summary of Key Features
| Feature | Description |
| Data Model | Hierarchical namespace similar to a file system. |
| Nodes (Znodes) | Both persistent and ephemeral types. |
| Consistency | Writes are through a leader to ensure consistency. |
| Sessions | Client interactions maintained through sessions. |
| Watches | Clients can receive notifications on znode changes. |
Conclusion
Apache ZooKeeper is a critical technology for creating distributed applications due to its simplicity and effectiveness at performing common coordination tasks. The architecture of ZooKeeper enables it to handle large sets of data across clusters efficiently. This makes ZooKeeper indispensable in modern distributed systems where reliability, scalability, and consistency are crucial.
Related reading
- ApacheKafka Appender logback
- Are there any good alternatives to RabbitMQ for low-end setups?
- Auto reconnect not woring in kafka
- Automate RabbitMQ consumer testing
- AppFabric cache configuration and hosts
- AppFabric unable to create a DataCache (LMTRepopulationJob FAILS)
- Application Load Balancers vs API Gateway
- Are there any gotchas in deploying a Cassandra cluster to a set of Linode VPS instances?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.