4.4.25 · D1Databases

Foundations — CAP theorem — consistency, availability, partition tolerance

2,743 words12 min readBack to topic

Before you can understand that fork, you need to own every word inside it: node, replica, write, read, partition, failure, error, stale, and the little labels , , , . This page builds each one from nothing, in the order they depend on each other.

See the parent map for the big picture: CAP theorem.


1. A single machine holding a value

Start with the smallest possible thing: one computer that remembers one fact.

Figure — CAP theorem — consistency, availability, partition tolerance

In the figure: one box is the node. The magenta name tag on the left points at (the label that never changes). The navy arrow on the right points at the contents (), the part that can be overwritten. Notice they are two different things sharing one box.


2. Versions of the value: ,

The contents of changes over time. We name each snapshot.


3. Two operations: read and write


4. Replicas: the same value on many nodes

Now grow from one node to two.

Figure — CAP theorem — consistency, availability, partition tolerance

In the figure: two boxes ( and ) both show — that is what "replica" means, the same fact copied twice. The orange double-headed arrow is the network link that carries messages so the copies stay equal. Watch this link: everything in CAP depends on whether it works.

See Replication and Quorums for how many copies you keep and how many must agree.


5. What "failure" means: the system model

Before we can talk about a "non-failing node," we must say what a failure even is. Engineers pick a failure model — a fixed list of the bad things they promise to cope with.


The two nodes stay in sync by talking over a network link.

For the wider setting, see Distributed Systems.


7. What an "error" reply is

The Availability definition promises a "non-error" reply, so we must pin down what an error is versus a normal answer.


8. Stale vs latest


9. The timeline: write-then-read across a partition

Now watch the events in order, because the order is what creates the clash.

Figure — CAP theorem — consistency, availability, partition tolerance

In the figure, read left-to-right along the time arrow: at step 2 the red jagged mark shows the link snapping; at step 3 the magenta arrow writes into ; at step 4 the crossed-out grey arrow is the sync message that never arrives; at step 5 the violet arrow shows the read hitting , which is still holding the stale . The whole clash lives in the gap between steps 4 and 5.


10. The normal case: no partition, no dilemma

CAP's fork only appears during a partition. When the network is healthy, C and A live together happily.


11. The three CAP letters, now that every word is earned

With the vocabulary built, the parent's definitions become plain:


Prerequisite map

Node one machine

Value named x

Versions v0 v1

Read and Write

Replica same value many nodes

Failure model crash omission

Messages over a link

Partition link broken

Error vs stale reply

Stale vs Latest

Write then read timeline

CAP trade-off C vs A


Equipment checklist

What is a node?
One machine (server) that stores data and answers requests.
What does the letter stand for?
A fixed name (label) for a stored value; its contents can change.
What do the subscripts in encode?
The order of versions — bigger subscript means newer.
What is a write vs a read?
A write changes the value; a read asks for the current value.
What is a replica?
A copy of the same value stored on a different node.
What are the three failure kinds?
Crash (node stops), omission (message lost/delayed), Byzantine (node lies).
Which failures does CAP's P handle, and which not?
P handles omission (dropped messages); it assumes away Byzantine (lying) nodes.
What is a "non-failing node"?
A node that has not crashed and can still run — even if it's cut off by a partition.
What counts as an "error" reply?
An explicit refusal, an exception, or a timeout — no value returned.
Is a stale answer an error?
No — it's a real (non-error) value, so it keeps A but breaks C.
What is a partition?
An omission failure: the network drops/delays messages so nodes can't reach each other.
Why is P not optional?
Partitions happen unavoidably (cut cables, GC pauses), so the system must cope with them.
Why does the write-then-read order create the clash?
A newer write () exists that never received before the read arrives.
Can C and A both hold with no partition?
Yes — the sync message reaches before the read, so it returns the latest value.
Is CAP's C the same as ACID's C?
No — CAP-C is replica linearizability; ACID-C is transaction invariants.

Connections

  • Distributed Systems
  • Replication and Quorums
  • Eventual Consistency
  • ACID vs BASE
  • PACELC theorem
  • Consensus — Paxos & Raft
  • NoSQL Databases