CAP Theorem Explained
The fundamental impossibility result that forces distributed systems to choose between consistency and availability during network partitions.
CAP Theorem
The CAP theorem states that a distributed data system can provide at most two of three guarantees simultaneously: Consistency (every read returns the most recent write), Availability (every request receives a response), and Partition tolerance (the system operates despite network failures).
Explanation
Formulated by Eric Brewer in 2000, the CAP theorem defines the fundamental trade-off in distributed systems. In a single-server database, you get all three: every read is consistent, the server always responds, and there are no network partitions to worry about. But in a distributed system — data replicated across multiple nodes — network partitions are inevitable, so you must choose between consistency and availability during a partition. CP systems (Consistent + Partition-tolerant) refuse to respond rather than return stale data during a partition. Examples: MongoDB (in certain configurations), HBase, ZooKeeper. These are suitable for financial transactions where incorrect data is worse than no data. AP systems (Available + Partition-tolerant) continue responding during partitions but may return stale data. Examples: Cassandra, DynamoDB, CouchDB. These suit use cases where availability is critical and temporary inconsistency is acceptable (social media feeds, product catalogs). In practice, the CAP theorem is more nuanced than a simple three-way choice — the PACELC theorem extends it to consider latency trade-offs during normal operation.
Bookuvai Implementation
Bookuvai evaluates CAP trade-offs during the architecture design phase of every project. We match the consistency and availability requirements of each data domain to the appropriate database technology. Financial data uses CP systems with strong consistency; user-facing catalogs and feeds use AP systems with eventual consistency.
Key Facts
- Network partitions are inevitable in distributed systems
- CP systems sacrifice availability for consistency during partitions
- AP systems sacrifice consistency for availability during partitions
- PACELC extends CAP to include latency trade-offs during normal operation
- Formulated by Eric Brewer in 2000, proved by Gilbert and Lynch in 2002
Related Terms
Frequently Asked Questions
- Can I have all three CAP properties?
- In a single-node system, yes. In a distributed system, no — network partitions are inevitable, so you must choose between consistency (refuse requests during partitions) and availability (respond with potentially stale data).
- Is the CAP theorem still relevant?
- Yes, but it is often oversimplified. Modern databases offer tunable consistency (e.g., Cassandra allows per-query consistency levels). The PACELC theorem adds nuance by considering latency trade-offs during normal (non-partition) operation.
- What is the PACELC theorem?
- PACELC extends CAP: if there is a Partition, choose Availability or Consistency; Else (during normal operation), choose Latency or Consistency. This captures the everyday trade-off between fast reads (eventually consistent) and slow reads (strongly consistent).