Two GeneralsCAP TheoremCoordination PrimitivesCP SystemDistributed Systems

The Coordination Problem

Why distributed coordination is fundamentally hard — networks are unreliable, clocks drift, and processes crash. Understanding the problem is the first step to appreciating ZooKeeper's solution.

35 min read9 sections
01

Why Coordination is Hard

In a single-process application, coordination is trivial — you use a mutex, a semaphore, or a simple variable. But the moment you distribute your system across multiple machines, three fundamental problems make coordination extraordinarily difficult.

⚔️

The Two Generals Problem

Two armies on opposite sides of a valley need to attack simultaneously. They can only communicate by sending messengers through the valley — but messengers can be captured. General A sends 'Attack at dawn.' Did General B receive it? B sends back 'Confirmed.' Did A receive the confirmation? Neither general can ever be 100% certain the other will attack. This is the fundamental impossibility of reliable communication over unreliable channels — and it's exactly what networks are.

The Three Fundamental Challenges

  • Network unreliability — messages can be lost, duplicated, delayed, or reordered. You cannot distinguish a slow node from a dead one.
  • Clock skew — no two machines have perfectly synchronized clocks. Even with NTP, drift of 10-100ms is common. You cannot use timestamps for ordering.
  • Process crashes — any process can crash at any point, including mid-operation. Partial failures are the norm, not the exception.
coordination-failure.txttext
Scenario: Two services try to become leader simultaneously

Timeline:
  t=0ms   Service A: "I'll check if there's a leader..."
  t=1ms   Service B: "I'll check if there's a leader..."
  t=2ms   Service A: reads DBno leader exists
  t=3ms   Service B: reads DBno leader exists  (race condition!)
  t=4ms   Service A: writes "I am leader"success
  t=5ms   Service B: writes "I am leader"success

Result: SPLIT BRAINboth think they're the leader
  - Service A processes orders 1-50
  - Service B processes orders 1-50 (duplicates!)
  - Data corruption, lost money, angry customers

This is why you need atomic coordination primitives.

FLP Impossibility Result

Fischer, Lynch, and Paterson proved in 1985 that in an asynchronous system where even one process can crash, it is impossible to guarantee consensus will be reached. Every practical consensus system (including ZooKeeper) works around this by using timeouts and assuming partial synchrony.

1 / 9