Loading…
Loading…
Charting your lesson…
Opening your lesson…
CAP Theorem
Lesson 5 of 6
In a network partition a distributed store must choose between consistency and availability — the CAP trade-off.
6 steps•about 11 min•8 flashcards
Step 1/ 61 min
The CAP theorem is the single most-quoted (and most-misquoted) idea in distributed systems interviews. Stating it precisely — and applying it to a real database choice — instantly separates candidates who memorized a slogan from those who understand it.
Step 2/ 62 min
The CAP theorem (Brewer's theorem) says a distributed data store can guarantee at most two of three properties at the same time:
Because real networks will partition, P is not optional. So the practical choice during a partition is C vs A.
The famous "pick two" is really "when a partition happens, pick C or A." When there is no partition, a well-built system can offer both strong consistency and availability. CAP is a statement about behavior during partitions, not a permanent cap on features.
CAP ignores latency. PACELC extends it: if Partition, choose A or C; Else (normal operation), choose Latency or Consistency. Many systems trade a little consistency for lower latency even when healthy. Also, "consistency" here means linearizability (strong), not ACID's C. Real databases are tunable — e.g., Cassandra (AP-leaning) and Dynamo-style stores let you pick per-request consistency levels; systems like HBase or a single-primary SQL lean CP.
Step 3/ 61 min
Two data centers lose the link between them (a partition). A banking ledger must not show two conflicting balances, so it's CP: it rejects writes on the minority side until the link heals — correct but temporarily unavailable there. A social "like" counter is AP: both sides keep accepting likes and merge the counts afterward — always available, briefly inconsistent. Same partition, opposite correct choices, driven by requirements.
Step 4/ 61 min
Lean CP when correctness is non-negotiable: payments, inventory, bookings, unique constraints. Lean AP when availability and user experience matter more than momentary accuracy: feeds, likes, presence, product views.
Step 5/ 61 min
Remember "P is mandatory, so it's really C-or-A." And: CP = correct but may go down; AP = always up but may be stale.
Don't say "you pick any two of C, A, P." In a real distributed system partitions are unavoidable, so you can't drop P. The real trade-off is Consistency vs Availability during a partition.
Step 6/ 6· Worked examples1 min
Problem
During a network partition in a distributed database, you must trade off consistency vs availability. Which do you favour for (a) a shopping cart and (b) a stock-trade matching engine?
Try it on paper first.
Recall
Keep this
Fast revision of the CAP theorem.
You've read 0 of 6 steps
Now lock it in — questions straight after reading are what make it stick.