ZooKeeper, etcd, and Distributed Coordination

How ZooKeeper and etcd package consensus as a small, strongly consistent store, and how systems build leader election, locks, membership and configuration on top of it.

Overview

Why a coordination service exists

Many distributed systems need a few decisions that every server must see the same way: who the leader is, which server owns which partition, which servers are alive, what the current configuration is. Getting those right needs consensus, and consensus is hard to build. A coordination service does it once, well, and hands everyone else a small store with strong guarantees.

ZooKeeper and etcd are the two best-known examples. Each runs as a small cluster, usually three or five servers, that replicates every write through a consensus protocol: Zab in ZooKeeper, Raft in etcd. One server in the cluster is the leader and the rest are followers. Applications talk to it as clients. A typical setup has several application servers that keep their bulk data elsewhere, in a normal database, and use the coordination cluster only for small, critical decisions.

Key concepts

  • Coordination service
  • Znode
  • Ephemeral znode
  • Sequential znode
  • Lease (etcd)
  • Watch
  • Fencing token
  • Herd effect

Interview questions

  • How do you implement a distributed lock safely with etcd?
  • How does leader election work in ZooKeeper, and what happens when the leader dies?
  • ZooKeeper versus etcd: how do they differ, and which would you choose?
  • Why not just put a lock row in the main database instead?

Sign up free to read the full topic

More DDIA topics

Start free on Cariara · Coding problems · System design studio