CAP Theorem
CAP (Consistency, Availability, Partition Tolerance) theorem is one of the fundamental theorems in distributed systems. CAP theorem, also known as Brewer’s theorem, was first advanced by Professor Eric A. Brewer and was later proved by MIT professors Seth Gilbert and Nancy Lynch.
CAP theorem states that any distributed data store system can deliver at most two of three desired characteristics:
- Consistency: Consistency guarantees that every read returns the most recent write. This means that after the execution of every operation, the data is consistent across all the nodes, and thus all clients see the same data at the same time, no matter which node they connect to.
- Availability: Availability guarantees that clients can always read and write data. This means that every request receives a response without the guarantee that it contains the most recent data.
- Partition Tolerance: Partition tolerance implies that the system continues its operation in the presence of network partitions. A partition is a communication break between two nodes in a distributed system due to a delay or message loss.
With these properties, we have three possible classes of systems: CA, AP, and CP.
However, one cannot choose both consistency and availability(CA) in a distributed system. A distributed system is always prone to network failure and hence network partitioning has to be tolerated. A CA database system delivers consistency and availability across all nodes. An example of a CA system is the traditional RDBMS which is not distributed system.
Now, in the event of a network partition, one has to choose between Consistency and Availability.
A CP system delivers consistency and partition tolerance. When one of the nodes becomes out of sync due to a partition, the system makes it unavailable until the partition is resolved. An AP system delivers availability and partition tolerance with the expense of consistency. When a partition occurs in an AP system, all nodes remain available, but those at the returned data would not be recent.
Fig b includes the examples for CA, AP, and CP systems.
Consistency, Availability, and Partition tolerance are three important properties in a distributed system. But you can choose only between Availability and Consistency as network partitioning is inevitable in a distributed system. The appropriate trade-off can be made base on the use case.
References: