0 XP · 0 scenes

CAP Theorem Explained Simply

By Vivek Kumar Bhardwaj · Updated · 5 min read

The CAP theorem says that when a network partition happens in a distributed system, you must choose between consistency and availability. It is about what you give up during a failure, not a menu where you pick two letters for everyday life.

The three words

  • Consistency. Every read sees the latest write, as if there were one copy of the data.
  • Availability. Every request to a working node gets an answer, even if it might be old.
  • Partition tolerance. The system keeps working even when the network splits and some nodes cannot talk to each other.

Why you cannot skip the P

Networks do fail. Cables break, switches crash and whole zones lose contact. A distributed system has to be ready for that, so partition tolerance is not really optional. The real choice is what to do when a partition happens.

Picture two data centers that lose their link. A user writes to one. If the other keeps answering reads, it may return old data (you chose availability). If it refuses to answer until the link is back, it stays correct but some users get errors (you chose consistency).

CP and AP in practice

ChoiceBehaviour during a partitionTypical examples
CP (consistency first)Some requests fail or wait so data stays correctCoordination services such as ZooKeeper and etcd, many relational setups
AP (availability first)Every node answers, data may be briefly stale and is merged laterCassandra and DynamoDB in their default modes

Beyond the label

  • Many databases let you choose per request. With quorums, reading from R nodes and writing to W nodes out of N gives strong consistency when R + W is greater than N.
  • When there is no partition you still trade latency against consistency. The PACELC idea names this: if there is a Partition choose A or C, Else choose Latency or Consistency.
  • "Consistency" in CAP means strong, single-copy behaviour. It is not the same as the C in ACID transactions.

What to say in an interview

Do not just say "we pick AP". Say which data needs which guarantee. A bank balance needs consistency. A like counter or a feed can be eventually consistent. Then name how you would get it: consensus (Raft), quorums, or conflict resolution.

See it happen in the CAP lesson: split the network yourself and watch what each choice does.