Lessons in this course (14)

3. CAP theorem, consistency models and PACELC

Intermediate★ Must knowLesson 3 of 14

CAP: in a distributed data store, when a network partition happens you must choose between Consistency (every read sees the latest write) and Availability (every request gets a response). Partitions are unavoidable, so the real choice is CP vs AP during failures.

ChoiceBehaviour during partitionExamples
CPRefuse/timeout some requests to stay consistentBanking ledgers, SQL with synchronous replication, ZooKeeper, etcd
APAnswer with possibly stale data, reconcile laterSocial feeds, shopping carts, DNS, Cassandra, DynamoDB (default)

PACELC: if Partition → choose A or C; Else (normal operation) → choose Latency or Consistency. Synchronous replication = more consistency, more latency.

Consistency models: strong (linearizable) → read-your-writes → monotonic reads → causal → eventual (replicas converge eventually). Choose per feature: payment balance strong; like counts eventual.

ACID vs BASE: ACID (Atomicity, Consistency, Isolation, Durability) — relational transactions. BASE (Basically Available, Soft state, Eventually consistent) — many NoSQL systems.