Lessons in this course (14)
3. CAP theorem, consistency models and PACELC
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.
| Choice | Behaviour during partition | Examples |
|---|---|---|
| CP | Refuse/timeout some requests to stay consistent | Banking ledgers, SQL with synchronous replication, ZooKeeper, etcd |
| AP | Answer with possibly stale data, reconcile later | Social 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.