All the basics

What is the CAP theorem?

When two copies of your data lose contact, you must pick: refuse to answer, or answer with maybe-old data.

Picture a triangle: always right, always answering, survives a split. When the split hits, you keep only one of the first two.

Press Play to watch it run · 4 steps

A writer updates Copy A while the link to Copy B is broken, and a reader asks Copy B.

Two copies, one broken linkA writer updates Copy A while the link to Copy B is broken, and a reader asks Copy B.keeps in syncYouCopy ACopy BA friend

Tap any box to see what it is and what it talks to.

  • Client
  • Database
Open in playground
Text description
  1. You change your balance from 100 to 50 on Copy A.
  2. The link between the copies breaks. The news never arrives.
  3. A friend asks Copy B for your balance.
  4. Copy B answers 100. That is old, and nobody knows it is wrong.
  • Network splits happen, so you choose during one.
  • Pick right and refuse, or answer and maybe be old.
  • With no split, you can have both.

Reach for it when

Whenever data lives on several machines. For money, pick correct and refuse; for a like count, answer with maybe-old data.

The catch

Pick correct and a split makes the bank app say try later; pick answering and a feed shows old counts.

Say it in an interview“CAP only bites during a network partition. Then I pick per feature: consistency for money, availability for feeds, and I say what users will see.”