System Design Foundations

CAP Theorem

During a network partition, a distributed system must choose between Consistency and Availability — it cannot have both. Outside a partition, both are attainable; CAP is a statement about behavior under failure, not a permanent label.
  • CAP: Consistency (every read sees the latest write), Availability (every request gets a non-error response), Partition tolerance (the system keeps working despite dropped/delayed messages between nodes)
  • Partition tolerance is not really optional for a system spanning more than one machine — networks partition — so CAP in practice is a choice between C and A during a partition
  • CP systems (e.g. ZooKeeper, HBase, etcd): a minority partition refuses to serve reads/writes rather than risk returning stale or conflicting data
  • AP systems (e.g. Cassandra, DynamoDB): every partition keeps serving, accepting that replicas may diverge until reconciled afterward
  • PACELC extends CAP: Else (no partition), there is still a tradeoff between Latency and Consistency — coordinating for strong consistency costs latency even when nothing is broken
A network partition splits the cluster in two
A CP system blocks writes on the minority side (Node 3); an AP system keeps serving on both sides and reconciles later
CP vs AP, by example
CP (consistency-first)AP (availability-first)
Behavior under partitionMinority side refuses requestsBoth sides keep serving
Data riskNone — no divergence allowedDivergent writes, reconciled later
ExamplesZooKeeper, etcd, HBaseCassandra, DynamoDB, Riak
Good fitConfiguration, leader election, financial ledgersShopping carts, social feeds, presence status
Sources
  • Designing Data-Intensive ApplicationsCh. 9 — Consistency and Consensus
  • System Design Interview – An Insider's GuideCh. 1 — CAP Theorem