Skip to content

CAP Theorem

In one line

CAP theorem: in a distributed system, you can have at most 2 of Consistency, Availability, Partition tolerance — not all 3.

In simple words

The CAP theorem (Brewer's theorem) states that a distributed database system can provide at most two of three guarantees simultaneously:

  1. Consistency — every read returns the latest write or an error
  2. Availability — every request gets a response (not necessarily latest)
  3. Partition tolerance — system works despite network failures between nodes

Since network partitions can happen, you must choose between C and A:

  • CP (Consistency + Partition tolerance) — reject requests during partition (e.g., MongoDB, HBase)
  • AP (Availability + Partition tolerance) — serve stale data during partition (e.g., Cassandra, DynamoDB)
  • CA — impossible in distributed systems (partitions will happen)

Most NoSQL databases are AP (eventual consistency). Traditional RDBMS are CP (strong consistency, single-node). The choice depends on your use case — banking needs C, social media can tolerate A.

Example

text
CAP Theorem — pick 2 of 3:

  Consistency (C): All nodes see the same data
  Availability (A): Every request gets a response
  Partition tolerance (P): Works despite network splits

Examples:
  CP: MongoDB, HBase, Redis Cluster
      → During partition: reject writes (stay consistent)
  AP: Cassandra, DynamoDB, CouchDB
      → During partition: accept writes (may be stale)
  CA: Traditional RDBMS (single-node MySQL/PostgreSQL)
      → No partition possible (single node)

Real-world:
  Banking → CP (consistency is critical)
  Social media feed → AP (stale posts are OK)
  Shopping cart → AP (availability drives sales)

CAP forces a choice: consistency (reject stale reads) or availability (serve stale reads) during network partitions. Most NoSQL is AP; traditional SQL is CP.

Common confusions

  • Confused with: ACID

    The difference: ACID is about transaction properties (Atomic, Consistent, Isolated, Durable) — a single-node concept. CAP is about distributed system trade-offs (Consistency, Availability, Partition tolerance) — a multi-node concept. ACID's 'C' is about transaction integrity; CAP's 'C' is about all nodes seeing the same data.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary