Advanced Topic 44 of 51 Databases
CAP Theorem
Trade-off among consistency, availability and partition tolerance.
How it works
The CAP theorem states that a distributed data store cannot simultaneously guarantee consistency, availability and partition tolerance. Since network partitions can always happen, a system must choose during a partition between consistency, refusing some requests so all nodes agree, and availability, answering every request, possibly with stale data. CP systems such as HBase and etcd favor consistency, while AP systems such as Cassandra and DynamoDB in default mode favor availability. PACELC extends the idea to normal operation, where latency trades against consistency.
Step-by-step walkthrough
- Consistency means every read sees the latest write.
- Availability means every request gets an answer.
- Partitions, broken links between nodes, will happen.
- During a partition you must choose consistency or availability.
- CP systems refuse requests, AP systems answer with possibly stale data.
Where it is used
System architects use CAP to reason about replication and failure behavior and to pick databases that suit their requirements.
Common pitfall
It is often misread as pick any two: partition tolerance is not optional in a distributed system. Consistency here means linearizability, unlike ACID consistency. Real systems offer tunable settings, not a binary choice. Decide the behavior needed per operation rather than per database.
Where it fits in the course
CAP Theorem is topic 44 of 51 in Databases, rated Advanced. It follows Graph Databases. The next topic is Eventual Consistency.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Databases quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Databases quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is CAP Theorem?
Where do people use CAP Theorem?
What is the most common mistake with CAP Theorem?
What should I learn before this topic?
How can I practice it?
Is CAP Theorem hard to learn?
How long does it take to learn CAP Theorem?
Which topics are related to CAP Theorem?
What should I study after CAP Theorem?
Related topics
- Graph Databases (Databases)
- Eventual Consistency (Databases)
- Column-Family Stores (Databases)
- Data Warehousing (Databases)
- Bayes' Theorem (Math for Computing)
- Master Theorem (Algorithms)
- Central Limit Theorem (Math for Computing)