9 Oct, 13 tweets, 4 min read
We keep hearing about the CAP Theorem, know what it means, but don't really know what it actually means in a real world distributed system.

🧵👇🏻
Definition:

CAP Theorem is one of the important system design concepts. It states that any distributed system can guarantee only 2 of the 3 following properties:

- Consistency
- Availability
- Partition Tolerance

Let's discuss different scenarios possible in a real world.

👇🏻
For the discussion we will take this distributed system as an example which has two components C1 & C2.

They are connected to each other and are always in sync with respect to the data they store.

👇🏻
1. Availability - Partition Tolerance (AP):

Let's assume the connection b/w the two components is broken. So we say that there's a partition in the system.

Now based on the theorem only either consistency or availability can be achieved. Not both.

Let's understand why.

👇🏻
Let's say we have a data variable a = 10 in both C1 and C2.

Since there's a partition in the system, the question is whether we want the system to be available until the partition is fixed or not.

Now if the user interacts with the component C1 and updates a to 20.

👇🏻
(Since availability is our goal, we will still allow the users to use the system by making consistency take a hit)

Since the connection between C1 & C2 is broken, `a` will still contain the value 10 in C2.

👇🏻
This means system was available(A) during this transaction but consistency(C) is not achieved.

👇🏻
2. Consistency - Partition Tolerance (CP):

In the same example if we want to keep the system consistent, we will not allow users to use the system until the partition is fixed.

This means that the system is not available all the time.

👇🏻
Once the partition is fixed and the system is up again, users can interact with the system and data will be consistent since the connection between the two systems would be working again ( partition is fixed ).

👇🏻
3. Consistency - Availability (CA):

Now in case of CA, we want the system to be both available and consistent.

So in this case if there's any partition in the system we will not allow users to interact with a part of the system, which means there's no partition tolerance.

👇🏻
Let's assume C2 has some issues. Now we will take C2 out of the working system until it is fixed, which means we will not allow users to interact with C2 and thus no partition tolerance in the system.

In our example only C1 would be functional.

👇🏻
C1 now is a single component in the distributed system which is available and consistent.

In real world we will have so many more components. So if 5% of the components go down, the rest 95% of the components will still be available and consistent.
I hope the CAP theorem is now clearer to you with the real world examples.

I'll be writing an articles with more detailed examples and explanations on my blog. Subscribe to stay updated 🙂

sunilkumarc.in

• • •

Missing some Tweet in this thread? You can try to force a refresh

This Thread may be Removed Anytime!

Twitter may remove this content at anytime! Save it as PDF for later use!

# More from @sunilc_

10 Oct
Are you a front-end developer / designer ?

You will be interested in these 20 websites that will help you with color codes & palettes:

🧵👇🏻
1. HTML Color Codes

htmlcolorcodes.com

6 Oct
Everyone wants to make money through freelancing but struggle to get started. Choose the right platform based on your skills.

Here's a thread on the list of top 20 freelancing platforms for designers and developers:

🧵👇🏻
1. Upwork

upwork.com
2. Freelancer

freelancer.com
4 Oct
Being a developer is like having superpower nowadays.

In this thread let's go over the different options to make passive income online with developer skills:

🧵👇🏻
1. Educational Course

University education is becoming less popular because of the amout of online courses that are available now.

A course by an expert in the field is a better option among learners instead of an expensive degree by an University.

👇🏻
The result is that there are huge opportunities for creating paid educational content.

You can host your courses on platforms like Udemy or on your own website if you want control over your customers and their emails.

👇🏻
2 Oct
SEO is a skill everyone should develop in this digital age and it's very important in building a brand and improving online presence.

Here's a list of top YouTube channels to learn SEO:

🧵👇🏻
30 Sep
Are you preparing for your interviews? It can be difficult to chalk out a plan yourself.

Here's a list of Github repositories which will help you create a study plan:

🧵👇🏻
1. Coding Interview University

github.com/jwasham/coding…
2. Tech Interview Handbook

github.com/yangshun/tech-…
29 Sep
Freelancing can replace your salary and can give you the freedom from your 9 - 5.

Here's a thread on the list of top youtube channels for getting started with freelancing:

🧵🧵🧵
1⃣Chris the Freelancer