Topic 13.1
CAP Theorem
In one line
During a network partition you choose between consistency and availability — and the answer is per-component, per-moment.
Think of it like this
Two friends running a shared shopping list app on their own phones with no internet between them (a network partition). Either the app refuses to let them edit (sacrificing Availability) until they're back online, or it lets both edit and sorts out the conflict later (sacrificing Consistency). It can't magically give perfect syncing AND always-on editing while they're disconnected.
Key ideas
- 01
The three properties: Consistency (all nodes answer the same), Availability (every node answers at all), Partition tolerance (survive node-to-node network failure).
- 02
The real statement: when a partition happens, you CANNOT have both C and A — you pick.
- 03
It is a partition-time choice, not a permanent property; most systems are 'CP during partition, consistent-ish anyway'.
- 04
The interview abuse: people call systems 'AP' or 'CP' as labels — correct them softly: 'tell me what happens during a partition'.
- 05
Every leader-based store (Postgres, Redis, Mongo) is CP during partition: the minority side becomes read-only or rejects.
- 06
Dynamo-style (Cassandra, DynamoDB) is AP during partition: any replica answers, conflicts merge later.
- 07
The graceful answer: 'during a partition my writes either fail (CP) or diverge-then-merge (AP); which I choose depends on whether the write can be merged.'
Code & diagrams
The exact moment the choice is forced: the network link between two nodes breaks.
Explain without notes
A bank and a news feed both partition. Which picks C and which picks A — and why is the bank 'CP during partition' fine?
Practice
Classify Postgres, Cassandra, Redis Cluster and DynamoDB on the partition-time axis, with the 'why'.
Trade-offs
- ↔
CP = availability drop during partitions; AP = staleness and merge logic. Neither is globally better.
Run it in production
You've designed it. Now build, operate, and break the same idea hands-on in the DevOps courses:
Completion checklist
I can state CAP precisely and classify a store by partition behavior, not by vibes.