The CAP theorem, formulated by computer scientist Eric Brewer, states that in a distributed data store, it is impossible to simultaneously guarantee all three of the following properties:
- Consistency (C): Every read receives the most recent write or an error.
- Availability (A): Every request receives a non-error response, without the guarantee that it contains the most recent write.
- Partition Tolerance (P): The system continues to operate despite an arbitrary number of messages being dropped (or delayed) between nodes.
The theorem asserts that in the presence of a network partition (P), a distributed system must choose between Consistency (C) or Availability (A), but not both. This is why the only possible options are CP and AP systems, not CA.
Why Not CA?
- Partition Tolerance (P) is a necessity in distributed systems because network partitions are inevitable in real-world scenarios (e.g., network failures, node crashes, or latency spikes).
- If you design a system that prioritizes Consistency (C) and Availability (A) but ignores Partition Tolerance (P), the system will fail catastrophically when a partition occurs. Thus, CA is not a practical option in real-world distributed systems.
Why Only CP or AP?
-
CP Systems (Consistency + Partition Tolerance)
- In a partition, the system sacrifices availability to maintain consistency.
- Example: If a node cannot communicate with others due to a partition, it may refuse to respond to requests (reducing availability) to avoid serving stale data.
- Used in systems where correctness is critical (e.g., banking systems, distributed databases like MongoDB in strict consistency mode).
-
AP Systems (Availability + Partition Tolerance)
- In a partition, the system sacrifices consistency to remain available.
- Example: If a node is cut off, it may continue serving stale data rather than failing.
- Used in systems where uptime is critical (e.g., social media platforms, DNS, Cassandra in default mode).
Why Not All Three (CAP)?
- Network partitions force a trade-off: When a partition occurs, you cannot simultaneously guarantee both consistency and availability because:
- If you allow writes to proceed on both sides of the partition, you lose consistency (AP).
- If you block operations until the partition is resolved, you lose availability (CP).
- P is non-negotiable: Since partitions are inevitable, you must choose between C and A when they occur.
Conclusion:
The CAP theorem is not about choosing two out of three properties in general but about the trade-off that must be made when a partition occurs. Since partitions are unavoidable, the only realistic options are CP or AP, not CA. This is why the theorem is often framed as a choice between C and A in the presence of P.