If you have ever worked on distributed systems you’ve probably heard about CAP Theorem which says that achieving all aspects of consistency, availability, and partition tolerance at the same time is impossible.
What is CAP Theorem?
CAP Theorem states that a distributed system can only guarantee two of the following three properties at the same time:
- Consistency – every read receives the most recent write or an error. After an update, all subsequent reads will return that updated value. This often requires coordination and locking, which can impact performance and availability.
- Availability – every request receives a non-error response, without guarantee that it contains the most recent write. The system remains responsive under failure, but it may serve stale or approximate data to maintain uptime.
- Partition tolerance – the system continues to operate despite network partitions (communication breakdowns between nodes). Since real-world networks can fail unpredictably, this is usually a must-have.
Why does it matter?
In real-world systems, network partitions are inevitable, which means partition tolerance is non-negotiable. As a result, system designers have to choose between two other properties.
- CP (Consistency + Partition Tolerance) – data accuracy is a priority here. Some requests may fail.
- AP (Availability + Partition Tolerance) – system uptime is priority. Data might be temporarily inconsistent.
- CA (Consistency + Availability) – only possible if there are no partitions, which is not the case in distributed systems
There is no silver bullet. The right tradeoff depends on the use case. For instance, the financial systems might prioritize CP, while in a social media applications AP can be a better choice.
Summary
CAP Theorem teaches us that trade-offs are inevitable in distributed systems. When a network partition occurs (which will happen) we have to choose between sacrificing consistency to keep the system responsive (AP) or sacrificing availability to ensure data correctness (CP).
Design choices depend on the business context.
Understanding these trade-offs helps architects make better design decisions for scalability, reliability, and user experience.