<?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: Dhawal Kumar Singh</title>
    <description>The latest articles on DEV Community by Dhawal Kumar Singh (@swehelper).</description>
    <link>https://dev.to/swehelper</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3882759%2F6b6329f8-1201-43de-9463-ab038f7e9655.png</url>
      <title>DEV Community: Dhawal Kumar Singh</title>
      <link>https://dev.to/swehelper</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/swehelper"/>
    <language>en</language>
    <item>
      <title>CAP Theorem — What Every Developer Gets Wrong</title>
      <dc:creator>Dhawal Kumar Singh</dc:creator>
      <pubDate>Sun, 19 Apr 2026 17:41:10 +0000</pubDate>
      <link>https://dev.to/swehelper/cap-theorem-what-every-developer-gets-wrong-21od</link>
      <guid>https://dev.to/swehelper/cap-theorem-what-every-developer-gets-wrong-21od</guid>
      <description>&lt;p&gt;If you've ever been in a system design interview, you've heard: &lt;em&gt;"Explain the CAP theorem."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Most developers say: &lt;em&gt;"You can only pick two out of three — Consistency, Availability, Partition Tolerance."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That's technically correct but misses the real point. Let me explain 👇&lt;/p&gt;

&lt;h2&gt;
  
  
  🔍 The Three Properties
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Consistency (C)&lt;/strong&gt;&lt;br&gt;
Every read receives the most recent write.&lt;/p&gt;

&lt;p&gt;You write &lt;code&gt;balance = $100&lt;/code&gt;. Someone immediately reads → they get &lt;code&gt;$100&lt;/code&gt;. Not &lt;code&gt;$90&lt;/code&gt;. Not stale data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Availability (A)&lt;/strong&gt;&lt;br&gt;
Every request gets a response — even if it's not the latest data.&lt;/p&gt;

&lt;p&gt;The system &lt;strong&gt;never&lt;/strong&gt; says "try later."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Partition Tolerance (P)&lt;/strong&gt;&lt;br&gt;
The system keeps working even when the network connection between nodes breaks.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚨 The Big Misconception
&lt;/h2&gt;

&lt;p&gt;Most people think you're choosing 2 from a menu:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Choice&lt;/th&gt;
&lt;th&gt;What happens&lt;/th&gt;
&lt;th&gt;Practical?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;CA&lt;/td&gt;
&lt;td&gt;Consistent + Available, no partition handling&lt;/td&gt;
&lt;td&gt;❌ Not in distributed systems&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CP&lt;/td&gt;
&lt;td&gt;Consistent, may reject requests during partitions&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AP&lt;/td&gt;
&lt;td&gt;Available, may serve stale data during partitions&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Here's what people get wrong:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You don't "choose" partition tolerance. Network partitions &lt;strong&gt;WILL&lt;/strong&gt; happen — they're not optional.&lt;/p&gt;

&lt;p&gt;So the &lt;strong&gt;real&lt;/strong&gt; choice is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🎯 During a network partition, do you want &lt;strong&gt;Consistency&lt;/strong&gt; or &lt;strong&gt;Availability&lt;/strong&gt;?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's it. That's CAP.&lt;/p&gt;

&lt;h2&gt;
  
  
  🏢 Real-World Examples
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;CP Systems — Choose Consistency&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;System&lt;/th&gt;
&lt;th&gt;Behavior&lt;/th&gt;
&lt;th&gt;Best for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;MongoDB (majority write concern)&lt;/td&gt;
&lt;td&gt;Minority side rejects writes during partition&lt;/td&gt;
&lt;td&gt;Financial data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HBase&lt;/td&gt;
&lt;td&gt;Strong consistency, may become unavailable&lt;/td&gt;
&lt;td&gt;Analytics platforms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Use case: Banking — wrong data is &lt;strong&gt;worse&lt;/strong&gt; than no data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AP Systems — Choose Availability&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;System&lt;/th&gt;
&lt;th&gt;Behavior&lt;/th&gt;
&lt;th&gt;Best for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cassandra&lt;/td&gt;
&lt;td&gt;Always accepts writes, resolves conflicts later (last-write-wins)&lt;/td&gt;
&lt;td&gt;Social feeds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DynamoDB&lt;/td&gt;
&lt;td&gt;Returns data even if slightly stale&lt;/td&gt;
&lt;td&gt;Shopping carts&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Use case: Social media feeds — slightly stale data is totally fine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The "CA" Myth&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Traditional single-node PostgreSQL is consistent AND available — but it's &lt;strong&gt;not distributed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The moment you scale to multiple nodes, you &lt;strong&gt;must&lt;/strong&gt; handle partitions. CA doesn't exist in the real world of distributed systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧠 Beyond CAP: The PACELC Theorem
&lt;/h2&gt;

&lt;p&gt;CAP only describes behavior &lt;strong&gt;during partitions&lt;/strong&gt;. But what about normal operation? That's where PACELC comes in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PACELC says:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If there's a &lt;strong&gt;P&lt;/strong&gt;artition → choose &lt;strong&gt;A&lt;/strong&gt;vailability or &lt;strong&gt;C&lt;/strong&gt;onsistency&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;E&lt;/strong&gt;lse (normal operation) → choose &lt;strong&gt;L&lt;/strong&gt;atency or &lt;strong&gt;C&lt;/strong&gt;onsistency&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;System&lt;/th&gt;
&lt;th&gt;During Partition&lt;/th&gt;
&lt;th&gt;Normal Operation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;DynamoDB (PA/EL)&lt;/td&gt;
&lt;td&gt;Available&lt;/td&gt;
&lt;td&gt;Low Latency&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HBase (PC/EC)&lt;/td&gt;
&lt;td&gt;Consistent&lt;/td&gt;
&lt;td&gt;Consistent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cassandra (PA/EC)&lt;/td&gt;
&lt;td&gt;Available&lt;/td&gt;
&lt;td&gt;Consistent (tunable)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This is honestly &lt;strong&gt;more useful&lt;/strong&gt; than CAP for real-world system design decisions.&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 Interview Tip
&lt;/h2&gt;

&lt;p&gt;When asked about CAP in an interview, &lt;strong&gt;don't just recite the definition&lt;/strong&gt;. Say something like:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Network partitions are inevitable in distributed systems, so the real trade-off is between consistency and availability during partitions. In practice, I'd use PACELC to also consider the latency-consistency trade-off during normal operation.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For example, for a payment system I'd choose a CP system like PostgreSQL with synchronous replication. But for a social media feed, I'd choose an AP system like Cassandra where eventual consistency is acceptable."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That answer shows you &lt;strong&gt;understand&lt;/strong&gt; it, not just memorized it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;CAP isn't really "pick 2 of 3" — it's "pick C or A during a partition"&lt;/li&gt;
&lt;li&gt;PACELC is the practical extension you should actually use&lt;/li&gt;
&lt;li&gt;Real systems often have &lt;strong&gt;tunable&lt;/strong&gt; consistency (Cassandra lets you choose per query)&lt;/li&gt;
&lt;li&gt;In interviews, always explain the &lt;strong&gt;trade-off&lt;/strong&gt;, not just the acronym&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you found this useful, I write about system design and distributed systems regularly. I also maintain 119+ free browser-based dev tools for developers.&lt;/p&gt;

&lt;p&gt;📚 &lt;strong&gt;Full article with more examples:&lt;/strong&gt; &lt;a href="https://swehelper.com/blog/cap-theorem" rel="noopener noreferrer"&gt;swehelper.com/blog/cap-theorem&lt;/a&gt;&lt;br&gt;
🔧 &lt;strong&gt;Free dev tools:&lt;/strong&gt; &lt;a href="https://swehelper.com" rel="noopener noreferrer"&gt;swehelper.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>webdev</category>
      <category>distributedsystems</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
