System design concepts · When Machines Disagree

CAP Theorem, PACELC and Consistency Models Explained

CAP is the most quoted and most misunderstood theorem in system design. Here's the version that actually helps you make decisions.

What you'll be able to explain
  • State CAP precisely and avoid the common misreadings
  • Use PACELC to discuss the everyday latency/consistency trade-off
  • Rank consistency models from linearizable to eventual
  • Pick consistency per feature, not per system
  • Use CRDTs and version vectors for convergence

CAP, stated properly

In a distributed data system, when a network partition (P) happens, you must choose between:

  • Consistency (C): every read sees the latest write (linearizability), so some requests must be refused or wait.
  • Availability (A): every request to a non-failed node gets a response, which may be stale.
CLIENTUser in MumbaiCLIENTUser in DelhiDATABASEReplica Abalance = ₹900DATABASEReplica Bbalance = ₹1,000withdraw ₹100read balance?partition
During a partition, a replica that can't reach the others must either refuse (CP) or answer with possibly stale data (AP).

Partitions aren't optional (networks fail), so the real choice is CP or AP during a partition. When there's no partition, you can have both.

Common trap

Saying "we chose CA". You can't opt out of partitions in a distributed system. And "AP" doesn't mean "no consistency ever"; it means "during partitions, we prefer answering over being up to date".

PACELC: the everyday trade-off

CAP only talks about partitions, which are rare. PACELC adds the common case: if Partition, choose A or C; Else, choose Latency or Consistency. Even with a healthy network, waiting for replicas to agree costs time.

System During partition Normally Notes
Cassandra / DynamoDB (default) A L Tunable per query
MongoDB (majority writes/reads) C C Configurable
Spanner / CockroachDB C C Pays latency for consensus
PostgreSQL + async replicas C (primary) L (replica reads) Depends on where you read

Consistency models, strongest to weakest

LinearizableBehaves like one copy; reads see the latest completed writeSequentialAll see the same order, not necessarily real-timeCausalCause before effect for everyone; concurrent ops may differRead-your-writesYou always see your own updatesMonotonic readsYou never see time go backwardsEventualReplicas converge if writes stop
From strongest (top) to weakest (bottom). Stronger is simpler to reason about and costlier.