Back to roadmap
Module 3 · Consistency & ReplicationDay 01925 min

CAP Theorem

Under network partition, you must pick consistency or availability.

Day 019

CAP Theorem

Partition
note
CP — refuse writes
datastore
AP — accept, reconcile
datastore
Signal path
CAP at the moment of a partition
Partition
note
flow
CP — refuse writes
datastore
Partition
note
flow
AP — accept, reconcile
datastore
Memory hook

CAP Theorem: under network partition, you must pick consistency or availability

Mental model

choose the failure mode you can explain

Design lens

AP keeps users productive; CP keeps invariants tight.

Recall anchors
PartitionConsistencyAvailability

Why it matters

When a network partition splits replicas, you can either reject writes to keep state consistent (CP) or keep accepting writes and reconcile later (AP). CAP says you cannot have both.

Deep dive

CAP is only about behavior during partitions. Outside partitions, every system trades latency vs consistency separately (PACELC).

CP examples: HBase, traditional RDBMS with synchronous replication, etcd, ZooKeeper. They prefer to refuse rather than diverge.

AP examples: Cassandra (default), DynamoDB tunable, Riak. They prefer to keep serving and reconcile via vector clocks, LWW, or CRDTs.

Demo / scenario

Two-region active-active write store under inter-region partition.

  1. Region A and B both accept writes.
  2. Conflict in same key occurs in both regions.
  3. AP: both succeed; reconciliation merges or picks LWW on heal.
  4. CP: one region refuses writes (loses availability); state stays single-valued.

Tradeoffs

  • AP keeps users productive; CP keeps invariants tight.
  • CP under partition equals downtime to the minority side.
  • Hybrid systems pick differently per workload (orders CP, profile AP).

Diagram

Partition
CP — refuse writes
AP — accept, reconcile
CAP at the moment of a partition.

Mind map

Check yourself

Loading quiz…

Sources & further reading