ZooKeeper: Coordination Service Built on Consensus
What you'll learn: How Apache ZooKeeper uses consensus to provide distributed coordination primitives like locks, leader election, and configuration management.
What Is ZooKeeper?
ZooKeeper is a coordination service that helps distributed applications manage shared state, elect leaders, and synchronize operations. Instead of building consensus algorithms directly into every distributed application, ZooKeeper provides high-level primitives built on top of a consensus protocol called ZAB (ZooKeeper Atomic Broadcast), which works similarly to Raft.
Think of ZooKeeper as a bulletin board for distributed systems: all nodes can read and write small pieces of coordination data (like "who is the leader?" or "what's the current configuration?"), and ZAB ensures every node sees updates in the same order.
How ZooKeeper Uses Consensus
ZooKeeper runs as a replicated cluster (typically 3, 5, or 7 servers). ZAB ensures:
- Total order: All state changes are applied in the same order across all replicas
- Atomic broadcast: Updates either succeed everywhere or nowhere
- Leader-based replication: Like Raft, one server is the leader handling writes; followers replicate
When a client writes to ZooKeeper (e.g., creating a lock node), the leader uses ZAB to replicate that operation across a quorum before acknowledging success.
Coordination Primitives
ZooKeeper exposes a simple hierarchical namespace (like a file system) where nodes can:
- Create ephemeral nodes: Automatically deleted when the client disconnects (useful for leader election)
- Watch for changes: Get notified when data updates
- Create sequential nodes: Auto-numbered for implementing distributed queues or locks
These simple primitives enable complex coordination patterns without requiring each application to implement Raft or Paxos.
Key Takeaway: ZooKeeper abstracts consensus complexity (via ZAB) into simple coordination primitives, letting distributed applications manage leader election, configuration, and synchronization without implementing consensus themselves.