LearnViz CompSci
Home / Learn / Databases / CAP Theorem

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

  1. Consistency means every read sees the latest write.
  2. Availability means every request gets an answer.
  3. Partitions, broken links between nodes, will happen.
  4. During a partition you must choose consistency or availability.
  5. 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

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Databases quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is CAP Theorem?
Trade-off among consistency, availability and partition tolerance. It belongs to Databases and is an advanced-level topic.
Where do people use CAP Theorem?
System architects use CAP to reason about replication and failure behavior and to pick databases that suit their requirements.
What is the most common mistake with CAP Theorem?
It is often misread as pick any two: partition tolerance is not optional in a distributed system.
What should I learn before this topic?
Start with Graph Databases, the topic just before it in Databases.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Databases quiz.
Is CAP Theorem hard to learn?
It is an Advanced topic. Expect to read the explanation more than once and to connect it with earlier topics. Working through a small example by hand helps most.
How long does it take to learn CAP Theorem?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to CAP Theorem?
Graph Databases, Eventual Consistency, Column-Family Stores are closely connected. The full list is in the related topics section of this page.
What should I study after CAP Theorem?
Continue with Eventual Consistency, the next topic in Databases.

Related topics