<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Divyanshi Narang</title>
    <description>The latest articles on DEV Community by Divyanshi Narang (@divyanshi_narang16).</description>
    <link>https://dev.to/divyanshi_narang16</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1835128%2F856843e1-baaa-443d-bb18-58e4e0886971.png</url>
      <title>DEV Community: Divyanshi Narang</title>
      <link>https://dev.to/divyanshi_narang16</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/divyanshi_narang16"/>
    <language>en</language>
    <item>
      <title>CAP Theorem Finally Made Sense to Me</title>
      <dc:creator>Divyanshi Narang</dc:creator>
      <pubDate>Sat, 05 Sep 2026 13:23:47 +0000</pubDate>
      <link>https://dev.to/divyanshi_narang16/cap-theorem-finally-made-sense-to-me-2aei</link>
      <guid>https://dev.to/divyanshi_narang16/cap-theorem-finally-made-sense-to-me-2aei</guid>
      <description>&lt;p&gt;While studying system design, I came across something called CAP theorem.&lt;/p&gt;

&lt;p&gt;At first, it sounded simple: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt; A distributed system can choose any two out of Consistency, Availability, and Partition Tolerance.&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But the more I read about it, the more I realized that this explanation can be a little misleading.&lt;/p&gt;

&lt;p&gt;So I tried to understand it through a simple real-world example: a single restaurant inventory with two branches.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is CAP theorem?
&lt;/h2&gt;

&lt;p&gt;CAP theorem describes fundamental trade-off that exists in &lt;strong&gt;distributed systems&lt;/strong&gt;. It was introduced by &lt;strong&gt;Eric Brewer in 2000&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;CAP stands for:&lt;/p&gt;

&lt;p&gt;C - Consistency&lt;br&gt;
A - Availability&lt;br&gt;
P - Partition Tolerance&lt;/p&gt;

&lt;p&gt;But before understanding the theorem, let's understand what these three terms actually mean.&lt;/p&gt;

&lt;p&gt;Suppose you have a restaurant named PizzaPazi having two branches and sharing a single inventory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3kr3cwtuulgy2klqmvm4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3kr3cwtuulgy2klqmvm4.png" alt=" " width="800" height="396"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;Consistency - 
A customer buys the last Pizza from Branch A.
Branch A knows Pizza left = 0.
For system to be consistent, Branch B should also reflect the latest state.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In simple terms:&lt;br&gt;
&lt;strong&gt;&lt;em&gt;All nodes should agree on the current state of the data.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Availability - 
Now imagine, Branch A is temporarily unavailable.
Should Branch B also stop serving customers? -&amp;gt; Not necessarily.
Branch B should continue responding to requests.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's Availability:&lt;br&gt;
&lt;strong&gt;&lt;em&gt;The system continues responding to requests even when some parts of the system in unavailable.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Partition Tolerance - 
Due to some reasons, the network connecting A and B breaks. Both branches are running, but they cannot communicate. This is a network partition.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Partition Tolerance means:&lt;br&gt;
&lt;strong&gt;&lt;em&gt;The distributed system continues operating despite nodes being unable to communicate with each other.&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;




&lt;h2&gt;
  
  
  Where does the CAP problem come in?
&lt;/h2&gt;

&lt;p&gt;Suppose Branch A sells the last Pizza while the network is down.&lt;/p&gt;

&lt;p&gt;Branch A -&amp;gt; 0 available&lt;br&gt;
Branch B -&amp;gt; 1 available&lt;/p&gt;

&lt;p&gt;A customer now asks Branch B for the Pizza.&lt;/p&gt;

&lt;p&gt;Branch B has a choice:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Stop and wait for Branch A&lt;/strong&gt; → preserve the latest consistent state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Continue serving the customer&lt;/strong&gt; → remain available, but potentially use stale data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And that's the core idea of CAP: &lt;br&gt;
** When a network partition occurs, you cannot guarantee both Consistency, and Availability at the same time.**&lt;/p&gt;

&lt;p&gt;The biggest thing I learned is that CAP isn't just about memorizing three words.&lt;/p&gt;

&lt;p&gt;It's about asking:&lt;br&gt;
&lt;strong&gt;What should my system do when two parts of it can no longer communicate?&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;Interview-ready answer -&amp;gt; &lt;/p&gt;

&lt;p&gt;CAP theorem states that in a distributed system, when a network partition occurs between nodes, we cannot guarantee both strong Consistency and Availability at the same time.&lt;/p&gt;

&lt;p&gt;Consistency means every request gets the latest, correct data.&lt;br&gt;
Availability means every request receives a response.&lt;br&gt;
Partition Tolerance means the system continues operating even when nodes cannot communicate with each other.&lt;/p&gt;

&lt;p&gt;Since network partitions are inevitable in distributed systems, the practical trade-off is usually between Consistency and Availability during a partition — resulting in CP or AP systems.&lt;/p&gt;




&lt;p&gt;Resources I used&lt;/p&gt;

&lt;p&gt;While learning this topic, these were particularly useful:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://ksat.me/a-plain-english-introduction-to-cap-theorem" rel="noopener noreferrer"&gt;A Plain English Introduction to CAP Theorem — Kaushik Sathupadi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=VdrEq0cODu4&amp;amp;list=PL5q3E8eRUieUHnsz0rh0W6AzwdVJBwEK6&amp;amp;index=7" rel="noopener noreferrer"&gt;Hello Interview's video explanation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@ngneha090/understanding-the-cap-theorem-balancing-consistency-availability-and-partition-cb11c2b97e2b" rel="noopener noreferrer"&gt;Understanding the CAP Theorem — Neha&lt;/a&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>distributedsystems</category>
      <category>softwareengineering</category>
    </item>
  </channel>
</rss>
