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.

Let's discuss about CAP Theorem in detail in this thread:


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 🙂


• • •

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

Keep Current with Sunil Kumar

Sunil Kumar Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!


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

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

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

2. Gradient Hunt

Read 21 tweets
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

2. Freelancer

Read 21 tweets
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.

Read 15 tweets
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:

Read 11 tweets
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

2. Tech Interview Handbook

Read 11 tweets
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:

🧵🧵🧵 Image
1⃣Chris the Freelancer

Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!

This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!