CAP Theorem in Distributed Systems
The three properties associated with the CAP theorem are Consistency, Availability, and Partition Tolerance.
Consistency: Maintaining consistency in all the nodes of the system.
Availability: Making the system available even if a node or functionality fails.
Partition Tolerance: Making the nodes of the system work independently even if the communication breaks between the nodes.
CAP theorem states that only two of these properties could be satisfied in a distributed system.
If the system prioritizes Consistency, then every node must be updated with the recent value which can increase latency and reduce availability
If the system prioritizes Availability, it has to be available all the time which might not allow all the nodes of the system to be updated regularly.
If the system prioritizes Partition Tolerance, it will not be able to provide both consistency and availability. When a network failure occurs between two nodes in the system, it is impossible to communicate and send updated data from one node to the other while maintaining availability. In the same way, if the system needs to be available, it cannot maintain consistency.
Example:
Consider a distributed social media application where network failure occurs and a data center is isolated.
If the system prioritizes consistency, it would block the like requests in the isolated region leading to consistency in the like count.
On the other hand, if the system prioritizes availability, it would allow the users from the isolated region to like the posts but the like count wouldn't be consistent throughout the data centers.