- Published on
CAP theorem – Why You Can Only Achieve Two Out of Three
- Authors
- CN
- Name
- aadarsh
- @aadarshsingh360
- CN
In the world of distributed systems, designing applications that are robust, responsive, and reliable is a complex challenge. One of the fundamental principles guiding these designs is the CAP theorem, which states that a distributed data store can only provide two out of the following three guarantees: Consistency, Availability, and Partition Tolerance But why ?

Breaking Down the CAP Theorem
Consistency (C):
Consistency means that every read operation retrieves the most recent write. In other words, all nodes in the system have the same data at the same time.
In Real-world Imagine a banking system. When you transfer money from one account to another, the balances must be updated immediately across all systems so that subsequent queries reflect the new balances accurately.
Availability (A):
Availability ensures that every request receives a response, even if some nodes are down. The system is always operational and ready to serve user requests.
Like An e-commerce website should allow users to browse products, add items to their cart, and make purchases at any time, even if some parts of the system are experiencing issues.
Partition Tolerance
is the system’s ability to continue functioning and providing services even if communication between nodes in the system is disrupted or delayed (network partitions). In distributed systems, network partitions are inevitable due to network failures, latency, or geographical distribution of nodes. Partition tolerance ensures that the system can handle these partitions without the entire system failing.
Real-world Example: A global messaging platform must ensure that users can send and receive messages reliably, even if there are temporary network issues that prevent some users in different regions from communicating directly. The system ensures that messages are eventually delivered once the network partition is resolved.
You can’t simultaneously achieve perfect consistency, high availability – But Why ?
The reason you can’t simultaneously achieve perfect consistency, high availability, and partition tolerance in a distributed system boils down to fundamental constraints imposed by network communication and the trade-offs required to manage them effectively
- Network Communication Limits:
In a distributed system, different nodes (servers or data centers) communicate with each other over a network. Networks can suffer from latency (delays), packet loss, or even complete failures (partitions).Ensuring perfect consistency across all nodes requires synchronous communication,
where every write operation must be propagated to all nodes before confirming the operation to the user. This synchronous approach increases latency and reduces availability, especially during network partitions.
2. CAP Theorem Trade-offs:
The CAP theorem states that in the presence of a network partition (P), a distributed system must choose between maintaining consistency (C) or maintaining availability (A).
If you prioritize consistency (C), you must ensure that all nodes have the same data at all times, which can lead to rejecting requests or waiting during partitions to maintain data integrity.
Prioritizing availability (A) allows the system to respond to every request, even during partitions, but this may lead to temporarily inconsistent data across nodes.
Achieving perfect consistency, high availability, and full partition tolerance simultaneously would require unlimited resources and instantaneous communication between all nodes
Why You Can’t Have All Three
The core challenge addressed by the CAP theorem is that in the presence of a network partition, a distributed system must choose between consistency and availability. Here’s why
Network Partitions Are Unavoidable:
In a distributed system, nodes communicate over a network. Network failures and latency are inevitable due to physical distances, hardware issues, and other factors. These partitions mean that some nodes can’t immediately communicate with others.
Consistency vs. Availability During Partitions
To maintain consistency during a partition, a system might need to reject or delay some requests to ensure all nodes have the same data. This compromises availability.
To maintain availability, a system might allow operations to continue even when nodes are partitioned, which can lead to inconsistencies in the data.
Real-World Trade-offs
Let’s look at practical examples to see how different systems prioritize these aspects.
Financial Systems (Consistency + Partition Tolerance)
Financial transactions must be accurate and consistent to maintain data integrity. During a network partition, the system might reject transactions or delay them until consistency can be ensured. This means that availability is sacrificed to maintain consistency and partition tolerance.
Example: Stock trading platforms ensure that all trades are accurately recorded, even if it means some trades might be delayed during network issues.
Social Media Platforms (Availability + Partition Tolerance)
Social media platforms prioritize user experience and uptime. They allow users to post updates, like content, and interact with others even if some nodes are temporarily out of sync.
This means they accept temporary inconsistencies in favor of high availability and partition tolerance.
Example: Facebook ensures that users can always interact with the platform, even if some data might not be immediately consistent across all servers.
Conclusion
The CAP theorem is a fundamental principle that helps us understand the trade-offs in distributed system design.
By acknowledging that we can’t have perfect consistency, high availability, and partition tolerance all at once, we can make informed decisions about how to design systems that best meet the needs of our users and applications.
In practice, the right balance depends on the specific requirements of the application. Understanding the CAP theorem allows developers and system architects to create more robust and user-friendly systems by prioritizing the guarantees that matter most for their use case.