CAP Theorem & PACELC
Definition
Network partition
- In plain English
- A network partition is when machines in a system are running but can't reach each other.
- Think of it like
- It is like two halves of a team on a phone line that keeps cutting out.
CAP theorem
- In plain English
- The CAP theorem says that during a network partition, a replicated system must choose between consistency (everyone sees the same latest data) and availability (every request gets an answer).
- Think of it like
- It is like two shop branches that lose their phone link and must either stop selling the last item or risk both selling it.
PACELC
- In plain English
- PACELC extends CAP: if there's a Partition choose Availability or Consistency, Else choose between Latency and Consistency.
- Think of it like
- It is like deciding not only what to do in a storm but also whether to drive fast or carefully on a normal day.
Why it exists
Two dispatch servers lose their network link. Both still run, but neither knows whether the other assigned the last free ambulance.
In CAP, consistent means every reader sees the latest change, as if there were only one copy.
Available means every working server still gives a real answer. Replying with an error does not count.
How it works
Two clients reach separate live nodes whose link cannot carry messages.
| Choice | During a partition | User sees | Useful when |
|---|---|---|---|
| CP: consistency over availability | Refuse operations that cannot be safely coordinated | Some errors or waiting | Conflicting assignments are dangerous |
| AP: availability over consistency | Answer without waiting for unreachable copies | Possibly stale or conflicting values | Old schedule data remains useful |
- PACELC also considers normal operation: coordinating distant copies can add latency.
- Synchronous replication waits for other copies, but waiting alone does not guarantee every read is fresh.
- Asynchronous replication can acknowledge sooner, while reads on lagging copies may return old data.
- Choose per operation
Ask what a wrong answer would cost compared with an unavailable answer.
- Specify the response
Document which side may answer and which operations must wait or fail.
- Plan recovery
If both sides accept changes, define how their conflicting updates are resolved.
Examples
Refuse an uncertain assignment
The dispatch system cannot confirm whether an ambulance remains free across a partition.
An assignment request succeeds only when exclusive ownership can be confirmed; otherwise it is refused and a dispatcher is alerted.
This operation chooses CP. It needs an atomic assignment check as well as fresh data, so two callers cannot both reserve the same ambulance.
The insight
Choose consistency when conflicting actions are dangerous.
Keep the schedule readable
The stage schedule app shows the last known schedule while copies cannot communicate.
An attendee reads a reachable local copy and receives the last known schedule with its update time.
This read chooses AP. Label older data so attendees can judge it, and merge updates when communication returns.
The insight
Availability is useful when an old answer remains acceptable.
Choose by operation
A nearby replica shows available-copy counts quickly, while borrowing checks the leader.
A reader browses a nearby replica but sends borrowing to the leader, which checks and reserves a copy before confirming.
The browse count may lag. Borrowing must check and reserve together, and may fail during a partition when coordination is unavailable.
The insight
PACELC decisions can differ between browsing and borrowing.
Trade-offs
Pros
- CP avoids conflicting operation histories.
- AP preserves responses from reachable nodes.
Cons
- CP can reject work during partitions.
- AP can require conflict resolution.
Use when
- Assignments need one agreed result.
- Read-only schedules can tolerate old data.
Avoid when
- One system-wide label hides different operation needs.
- Treating an error message as “still available”.
Quick check
Takeaways
- Partitions can force you to sacrifice consistent responses or successful responses.
- Choose guarantees per operation using the cost of wrong and missing answers.
- PACELC adds the latency and consistency choice during normal operation.