The CAP theorem states that a distributed database can guarantee only two of three properties: Consistency (every read gets the latest write), Availability (every request gets a response), and Partition tolerance (the system works despite network failures). Since network partitions are inevitable, you choose between consistency and availability.

How CAP Theorem Works

When a network partition splits your database cluster, you choose: reject requests to stay consistent (CP — like MongoDB, HBase) or serve potentially stale data to stay available (AP — like Cassandra, DynamoDB). Most real-world systems let you tune this per-query.

Key Concepts

  • Consistency — Every read returns the most recent write — all nodes see the same data at the same time
  • Availability — Every request receives a response — the system never refuses to answer
  • Partition Tolerance — The system continues operating despite network failures between nodes

Frequently Asked Questions

Which should I choose: consistency or availability?

Banking, inventory → consistency (CP). Social media feeds, analytics → availability (AP). Most applications need consistency for writes and can tolerate eventual consistency for reads.