ZooKeeper 3.9.7: Choosing a Coordination Service
Choose ZooKeeper or another coordination service, then run a ZooKeeper 3.9.7 leader-election lab and observe how losing quorum affects writes.
ZooKeeper manages small pieces of shared coordination state with znodes, sessions, and quorum-backed updates. This guide helps you decide whether it fits, then uses a local 3.9.7 ensemble to demonstrate ephemeral sequential election proposals and quorum loss.
ZooKeeper 3.9.7: Choosing a Coordination Service
ZooKeeper is built for coordination between processes: small shared state, membership, locks, and leader election. It is another service to deploy and operate, so it should solve a coordination problem your platform does not already handle.
First choose the coordination service. Then use a local three-server ZooKeeper 3.9.7 ensemble to create two ephemeral sequential proposals and observe what happens when the ensemble loses its majority. The version and documentation were checked on 2026-11-04.
Decide whether ZooKeeper fits
Use this decision path before adding an ensemble:
- Is one process enough? Keep the state local if only one process needs it. A distributed service adds a network and failure boundary.
- Does your platform already provide the coordination primitive? For leadership among workloads inside Kubernetes, evaluate its Lease API. A managed coordination service can also avoid operating another cluster, if its semantics, availability, access controls, and cost fit the application.
- Do several applications need a shared coordination service? ZooKeeper is a candidate when they need small metadata with ordered updates, sessions, ephemeral membership, or sequential nodes, and the team can operate an ensemble.
- Are you trying to store application records or queue work? Choose a database or message broker. ZooKeeper’s tree of znodes is for coordination data, not general queries, bulk values, or durable event delivery.
| Situation | First option to evaluate | Why |
|---|---|---|
| Leader among controllers in one Kubernetes cluster | Kubernetes Lease | The control plane already stores and coordinates Kubernetes objects. |
| Shared membership, configuration, or election for multiple services | ZooKeeper, etcd, Consul, or a managed equivalent | Compare the API and consistency needs with the service your team already operates. |
| Durable event delivery, large objects, or flexible querying | A broker or database | Those systems are designed for data retrieval or message retention. |
ZooKeeper can be the right choice when applications need its specific coordination primitives and the team is prepared to own its servers, disks, network paths, ACLs, upgrades, backups, and monitoring. If your platform already runs etcd or provides an equivalent API, adding a ZooKeeper ensemble means taking responsibility for a second control-plane service. Compare failure behavior and client libraries, not a generic operations-per-second estimate.
Treat any fixed operations-per-second figure as a benchmark result, not a ZooKeeper guarantee. Throughput depends on request mix, data size, hardware, network, ensemble layout, and benchmark method. Test the operations and failure cases your application will use.
How ZooKeeper stores coordination state
ZooKeeper stores data in a hierarchical namespace. A znode has a path, optional data, children, and access controls. The data is intended for small coordination values, not large records. Clients work through sessions; ephemeral znodes are removed after the creating session ends. Sequential creation adds an increasing suffix, which gives clients an ordering mechanism. Watches notify a client about a change and must be re-armed after firing.
A write is committed through the ensemble’s quorum protocol. For a three-server ensemble, two servers make a majority. If the connected servers cannot form a majority, they cannot commit new updates or elect a functioning leader. This trades write availability during quorum loss for a shared, ordered history after recovery. The versioned ZooKeeper Programmer’s Guide covers sessions, znodes, watches, and client consistency. The Administrator’s Guide explains ensemble setup and majority behavior.
Set up a local 3.9.7 ensemble
Apache lists ZooKeeper 3.9.7 as its current release and 3.8.8 as the latest stable release, checked on 2026-11-04. This tutorial pins the commands to 3.9.7; see the release page and 3.9.7 release notes. Download the binary archive, unpack it, and set ZK_HOME to the extracted directory. This local, single-machine setup is for learning the protocol; production ensembles should place servers on separate machines and failure domains.
Create one data directory and myid file per server:
mkdir -p /tmp/zk-lab/server1/data /tmp/zk-lab/server2/data /tmp/zk-lab/server3/data
printf '1\n' > /tmp/zk-lab/server1/data/myid
printf '2\n' > /tmp/zk-lab/server2/data/myid
printf '3\n' > /tmp/zk-lab/server3/data/myid
Each configuration directory below must contain a file named zoo.cfg. Start with this server 1 example:
tickTime=2000
initLimit=5
syncLimit=2
dataDir=/tmp/zk-lab/server1/data
clientPort=2181
server.1=127.0.0.1:2881:3881
server.2=127.0.0.1:2882:3882
server.3=127.0.0.1:2883:3883
Make /tmp/zk-lab/server2/zoo.cfg and server3/zoo.cfg with the same three server lines, but set dataDir to that server’s own data directory and set clientPort to 2182 or 2183. The myid file must contain the matching server number. Each process shares the same list of members but uses unique client, quorum, and election ports. These properties follow the versioned clustered setup guide.
Start and check each server in separate commands:
$ZK_HOME/bin/zkServer.sh --config /tmp/zk-lab/server1 start
$ZK_HOME/bin/zkServer.sh --config /tmp/zk-lab/server2 start
$ZK_HOME/bin/zkServer.sh --config /tmp/zk-lab/server3 start
$ZK_HOME/bin/zkServer.sh --config /tmp/zk-lab/server1 status
$ZK_HOME/bin/zkServer.sh --config /tmp/zk-lab/server2 status
$ZK_HOME/bin/zkServer.sh --config /tmp/zk-lab/server3 status
One server should report that it is leader; the other two should report follower. If a server does not join, check that its myid matches the server.N entry, that its dataDir is distinct, and that no process is already using one of the lab ports. The pinned 3.9.7 zkServer.sh script documents the –config option and start, stop, and status commands.
Create and release election proposals
Open two terminals. In each, connect a ZooKeeper CLI client to the ensemble:
$ZK_HOME/bin/zkCli.sh -server 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
The CLI accepts commands from the versioned ZooKeeper CLI guide. In the first terminal, create a persistent parent, then an ephemeral sequential proposal:
create /election "lab"
create -s -e /election/proposal- "worker-a"
ls /election
In the second terminal, create another proposal:
create -s -e /election/proposal- "worker-b"
ls /election
The children should have different numeric suffixes, for example proposal-0000000000 and proposal-0000000001 on a new path. Compare the suffixes to see which proposal is older; do not depend on the display order from ls. In the first terminal, enter close to end that client’s session. In the second terminal, list /election again. The first proposal should disappear because it was ephemeral, leaving the second one.
Closing the CLI session makes the cleanup visible right away. If a process crashes or becomes unreachable, the ensemble cannot know immediately whether it is dead or temporarily disconnected; the ephemeral node is removed after its session expires. Applications should use session-state notifications and must stop acting as leader when they lose authority, rather than treating a short disconnect as a safe handoff.
This shows the ingredients of an election, not a complete production election client. An application must handle session state and uncertain outcomes. For example, a create request may have succeeded on the server even if the reply was lost before the client received the new path. The official leader-election recipe discusses recovery from that case and recommends that each candidate watch its immediate predecessor rather than having every candidate watch the leader. Watches are one-shot notifications, so a client must re-check state and install the next watch after a change.
A vetted client recipe also handles cases this CLI exercise cannot: reconnecting to another server, session expiration, duplicate proposals after recoverable errors, ACLs, and confirming that a process still has authority before it performs work. Do not use the smallest suffix alone as a lease to modify an external system. If the old leader is paused or partitioned from ZooKeeper but can still reach that system, fencing or a destination-side version check may be needed to prevent stale work.
What quorum loss looks like
With all three servers running, stop two of them:
$ZK_HOME/bin/zkServer.sh --config /tmp/zk-lab/server2 stop
$ZK_HOME/bin/zkServer.sh --config /tmp/zk-lab/server3 stop
Server 1 is now a minority. It cannot commit a new znode update or elect a functioning leader on its own. A client attempting a write may wait and eventually see a timeout or connection-loss error; the failure is not guaranteed to arrive as an immediate, neatly labeled “no quorum” response. An application must treat an uncertain write result as uncertain and reconcile before blindly repeating a non-idempotent action.
This does not mean every read behaves the same way during the outage. A client may remain connected to a server and receive some read responses, but a read response is not evidence that the server can commit updates or that a new leader was elected. Application consistency needs depend on the operation and any synchronization barrier used before a read. The lab demonstrates quorum-dependent writes and election, not a blanket rule that all reads stop or all reads are safe to use.
Bring both peers back:
$ZK_HOME/bin/zkServer.sh --config /tmp/zk-lab/server2 start
$ZK_HOME/bin/zkServer.sh --config /tmp/zk-lab/server3 start
$ZK_HOME/bin/zkServer.sh --config /tmp/zk-lab/server1 status
After a majority can communicate, the ensemble can elect a leader and resume quorum-backed updates. Confirm the reported roles before continuing the lab. In a real application, reconnect according to the client’s session state, re-read the coordination state, and resolve writes whose result was unknown. A timed-out request may have taken effect before the connection failed; retry logic should account for that possibility.
Before deploying in production
The lab uses three server processes on one machine, so it cannot show failure isolation. In production, the versioned administrator guide recommends an odd-sized ensemble across separate hosts; put members in independent failure domains where possible. A shared switch, storage system, or power domain can take out several members together.
Plan the service around coordination data and its clients. Keep znode values small, set ACLs for the application, protect client and quorum traffic, and monitor server state, request latency, outstanding requests, and storage health. Keep transaction logs and snapshots on reliable storage and validate backup and restore procedures. The admin guide’s monitoring, maintenance, and configuration sections are a starting point; deployment thresholds must come from your own workload and service objectives.
Use a maintenance sequence that preserves a communicating majority: stop or upgrade one member, confirm the other two still form a quorum, then bring that member back before moving to the next. With a three-member group, taking one server down leaves no room for a second failure. During an incident, check each member’s reported mode, logs, network reachability, and configured data directory before attempting recovery. Avoid deleting a peer’s data as a first response; establish which history the quorum has committed and follow the versioned recovery guidance.
Measure your request mix against a representative ensemble, include leader failover and quorum loss, and check whether the application tolerates reconnects and ambiguous writes. If a Kubernetes Lease, an existing etcd or Consul deployment, or a managed coordination service already fits, using it may leave your team with fewer systems to run.
Summary
Use ZooKeeper when its ordered, session-aware coordination model solves a real shared-state problem and your team can operate an ensemble. The local 3.9.7 exercise shows how ephemeral sequential proposals work and why a three-server group needs two reachable members for quorum-backed updates. Losing quorum blocks new committed writes and leader election; it does not justify a blanket claim about every read.
Further reading
Continue with leader election in distributed systems for algorithm tradeoffs, or compare another coordination store in the etcd guide and the Raft consensus guide.
Category
Related Posts
Leader Election in Distributed Systems
Learn how failure detection, quorum-based elections, leases, and fencing tokens affect safety and stale writes in distributed systems.
Raft Consensus Algorithm
Raft is a consensus algorithm designed to be understandable, decomposing the problem into leader election, log replication, and safety.
Distributed Systems Primer: Key Concepts for Modern Architecture
A practical introduction to distributed systems fundamentals. Learn about failure modes, replication strategies, consensus algorithms, and the core challenges of building distributed software.