Introduction
There are three pillars that form the foundation of distributed systems: Consistency, Availability, and Partition Tolerance.
However, according to the CAP Theorem, you can choose only two of them. So, how do you choose between CP, AP or CA?
CP (Consistency and Partition Tolerance)
This means that availability is not the priority. The system may deny some requests if it detects that the replicas have lost communication. However, the data always remains consistent, and the system remains tolerant to network partitions.
AP (Availability and Partition Tolerance)
This means you won't have the most consistent data across all of your servers, but the system will be always available even if a network partition occurs.
If the data is updated on replica A, and you try to fetch the same information from replica B, it may not be updated yet.

CA (Consistency and Availability)
This means that the system will not always provides the most up-to-date data while remaining available to handle requests. However, it cannot tolerate network partitions. If communication between the replicas is lost, the system may fail or become unavailable. In modern distributed systems, Partition Tolerance is usually a requirement. Because of that, CA is rarely chosen in practice.
The decision
In distributed systems, most of the time we are only choosing between Consistency and Availability. Partition Tolerance is a must nowadays. With that said, the real choice is between CP and AP. So how do we decide?
Choose CP when consistency is a must, such as when dealing with money or financial transactions. It is crucial for this kind of data to be completely accurate.
Choose AP when having the most up-to-date data is not crucial. Think about likes on a social network. It is not necessary for the like count to be perfectly up to date, but the Like feature needs to be available all the time. Otherwise, users would get frustrated.
Conclusion
Now that you know what each option is and when to use it, choose wisely.
Understand your system's requirements and choose the option that fits them best.



Top comments (0)