Course map

Topic 128 / Core

CAP theorem and PACELC

Chapter 8.2 · Consistency Theory

What and why

Replication (→ 72) gives availability and scale, but one question stays open: when a network partition actually happens (→ 126), what should a replicated system do? The CAP theorem states that a replicated data store can provide at most two of three properties at once — Consistency (every read sees the latest write, i.e., linearizability), Availability (every request gets a non-error response), and Partition tolerance — and since partitions will happen regardless of design, the real choice CAP forces is: during a partition, choose availability or consistency. PACELC adds the trade-off for the rest of the time: else (no partition), choose latency or consistency — because even a healthy network has propagation delay, so staying strongly consistent still costs latency. Builds on: → 126 (network partitions).

Diagram

Situation Forced choice
During a partition (CAP) Availability or Consistency — not both
Else, no partition (PACELC) Latency or Consistency — not both

How it works

  1. Partition tolerance isn't optional in practice — networks partition regardless of design — so CAP is read as a forced choice between C and A for the duration of a partition, not a three-way menu.
  2. Choosing C during a partition means the side that can't confirm it holds the latest data refuses requests rather than risk returning stale or conflicting data — correctness over uptime.
  3. Choosing A during a partition means every side keeps serving requests, possibly returning stale reads or accepting writes that later conflict and must be reconciled (→ 134) — uptime over strict correctness.
  4. PACELC's second half applies the rest of the time: staying linearizable still requires coordinating with remote replicas before replying, which costs latency; accepting eventual consistency lets a node reply from local state immediately.
  5. The choice is made per data item, not once for a whole system — an account balance and a "likes" counter on the same platform can legitimately sit on opposite sides of this trade-off (→ 129).

Practical example

(illustrative). A partition splits a 2-region deployment. A CP-leaning configuration has the minority region return errors for writes until the partition heals — correct, unavailable. An AP-leaning configuration keeps accepting writes in both regions, producing two divergent histories for any row touched on both sides, which must be reconciled once the partition heals (→ 134).

When to use it

  • Use when: deciding, per data item, whether it can tolerate being wrong-but-available or must refuse rather than be wrong.
  • Avoid when: applying one answer to an entire system — most real systems are a mix.
  • Failure scenarios: a system advertised as "always consistent and always available" that has simply never been tested under a real partition; defaulting to AP everywhere because it's simpler, including for data where staleness causes real harm (an inventory count that oversells).
  • Simpler alternative: for a single-node or single-region system with no replication, CAP doesn't apply yet — don't invoke it until there are actually multiple nodes that can disagree.

Practice

(Vocabulary kind — classification drill; 15–20 min, no lab services). For 5 data items (an inventory count, a social "like" count, a password hash, a chat message's delivery status, a bank balance), decide CP or AP and justify with one sentence naming the concrete harm of choosing wrong. Done when every answer names a harm, not just a label.

Key takeaway

During a partition, pick availability or consistency — there is no third option — and the same latency-vs-consistency trade-off exists even without a partition. Done when you can: classify 5 data items as CP or AP with a stated reason, and state the PACELC trade-off separately from the CAP one. Used next in → 129, 130.

References

Kleppmann and Riccomini, Designing Data-Intensive Applications — see references.md.

Source directory

Search the guide