Module 21 / 46 · Phase E — Distributed Reality · 42 min

CAP, and
the distributed
reality.

Everything in the Beginner track quietly assumed you had one machine. The moment there are two, an unfixable trade-off appears — one that shapes every database, every queue, every cache you'll work with in production. Welcome to distributed systems.

// What you'll know by the end

  • The CAP theorem stated correctly (not the usual myth)
  • Why "CP vs AP" is the actual production choice
  • What happens to writes during a real partition
  • PACELC — the trade-off CAP doesn't tell you about
§ 01 — The new reality

"Distributed systems
are different."

Twenty modules of foundation — request/response, storage, scaling, reliability, the design framework. All of it built on a quiet assumption: there is a system. Singular. One MySQL primary. One Redis. One API server (or, fine, a few, but treated as interchangeable). The conversation was always about what the system does, not what happens when the system disagrees with itself. That last sentence sounds odd because the previous track gave you no reason to imagine it. It's about to become unavoidable.

"A distributed system is one in which the failure of a computer you didn't even know existed can render your own computer unusable."
— LESLIE LAMPORT

Once you have more than one node — replicas, shards, microservices, multi-region writes — every "obvious" thing you knew about programming gets quietly violated. The system can be in two different states at the same time. A write can be acknowledged and then disappear. A read can return data that no client ever wrote. Two correct programs running on two correct machines can produce contradictory truths and both be right. This isn't bug-land; it's the territory.

// HIDDEN ASSUMPTIONS OF THE BEGINNER TRACK
i
// what we assumed
"A write that returns 200 OK has happened."
The new truth: a write that returned 200 from one replica may not yet be visible at another. It may also be rolled back if the replica that accepted it crashes before the data propagated.
ii
// what we assumed
"Two reads of the same key return the same value."
The new truth: reading from different replicas — or even the same replica at different times — can return different values, depending on the consistency model.
iii
// what we assumed
"The network either delivers a message or doesn't, quickly."
The new truth: the network can partition, arbitrarily delay, deliver out of order, or duplicate. You can't tell "slow" from "dead" — and the design of your system depends on which you guess.
iv
// what we assumed
"There's a single global ordering of events."
The new truth: in a distributed system, there is no global clock. Two events on different machines have no inherent before/after — only causal relationships, which need explicit tracking (M.23 territory).

The first concept that forces all of this into the open is the CAP theorem. It's the most-quoted, most-misstated result in distributed systems folklore. People who can quote it often get it wrong; people who don't quote it sometimes apply it correctly by intuition. The goal of this module is to give you the precise version, the production-relevant version, and a simulator that makes the trade-off impossible to forget.

The moment there are two nodes, you must choose which lie to tell when they disagree.
§ 02 — The theorem, stated correctly

Three letters.
You can only
pick two.

Brewer's CAP theorem (formalized by Gilbert & Lynch, 2002) says: any networked shared-data system can guarantee at most two of the following three properties at the same time. This sounds like a buffet, but it isn't — one of the three is not really optional in practice. Get clear on each definition first, then we'll see why the choice is narrower than it looks.

// THE THREE LETTERS · WHAT EACH ACTUALLY MEANS

C
Consistency
// strictly: linearizability
Every read returns the most recent write, or an error. Not ACID consistency — this is about all nodes seeing the same value at the same time. After a successful write, no read anywhere returns the old value.
A
Availability
// every request gets a non-error response
Every non-failing node returns a response (success or value), not an error, for every request — even when other nodes are unreachable. No "go away, I can't help right now."
P
Partition Tolerance
// system keeps working when messages are lost
The system continues to operate even when the network drops or delays messages between nodes — i.e., when the cluster has been split into groups that can't talk to each other.

The theorem says: during a network partition, you cannot have both Consistency and Availability. Pick one. This is the entire content of CAP, and it's much narrower than the way it's usually quoted.

// THE MYTH · AND THE PRECISE VERSION

WHAT PEOPLE OFTEN SAY
WHAT THE THEOREM ACTUALLY SAYS
"Pick 2 of 3: Consistency, Availability, Partition Tolerance."
"During a network partition, you must choose between Consistency and Availability." When there's no partition, you can have both.
"Cassandra is AP, Postgres is CA, MongoDB is CP."
No system is "CA." Partitions will happen in any networked system. Real systems fall on a CP-vs-AP spectrum for partition behavior.
"It's a permanent property of the system."
It's a per-operation, per-moment choice. Some operations in a system can be CP; others on the same system can be AP.
"Consistency means data is correct."
CAP "Consistency" means linearizability — every read sees the latest write across the whole cluster. Different from ACID's C, which is about constraints.

That last row is worth re-reading. The "C" in CAP is not the "C" in ACID. CAP's consistency is about distributed observability: can two clients reading from two different nodes at the same moment see the same value? ACID's consistency is about constraints: does the database state satisfy the schema's invariants (foreign keys, NOT NULL, unique)? They use the same word for completely different ideas. Mix them up at your peril.

§ 03 — Why it's really CP vs AP

P isn't
optional. So pick.

The third row in the myths table is the one that bites. In any real distributed system — once your data lives on more than one machine, especially across availability zones, regions, or data centers — partitions will happen. Network cables get cut. Switches reboot. Cloud regions lose connectivity. Even within a single datacenter, microsecond delays under load can functionally partition nodes (one node hasn't heard from another in long enough that it's effectively isolated). Partition tolerance isn't a thing you choose; it's a thing you survive.

That collapses CAP from a three-way pick to a two-way one. Once you accept that P is mandatory, the only real choice during a partition is:

// THE ACTUAL CHOICE · CP vs AP DURING A PARTITION

// CP — choose Consistency
Refuse the write.
Stay correct.

When a partition happens, the minority side stops accepting writes (and often reads too). It returns errors. The majority side continues serving. "Better unavailable than wrong."

Use when: the data must be correct (money, inventory, identity). A stale read or lost write would cause real harm.

// canonical CP systems
etcd ZooKeeper HBase Consul Spanner
// AP — choose Availability
Accept the write.
Reconcile later.

When a partition happens, both sides keep accepting reads and writes. They diverge temporarily. When the partition heals, conflicts are reconciled (last-write-wins, vector clocks, CRDTs, custom merge). "Better stale than unavailable."

Use when: staleness is recoverable. A user's shopping cart, a like count, a cache entry — all tolerate momentary inconsistency.

// canonical AP systems
Cassandra DynamoDB Riak Voldemort CouchDB

Two things to internalize. First, "AP" doesn't mean "no consistency forever" — it means during a partition, prefer availability. After the partition heals, AP systems work to reconverge. The technical name for this is eventual consistency (M.22 will go deeper). Second, the choice can be made per operation. DynamoDB lets you choose: for this read, do you want a fast eventually-consistent answer (AP), or are you willing to wait for a strongly-consistent one (CP)? Production systems don't pick CP-or-AP globally; they pick it per call.

Real systems don't pick CP-or-AP globally; they pick it per call.

Now you've heard the theory. Time to make the choice physical. The lab below puts you in control of a 3-node cluster — partition it, choose your mode, and watch the consequences of CP vs AP play out write by write.

§ 04 — The partition simulator · interactive lab

Now feel the
trade-off.

Below: a 3-node cluster. Pick a network topology (healthy, or one node isolated, or a brain split). Pick CP or AP mode. Send writes to any node and watch what survives. The event log shows the negotiation; the verdict explains what just happened. The CP/AP trade-off should become so visceral after this lab that you'll never confuse it again.

PARTITION.SIM // m.21 lab
// 3-NODE CLUSTER · current state
CP MODE A ↔ B · OK A ↔ C · OK B ↔ C · OK A node-1 B node-2 C node-3 cluster: healthy · quorum: 2/3
// network topology
// send a write
// utility
// event log
No events yet. Try sending a write to any node.
// VERDICT
Ready when you are

Pick a topology, choose a mode, send some writes. The verdict will explain what happened and why — covering quorum math, divergence, and what real systems do in the same situation.

§ 05 — PACELC

The trade-off
CAP doesn't tell you.

CAP describes what happens during a partition. But partitions are rare — minutes per year in a well-run system. CAP says nothing about the other 99.9% of the time. Daniel Abadi's 2010 extension fills the gap: PACELC. It reads as: "during a Partition, choose between Availability and Consistency. Else (no partition), choose between Latency and Consistency." The "ELC" half is the one most engineers haven't met, and it's the one that shapes day-to-day system feel.

// PACELC · THE FULL DECOMPOSITION

P · A · C
During a Partition: choose Availability or Consistency. This is the classic CAP trade-off — refuse writes on the minority side (CP), or accept and diverge (AP).
E · L · C
Else (no partition): choose between Latency and Consistency. This is the under-appreciated half. Even when the network is healthy, achieving strong consistency requires cross-node coordination — and coordination adds latency. Faster reads usually mean accepting that some replica might be slightly behind.
EXAMPLE
DynamoDB · "PA / EL" — under partition: stay Available. No partition: minimize Latency. Defaults to eventual consistency for both speed reasons. Pays the consistency cost only when you explicitly ask.
EXAMPLE
Spanner · "PC / EC" — under partition: stay Consistent (refuse writes on minority). No partition: still pays Consistency cost (cross-region coordination via TrueTime, ~10ms minimum). Slower but always correct.
EXAMPLE
Most SQL DBs · "PC / EL" — under partition: refuse minority writes (CP). No partition: typically read from primary fast, accept that read replicas can lag (EL: prefer latency, accept some staleness for reads).

The EL/EC distinction is what determines whether your "strongly consistent" database feels snappy or sluggish at low load. Spanner's elegance is real, but the price is paid in every read latency — every operation does a coordination round trip. DynamoDB defaults the other way: tell me you need consistency, and I'll do the work; otherwise, fast and slightly stale is the default. Both are correct designs for different needs. PACELC just makes the trade-off visible.

Internalize this: when someone says "we need a strongly consistent database," ask "strongly consistent during partitions, or also during normal operation?" The first is CAP-C. The second is PACELC's EC. Different cost, different system, different conversation.

§ 06 — Eight words for the new vocabulary

Vocabulary,
for the cluster.

The distributed-systems vocabulary that shows up in every paper, every system doc, every postmortem. Master these and a whole literature opens up.

Linearizability
/ˌlɪn.i.ɚ.aɪ.zəˈbɪl.ɪ.ti/
The strongest single-key consistency model. Every operation appears to take effect atomically at some instant between its start and end. After a write completes, every subsequent read returns that value.
Network Partition
/pɑːrˈtɪʃ.ən/
A network event that splits a cluster into groups that can communicate within but not between. Not optional — every distributed system experiences them. Sometimes lasts seconds; sometimes hours.
Split Brain
/splɪt breɪn/
When a partition causes two or more sides to each believe they're the leader and accept writes independently. The classic AP failure mode that requires reconciliation on heal.
Quorum
/ˈkwɔːr.əm/
The minimum number of nodes that must agree for an operation to proceed. Typically floor(N/2) + 1 — a strict majority. Ensures only one side of a partition can make progress.
Eventual Consistency
/ɪˈven.tʃu.əl/
A guarantee that if no new writes happen, all replicas eventually converge to the same value. The opposite of linearizability. The "eventually" can be milliseconds or hours.
Stale Read
/steɪl riːd/
A read that returns an outdated value because the replica hasn't yet received recent writes. Allowed in AP systems, forbidden in CP systems. Not a bug — a design choice.
PACELC
/peɪ-sɛlk/
Abadi's extension of CAP. "During Partition: Availability vs Consistency. Else: Latency vs Consistency." Captures the trade-off even when the network is healthy.
Conflict Resolution
/ˈkɒn.flɪkt/
The process of merging divergent values from different replicas after a partition heals. Strategies: last-write-wins, vector clocks, application-level merge, CRDTs.
§ 07 — Knowledge check

Five questions.
Defend the trade-off.

Test the distributed-systems intuition. Click an answer; explanation drops in instantly.

QUESTION 1 OF 5
Loading question...
Score: 0 / 5
5 / 5

Partitioned.

Perfect. The CAP/PACELC framing is yours, and the trade-off is no longer a textbook diagram. Next: a closer look at consistency itself — the spectrum from linearizable down to "almost certainly eventually."

§ 08 — The recap

Three ideas to
carry forward.

The trade-offs at the heart of distributed systems. Every module in this track will refer back to these.

i

P isn't optional

Partitions will happen in any networked system. CAP collapses to a CP-vs-AP choice during partitions — and that's the only choice worth thinking about.

ii

Pick per operation

Real systems don't choose CP-or-AP globally. They choose per call, per query, per write. The mature view: tell me what this specific operation needs.

iii

PACELC fills the gap

CAP covers partitions. PACELC covers the rest of the time. Even healthy systems trade latency for consistency — the choice is just less visible.

↓ UP NEXT

M.22 — Consistency
models.

Now that you know CP and AP, zoom in. Linearizable, sequential, causal, eventual, read-your-writes, monotonic — the precise spectrum, and which model real systems give you. The vocabulary your favorite database's docs assume you already speak.

Continue to Module 22 →