Eric Brewer's CAP theorem states that a distributed data store can provide at most two of the following three guarantees simultaneously.
The Three Properties
- Consistency (C) — every read receives the most recent write or an error. All nodes see the same data at the same time.
- Availability (A) — every request receives a non-error response, though it may not contain the most recent data.
- Partition Tolerance (P) — the system continues operating even when network messages between nodes are dropped or delayed.
In practice, network partitions are unavoidable in any distributed system. This means P is not optional — you must choose between C and A when a partition occurs.
CP vs AP Systems
- CP (Consistent + Partition-tolerant): returns an error or timeout rather than stale data. Examples: HBase, Zookeeper, MongoDB (default config).
- AP (Available + Partition-tolerant): returns the best available data, possibly stale. Examples: Cassandra, CouchDB, DynamoDB (eventual consistency).
Eventual Consistency
AP systems promise eventual consistency: if no new updates are made, all replicas will converge to the same value given enough time. This is acceptable for many use cases — social media feeds, shopping carts — but not for financial transactions or inventory counts.