Scaling data / Intermediate / 6 min
CAP theorem: a partition forces a choice
Cut the link between two regions. CP refuses requests on the minority side; AP keeps answering and loses writes when the link heals.
Start the simulation → Change the load, break a part, watch what happens. Free, no sign-up.
In short
- What it is
- CAP says that while the network is split, a replicated system must choose between consistency (refuse) and availability (answer, maybe stale).
- Why it matters
- Links between data centres do fail, so every distributed database has to decide which of the two it gives up during a split.
- The trade-off
- CP returns errors on the minority side; AP keeps serving but reads go stale and conflicting writes must be merged or lost.
- Say it in an interview
- "Payments and inventory are CP, likes and feeds are AP; and when there is no partition, PACELC says the trade-off is latency vs consistency."
Check yourself
During a network partition, what does CAP say you must give up?
Answer: Either consistency or availability. Partitions happen, so while one lasts a system either refuses some requests (CP) or answers with possibly stale data (AP).
In CP mode, which side keeps working during the split?
Answer: The side with a majority of replicas. Only a majority can be sure it has the latest data, so the minority refuses rather than risk answering wrongly.
An AP system heals with last-write-wins. What can happen?
Answer: Writes accepted on the losing side during the split are thrown away. LWW keeps only the newest value. Systems that cannot lose writes merge instead (CRDTs, version vectors, or app-level merges like a shopping cart union).