TwiceToldby Develoker
ConceptsSystem designLabsCheat sheetsAbout

Develoker makes free tools for learning to build software. TwiceTold explains each idea twice, as an everyday analogy and the real thing; CloudArch lets you design cloud systems and put load on them.

About · Labs · Cheat sheets · Learning paths

← Back to CAP theorem

⚖️ CAP theorem: cheat sheet

🎨 The analogyTwo shop branches whose phone line goes down: close until it's back, or stay open and risk different prices.
🎓 The regular explanationWhen a network split cuts replicas off from each other, a distributed database must choose between staying consistent (refuse some requests) and staying available (answer, possibly with stale data).
Two branches, one price listStep 3 of 3
network🙋Shopper A🏪North branchcake £5🏬South branchcake £5🙋‍♂️Shopper B
  1. A shop has two branches with a phone line between them. Both show the same price list, with cake at £4.
  2. The manager changes the price at the north branch. The north branch phones the south branch straight away.
  3. A shopper asks the south branch and gets £5. While the line works, you can have it all, both branches open and both agreeing.
Line down, choose consistencyStep 4 of 4
🙋Shopper A🏪North branchcake £5🏬South branchcake £5🙋‍♂️Shopper B
  1. A storm cuts the phone line. Both branches are fine, but they can't reach each other.
  2. The manager wants to raise the price to £6. The north branch can't tell the south, so it refuses rather than let the two disagree.
  3. The south branch, cut off and unsure whether it's out of date, puts up a "back soon" sign rather than risk quoting a wrong price.
  4. When the line is repaired, the south branch catches up and opens again. Nobody ever saw two different prices.
Line down, choose availabilityStep 3 of 3
🙋Shopper A🏪North branchcake £6🏬South branchcake £6🙋‍♂️Shopper B
  1. Same storm, different shop. This one would rather stay open, so the north branch takes the new price, £6, anyway.
  2. A shopper asks the south branch and is told £5. The shop stayed open, but the two branches now disagree.
  3. When the line comes back, the branches compare notes and agree on the latest change. Eventually, everyone sees £6.
Both sides accept, then a conflictStep 4 of 4
line back🙋Shopper A🏪North branchcake £7🏬South branchcake £7🙋‍♂️Shopper B
  1. The phone line is down and both branches stay open. The cake costs £5 in both.
  2. The north branch is told £6 at 10:00. The south branch is told £7 at 10:01. Neither can hear the other.
  3. The line comes back. The branches swap what they were told and find they disagree. Someone must pick a winner.
  4. The shop's rule is that the latest time wins, so £7 stays and the £6 change is thrown away. Shopper A is never told. When Shopper A asks again, they hear £7 with no warning.

🧩 Key questions

The phone line between the two branches is cut. What choice does each branch face?
Close to changes until the line is back, or stay open and risk different prices. A branch can't know what it hasn't been told, so there's no third option.
While the line works, what can the two branches do?
Both stay open and agree. The hard choice only appears when the line is down.
A branch stayed open during the storm. What must it do when the line comes back?
Compare notes with the other branch and agree on the latest price. Shoppers may have seen different prices for a while, but eventually everyone sees the same one.
Both branches stayed open. The north was told £6, the south was told £7, and the rule is that the latest time wins. What happens when the line returns?
One change wins by its time and the other is thrown away without warning. Quick rules are simple but can discard a change nobody notices. Keeping both notes avoids that.