Distributed Locking Services (CP)
You'll learn why systems that coordinate distributed locks must sacrifice availability to guarantee correctness.
The Coordination Problem
When multiple processes need to coordinate actions—like electing a leader, acquiring a lock, or maintaining distributed configuration—they rely on coordination services like ZooKeeper or etcd. These services face a critical choice: should they allow potentially conflicting decisions during a network partition, or should they refuse to answer until they're certain their response is correct?
Why CP is Non-Negotiable
Coordination services must be CP systems because inconsistent coordination leads to catastrophic failures. Imagine two servers both believing they hold the same exclusive lock—they might simultaneously write to the same file, corrupt data, or trigger duplicate financial transactions.
Consider a leader election scenario during a network partition:
- If ZooKeeper prioritized availability (AP), both sides of the split might elect different leaders
- Two leaders could issue conflicting commands, corrupting shared state
- The system would violate its fundamental correctness guarantee
Instead, ZooKeeper chooses consistency: during a partition, only the side with a majority quorum continues operating. The minority side becomes unavailable, refusing to answer requests. This ensures only one leader exists, even if some nodes can't participate.
The Correctness Guarantee
Systems like ZooKeeper and etcd use consensus algorithms (like Zab or Raft) that guarantee: if you get an answer, it's the globally consistent answer. If the service can't guarantee consistency, it simply becomes unavailable—better to block than to lie.
Key Takeaway:
Distributed locking and coordination services like ZooKeeper and etcd are CP systems because incorrect coordination (like two processes holding the same lock) causes worse problems than temporary unavailability—correctness cannot be compromised.