Course map

Topic 136 / Advanced

Coordination services (ZooKeeper and etcd as examples)

Chapter 8.3 · Consensus and Coordination

What and why

Topics 132–133 showed consensus and leader election are correct but genuinely hard to implement well — term handling, majority arithmetic, and fencing all have to be right, with no partial credit. A coordination service is a small, strongly consistent store, itself built internally on a consensus protocol, that exposes a few primitives — key storage, change notifications, locks, and leader election — so applications borrow correctness instead of re-implementing it. ZooKeeper and etcd are the field's common examples; the point of this topic is the category, not either specific product. Builds on: → 133 (leader election).

Diagram

   App A ──┐
   App B ──┼──► Coordination service (small cluster, consensus-based internally)
   App C ──┘        stores: config keys · locks · leader-election entries
                     notifies watchers when a key changes

How it works

  1. The service runs as a small cluster and uses a consensus protocol internally to keep its own small dataset linearizable — deliberately not meant to store large amounts of data, only coordination metadata.
  2. Applications use it for configuration (small values many nodes must agree on), locks (→ 137, acquired by writing a key only one client can hold), membership (entries that disappear if a client disconnects), and leader election (→ 133, whoever successfully claims a key is leader).
  3. Watches notify a client when a key it cares about changes, instead of polling — the basis for "the leader changed, update downstream routing."
  4. Because the service's own writes go through consensus, a successful write is immediately visible, linearizable, cluster-wide — the property applications borrow instead of building themselves.
  5. The service becomes a real dependency: if it's unreachable, every application leaning on it for locks or leader election loses that capability too — it must run as a small, highly available cluster in its own right, not incidental infrastructure.

Practical example

(illustrative). A job scheduler's 5 worker processes each try to create the same "leader" key in the coordination service; exactly one create succeeds (enforced by the service's own consensus), and that worker becomes the active scheduler. If it crashes, its session-bound key disappears, a watch fires on the other workers, and a new election for the same key happens automatically.

When to use it

  • Use when: cluster-wide locks, leader election, and small shared configuration where correctness under failure genuinely matters (Project 11).
  • Avoid when: treating it as a general-purpose database — it is sized and tuned for small, infrequently-changing data, not application records or high write throughput.
  • Failure scenarios: storing large or fast-changing data and overwhelming the small cluster it runs on; running it as one node instead of a properly sized, highly available cluster, recreating the single point of failure it was meant to remove.
  • Simpler alternative: for a single process, an in-memory lock needs no coordination service; for a handful of processes sharing one database, a database row lock (→ 71) is simpler than standing up a separate coordination cluster.

Practice

(Process kind — fill a small design on paper; 15–20 min, no lab services). For Project 11's job scheduler, write out the three pieces of coordination it would delegate to a coordination service (leader election, duplicate-run prevention, worker membership) and, for each, what the application does if the service becomes unreachable. Done when each of the three has a stated degraded behavior, not just "it would break."

Key takeaway

A coordination service lets applications borrow a small cluster's already-correct consensus for locks, election, and shared config instead of re-implementing it. Done when you can: name its four primitives and one reason not to use it as a general database. Used next in → 137.

References

None — this topic makes no external claims.

Source directory

Search the guide