A type of system that includes a set of computers working together to perform a task is known as a distributed system. When designing a distributed system we will come across a concept called CAP theorem. In this article, we will be diving deep into the concept.
What is the CAP Theorem?
In 2000, computer scientist Eric Brewer introduced Brewer’s theorem which is also referred to as CAP theorem. The abbreviation of CAP theorem is nothing but 3 properties that distributed systems are aiming to achieve.
Those are:
C – Consistency
A – Availability
P – Partition Tolerance
The theorem states that it is impossible to simultaneously make sure all these three properties can exist in a distributed system. Instead, we can achieve only 2 at a time.
Let us explore each property one by one.
Consistency: The reliability of Data
We might have used Google Docs or any online multi-user editor which enables us to collaborate and edit together as a team at a time. In these applications, all the users should be able to view the document consistently when any changes happen it should be seen by all the collaborators.
Similarly, Consistency means that all the collaborators should be able to see the same document content irrespective of the place from where they are checking that document. In a distributed systems context it refers that whenever users access the distributed system they should get what all others are receiving from the system.
You might have used Online Banking apps, where when you transfer a particular amount from one account to another it should be shown as transferred in one account and received in another account. This makes sure that both accounts are consistent.
Availability: Reliability of the system
Let’s say we requested something from a website that publishes the cricket score from time to time (should be by every ball). However, due to some technical issue or network failure, the delays of 1 over backward delay occurred.
Anyhow still the system remains up but not updated as it should be. Availability means the system’s capacity to remain alive or in operation and should be able to handle requests and provide responses irrespective of external factors such as failures. The response can even not be the recent one but still responds.
Sometimes, the strict consistency of data might be renounced to guarantee high availability.
Partition Tolerance: Handling the Unexpected
Partition tolerance is the ability to maintain the system’s functionality even when certain components are not communicating with one another.
Consider the following scenario:
A group of friends is collaborating on a shared document when abruptly two of them lose internet access. Partition tolerance implies that the system can continue to operate and administer the document, even though not all individuals are currently able to communicate with one another.
In a distributed system, partitions can happen when there are problems with the network, servers, or other things. Partition tolerance means that the system can handle these problems without getting worse.
Choosing Two Out of Three: The Trade-off
So, what is the true meaning of the CAP theorem in the context of distributed systems?
It indicates that we must make a choice when developing these systems: perfect consistency, availability, and partition tolerance cannot all be achieved at the same time. We must choose the two that are most important to our needs while acknowledging that the third will be slightly compromised.
For example, consider the following scenario;
If we consider consistency and availability, we may have to concede partition tolerance. This may be feasible in systems that demand consistent data, such as banking, where all users must have access to the same account balance.
If we choose Consistency and Partition Tolerance, we may see an overall reduction in availability. This may be significant in systems where accuracy is more important than accessibility, such as financial systems. Consistency may be compromised if we choose Availability and Partition Tolerance. This option is typically taken on social media platforms, when it is more important to maintain the system’s operation and responsiveness, even if not all postings or updates are always constant.
Real-World Example:
Let’s consider following a real-world scenario where we can get an actual use-case of the CAP theorem.
NoSQL databases like DynamoDB and Cassandra usually favour availability and partition tolerance over consistency. They are designed to manage large amounts of data while ensuring that the system remains functioning even if some data is temporarily inconsistent.
Traditional Relational Databases, like MySQL, typically prioritise Consistency and Availability. This means that the data you retrieve from these databases is consistently accurate, even if it means that some system components may not be fully tolerant to partitioning.
What is the importance of the CAP Theorem?
The question “What does this mean to me?” may be on your mind. The CAP theorem is important for people who build or use distributed systems, which can be anything from large-scale internet services to small apps that need to share data between different places.
By understanding the CAP theorem, developers can decide for themselves if trade-offs are right for their specific use cases.
If you’re developing a global e-commerce site, for instance, you can prioritise partition tolerance and availability to guarantee that clients can always make purchases, even if the data they’re viewing isn’t entirely up to date.
In contrast, if you’re designing a financial app, you may prioritise Consistency to ensure consumers always receive correct, up-to-date information, even if it makes the system less responsive or unavailable.
In conclusion, The CAP theorem is a potent instrument for comprehending the intricacies of distributed systems. Although it may appear abstract at first, the fundamental concept is that in a distributed system, it is impossible to have it all.
We must make decisions based on the requirements of our application and our users. By applying the CAP theorem to system design, we may create more user-friendly, efficient, and reliable applications that balance partition tolerance, availability, and consistency.
Whether you are a developer, a system architect, or just someone curious about the operations of the internet, this idea will help one to better understand the trade-offs allowing the digital world in which we live.
No related posts found.
Leave a Reply