Skip to content
IT glossary
BackendUpdated December 3, 2026

Apache ZooKeeper

A coordination service that lets applications running on several machines share small pieces of state and agree on things like which instance should lead.

Also known as: ZooKeeper

What ZooKeeper is for

Imagine a service with several workers, only one of which should schedule the nightly job. If every worker makes that decision on its own, several may launch the job. Apache ZooKeeper gives the workers a shared place to record who has the role and detect when it becomes available. It provides the coordination primitives; the workers still decide what to do and run the job themselves.

How it works

ZooKeeper organizes data as a tree of znodes. Each znode has a path, such as /scheduler/leader, and can hold a small value. A persistent znode outlives the client session. An ephemeral znode belongs to a session and is removed when that session closes or expires. A brief network interruption does not necessarily end the session: a client can reconnect before the timeout.

Clients can register watches to learn that a znode or its list of children has changed. A standard watch fires once. Treat it as a signal to read the current state and set another watch, not as a stream containing every intermediate change.

A production cluster, called an ensemble, elects a ZooKeeper server to lead it and put writes in order. A write commits once a majority of voting servers acknowledge it. A three-server ensemble can therefore keep committing writes with one server down, but not with two down. Normal reads are served by the server a client is connected to and may not reflect the very latest committed write.

Example: electing a scheduler

Each worker tries to create an ephemeral znode at /scheduler/leader with its own ID. ZooKeeper allows only one creation at that path. Workers that find the node already present can watch for its removal and try again. What if the winner loses its connection? The znode remains until the session ends. Even after expiration, the old worker may not yet know it lost the role. The election decides who holds the role in ZooKeeper; it does not make external actions exactly-once. For instance, the job store can enforce a unique ID for each scheduled run so two workers cannot enqueue it twice.

Where it fits and what interviews test

Common uses include leader election, distributed locks, and small shared configuration records. ZooKeeper is not a general-purpose database or a message broker. Older Apache Kafka deployments used it for cluster coordination; Kafka 4.0 removed ZooKeeper mode and uses KRaft to manage metadata.

In a system design interview, walk through a network partition or a worker crash rather than just naming the tool. Explain which side can still commit writes, when an ephemeral znode disappears, and how you would keep a former leader from doing duplicate work. Keep the two elections separate: ZooKeeper elects a server to order writes, while your application uses ZooKeeper to elect a worker.