16. Consistency and CAP
1
The picture to keep in your head2
16.1 What does "consistent" actually mean?3
16.2 What is strong consistency?4
16.3 What is eventual consistency?5
16.4 What are read-your-writes and monotonic reads?6
16.5 What is a network partition?7
16.6 What does the CAP theorem actually say?8
16.7 What do CP and AP systems look like in practice?9
16.8 What is PACELC?10
16.9 How do quorums give tunable consistency?11
16.10 How do you choose consistency for each feature?12
Memory card and where the analogy breaks13
Practice: five levels14
Interview questions15
Solutions16
Sources17
Code lab16. Consistency and CAP
Memory card and where the analogy breaks
3 min read+10 XP
The memory card (tear this page out)
| # | Question | Memory code |
|---|---|---|
| 16.1 | Two meanings of consistent? | ACID's C keeps the rules; CAP's C keeps the copies agreeing |
| 16.2 | Strong consistency? | Many counters, one ledger |
| 16.3 | Eventual consistency? | Couriers arrive eventually; until then, branches may disagree |
| 16.4 | Session guarantees? | Show me my own deposit, never go back in time, and never show the answer before the question |
| 16.5 | Partition? | A cut line and a slow line look the same from your side |
| 16.6 | CAP? | When the line is cut, refuse or risk: you can't promise both right and always |
| 16.7 | CP vs AP? | CP says sorry; AP says maybe |
| 16.8 | PACELC? | On bad days, choose answer or accuracy; on good days, choose speed or accuracy |
| 16.9 | Quorums? | Ask enough counters that the asking and the telling must overlap |
| 16.10 | Per feature? | Price the stale answer and the missing answer; pick per feature |
The whole chapter in one line: When copies can't talk, choose sorry or maybe; when they can, choose fast or certain; and choose per feature, not per company.
Where the analogy breaks
- Clerks can tell when a phone line is dead. Servers can't tell a dead line from a slow one, which is why timeouts and careful defaults matter so much.
- A bank can call the customer back to fix an overpayment. Software often can't undo a stale decision (a shipped order, a sent email), so choose strong consistency where undoing is hard.
- Two counters is a small bank. Real systems have dozens of replicas, and "consistent" can mean many precise things in between strong and eventual.
Quick check
Five questions on this chapter. Pick an answer, then check it.
quiz