Understanding the CAP theorem [Math Mondays]
One of the most important concepts when it comes to building systems.
If you like my writing, I would really appreciate an anonymous testimonial. You can drop it here.
To learn more about the newsletter, check our detailed About Page + FAQs
To help me understand you better, please fill out this anonymous, 2-min survey. If you liked this post, make sure you hit the heart icon in this email.
Recommend this publication to Substack over here
Take the next step by subscribing here
Life is all about tradeoffs,
This is also true in designing high-level systems. As an engineer/tech manager, you will have to design systems that are scalable, robust, and (most importantly) useful. A large part of this is in understanding your problem domain and picking the avenues that you should maximize and which metrics are not critical.
The CAP theorem is one way of framing the tradeoffs you would make. It states that you can only guarantee 2 out of the 3 desirable traits you would want in a distributed system- Consistency, Availability, and Partition Tolerance.
Have you ever seen an advertisement for a landscaper, house painter, or some other tradesperson that starts with the headline, “Cheap, Fast, and Good: Pick Two”?
.In this post, we’re going to go over what these terms mean and why you have to make a tradeoff. In a follow-up Sunday post, I will go into more detail about the datasets you should know about to excel in your interviews/system design work.
Sponsored Segment
Start speaking a new language in just three weeks with Babbel
Learning to speak a new language goes beyond just vocabulary: it’s about being able to hold a real-life conversation with a local, and understanding the culture and the people of each place. Consider Babbel your expert-led passport to learning, with 10-minute lessons that are so effective, many users feel confident speaking a new language in just three weeks. Supplement those with the podcasts, games, articles and live online classes for a well-rounded education in weeks. Start learning a new language (and culture) today for up to 55% off by clicking here.
Important Highlights
What is the CAP Theorem- As mentioned, the CAP theorem (or Brewer's theorem after computer scientist Eric Brewer) states that you can only guarantee 2 out of the 3 desirable traits you would want in a distributed system- Consistency, Availability, and Partition Tolerance.
What is Consistency in the CAP theorem- Every node in your network will be updated with the most recent read/write at the same time. This ensures that at any given moment, every node has the same values.
What is Availability in the CAP theorem- Each read or write request for a data item will either be processed successfully or will receive a message that the operation cannot be completed (I like to liken it to the idea of Atomicity in ACID). Every node must be able to respond in a reasonable amount of time.
What is Partition Tolerance in the CAP theorem- Partitions occur when due to a failure in the network responsible for connecting the nodes of the system. The nodes are fragmented into different partitions and the nodes in each partition can only communicate with each other. Partition Tolerance guarantees that the system keeps functioning when this happens.
Why we can only make 2 out of 3 guarantees in the CAP theorem- In the case where you have single systems (no partitions can occur), you can guarantee Consistency and Availability. Single-node systems clearly can’t guarantee Fault Tolerance.
Let’s say that network partition failure happens, it must be decided whether to do one of the following:
cancel the operation and thus decrease the availability but ensure consistency
proceed with the operation and thus provide availability but risk inconsistency.
Knowing which tradeoff to pick- Depending on your needs, these 3 metrics will have different importances. So how do you know which guarantees to pick? I suggest thinking back to your end customer. Which of these can they live without? Which guarantee is absolutely essential? Your user journey will decide which guarantee you sacrifice.
To those of you who want some fun visuals, the following video by ByteByteGo is a good start. Check it out.
I created Technology Made Simple using new techniques discovered through tutoring multiple people in top tech firms. The newsletter is designed to help you succeed, saving you from hours wasted on mediocre resources or on the Leetcode grind. Easily find your needs met in one place. I have a 100% satisfaction policy, so you can try it out at no risk to you. Use the button below to get 20% off for up to a whole year. Using this discount will drop the prices-
800 INR (10 USD) → 533 INR (8 USD) per Month
8000 INR (100 USD) → 6400INR (80 USD) per year
In the comments below, share what topic you want to focus on. I’d be interested in learning and will cover them. To learn more about the newsletter, check our detailed About Page + FAQs
If you liked this post, make sure you fill out this survey. It’s anonymous and will take 2 minutes of your time. It will help me understand you better, allowing for better content.
https://forms.gle/XfTXSjnC8W2wR9qT9
Stay Woke,
Go kill all,
Devansh <3
To make sure you get the most out of Math Mondays, make sure you’re checking in the rest of the days as well. Leverage all the techniques I have discovered through my successful tutoring to easily succeed in your interviews and save your time and energy by joining the premium subscribers down below. Get a discount (for a whole year) using the button below
Reach out to me on:
Instagram: https://www.instagram.com/iseethings404/
Message me on Twitter: https://twitter.com/Machine01776819
My LinkedIn: https://www.linkedin.com/in/devansh-devansh-516004168/
My content:
Read my articles: https://rb.gy/zn1aiu
My YouTube: https://rb.gy/88iwdd
Get a free stock on Robinhood. No risk to you, so not using the link is losing free money: https://join.robinhood.com/fnud75