<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Divyanshu on Medium]]></title>
        <description><![CDATA[Stories by Divyanshu on Medium]]></description>
        <link>https://medium.com/@divyanshukr16?source=rss-1f447c73c09c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qEpEDvIJytXsfx42Nl92ww.jpeg</url>
            <title>Stories by Divyanshu on Medium</title>
            <link>https://medium.com/@divyanshukr16?source=rss-1f447c73c09c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 17:35:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@divyanshukr16/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[CAP theorem 2.0 (PACELC Theorem)]]></title>
            <link>https://divyanshukr16.medium.com/cap-theorem-2-0-pacelc-theorem-5a71ee5e52a6?source=rss-1f447c73c09c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a71ee5e52a6</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[cap-theorem]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Divyanshu]]></dc:creator>
            <pubDate>Mon, 26 Feb 2024 06:57:26 GMT</pubDate>
            <atom:updated>2024-02-28T05:12:36.772Z</atom:updated>
            <content:encoded><![CDATA[<p>Most software engineers are well versed in the CAP theorem but I feel some of us have not heard the PACELC Theorem which according to me is an updated version of the CAP theorem.</p><p>In the CAP theorem, we have to choose between consistency or availability when the network failure happens. Let’s say we have 2 nodes of a database and the user updates one record which will be updated for any one node. Since we do have a network partition, node 1 will not be able to send the updated data to node 2. Now if we choose availability, the application will read from both nodes which will hamper our consistency as data is not consistent and if we choose consistency, we need to stop serving from node 2 which will hamper our availability as it will not be100 percent available.</p><p>Now that we know the cap theorem we will think about what choice a distributed system has when there is no network partition. Is it consistent or available or both??? This is missing in the CAP theorem. This is where the PACELC theorem comes into the picture.</p><p>Fun fact: Think about how we have to pronounce PACELC Theorem. Its “pass-elk” (according to official paper) <a href="http://www.cs.umd.edu/~abadi/papers/abadi-pacelc.pdf?ref=hackernoon.com">paper link</a></p><p>Now since you know how to pronounce it, it’s better to know what is this theorem.</p><p>The PACELC theorem states that in a system:</p><ul><li>If there is a partition (‘P’), we have to choose between availability and consistency (i.e., ‘A’ and ‘C’);</li><li>Else (‘E’), when the system is running normally in the absence of partitions, we have to choose between latency (‘L’) and consistency (‘C’).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4NyMPcj-7wy4SLyGn89_bw.png" /></figure><p>Lets dig a bit more deeper. Maybe we find something interesting</p><p>Okay so the first (i.e. PAC) is the same as the CAP just spelled backward. Easy right?</p><p>Now since you know half of this theorem better to know 2nd half as well. So 2nd half says that if there is no partition we have to choose between latency and consistency.</p><p>Let’s focus on ELC (2nd half of the theorem). Let’s say we have 3 nodes of a database. Since there will be no network partition so now we have 3 options.</p><p><strong>Option 1 (Low latency):</strong> When a write request comes up to node 1, it will send the response immediately after writing data into node 1 and eventually node 1 will pass it to node 2 and node 3. In this scenario, we chose low latency because of which we have to settle with eventual consistency.</p><p><strong>Option 2( Strong consistency):</strong> When a write request comes up to node 1, it will send the response after writing data into all the nodes. In this scenario, we chose Strong consistency which leads to high latency.</p><h3><strong>Conclusion</strong></h3><p>The tradeoffs involved in building distributed database systems are very complex, and neither CAP nor PACELC can explain them all. Nonetheless, incorporating the consistency/latency tradeoff into modern DDBS design considerations is important enough to warrant bringing the tradeoff closer to the forefront of architectural discussions</p><p>To learn about this in a fun way try this <a href="https://divyanshukr16.medium.com/navigating-the-jungle-of-distributed-system-cap-vs-pacelc-296500754562">Fun Time</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a71ee5e52a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Navigating the Jungle of Distributed System: CAP vs. PACELC]]></title>
            <link>https://divyanshukr16.medium.com/navigating-the-jungle-of-distributed-system-cap-vs-pacelc-296500754562?source=rss-1f447c73c09c------2</link>
            <guid isPermaLink="false">https://medium.com/p/296500754562</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[cap-theorem]]></category>
            <dc:creator><![CDATA[Divyanshu]]></dc:creator>
            <pubDate>Mon, 26 Feb 2024 06:56:24 GMT</pubDate>
            <atom:updated>2024-02-26T08:44:59.650Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey there, fellow explorer of the digital wilderness! Today, we’re embarking on an adventure into the intriguing world of distributed system. But fear not, we’re equipped with a trusty map called the CAP theorem… and its cooler cousin, the PACELC theorem!</p><p>CAP: Consistency, Availability, Partition Tolerance</p><p>Let’s start with CAP. Picture a big campfire where we’re roasting sweet potatoes(our precious data). Now, imagine our campsite has two tents (nodes) for storing these sweet potatoes. Suddenly, a river (network) divides our camp in two. Uh-oh! We have to decide: Do we ensure that every camper (user) gets the same perfectly roasted sweet potato(consistent data) or do we make sure that everyone gets a sweet potato, even if it’s not perfectly roasted (available data)? It’s a tough choice!</p><p>PACELC: Partition, Availability, Consistency, Else, Latency, Consistency</p><p>Now, let’s enter the realm of PACELC. We’re still in our camp, but the river has dried up (no partition!). Hooray! Now, we face a different challenge: time. We’re surrounded by three tents (nodes), and we must decide how long it takes for everyone to get their sweet potatoes.</p><p>Option 1: Low Latency (Fast Food Drive-Thru) When someone orders a sweet potato at Tent 1, they get it ASAP, even if it’s not perfectly roasted. Tent 2 and Tent 3 might take a bit longer to catch up, but eventually, everyone gets a sweet potatoes. This is like hitting up a fast-food joint — quick but maybe not the best quality sweet potatoes (eventual consistency).</p><p>Option 2: Strong Consistency (Gourmet sweet potatoes Chef) When someone orders a sweet potatoes at Tent 1, they wait patiently until all three tents have perfectly roasted sweet potatoes ready. Sure, it takes longer, but everyone gets the same gourmet experience. This is like waiting for a gourmet chef to whip up a masterpiece — takes time, but oh-so-worth-it (strong consistency).</p><p>In Conclusion…</p><p>Choosing between CAP and PACELC is like navigating through a dense jungle of trade-offs. Neither theorem can perfectly guide us through every twist and turn, but they give us valuable tools to make decisions.</p><p>Remember, the journey of building distributed system is an adventure full of complexities and surprises. So, let’s keep exploring, learning, and maybe toasting a few sweet potatoes along the way!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=296500754562" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is stream better than an iterative approach (e.g. For loop)?]]></title>
            <link>https://medium.com/walmartglobaltech/is-stream-better-than-an-iterative-approach-like-for-loop-624481d8ccae?source=rss-1f447c73c09c------2</link>
            <guid isPermaLink="false">https://medium.com/p/624481d8ccae</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Divyanshu]]></dc:creator>
            <pubDate>Mon, 31 May 2021 09:32:51 GMT</pubDate>
            <atom:updated>2021-10-18T07:11:24.266Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*feg3Ii110jswahXwg18Q-g.jpeg" /><figcaption>Source: <a href="https://www.incimages.com/uploaded_files/image/1920x1080/getty_506903004_200013332000928076_348061.jpg">https://www.incimages.com/uploaded_files/image/1920x1080/getty_506903004_200013332000928076_348061.jpg</a></figcaption></figure><p>In today’s data rich and integrated world, we are often dealing with streams especially if you are a java programmer. However, how many of us(java programmers) know the internal workings of streams or have a point of view on whether- is stream better than a simple <strong>For</strong> loop ?</p><p>If you know these things, then I believe this blog may not be relevant for you. If not, then let’s dig deeper.</p><p>Since I asked you this question so let us start with the internal working of ‘<strong>For each</strong>’ loop.<br><strong><em>for(int x:list)</em></strong><br>This is a sugar-coated line that wrapped up the internal iteration code.</p><pre><em>Iterator&lt;Integer&gt; iterator = list.iterator();<br> while(iterator.hasNext()){<br> Integer x=iterator.next();<br> }</em></pre><p>This is what is happening when we are calling a <strong>For </strong>loop. The logic behind this is that the iterator is created over your application code and for every iteration, it will go to collection and collect whatever it requires and comes back to the application code.<br>It is not possible to process elements of the collection in a parallel way if we are using a For loop. With a For loop, it is not easy to implement something which will do more than one operation on it. E.g., if you want to change the element of a list to upper case, filter something out of it, and then store it in a list, then it’s challenging.</p><pre>List&lt;String&gt; updatedList=new ArrayList&lt;&gt;();<br>for(String value:list){<br>    String valueInUpperCase = value.toUpperCase();<br>    if(isMatching(valueInUpperCase)){<br>        updatedList.add(valueInUpperCase);<br>    }<br>}</pre><p>All these difficulties are there because iteration is done on code, not on collection. Here stream comes with simple logic that iteration will be done over-collection internally, not on application code. In technical terms, this is internal iteration and the one with for loop is an external iteration on application code. This logic will mitigate both issues mentioned above. since the stream is doing iteration internally on the collection, it can quickly be processed parallelly as there is no dependency of one element over another and with streams, we can do more than one operation quite easily.</p><p>For the same example, which was difficult by a single For loop, we can call streams and convert it to uppercase and filter it as required.</p><pre><em>list.stream().map(x -&gt;x.toUpperCase()).filter(ismatching()).collect(Collectors.toList());</em><br> </pre><p>Its much more readable as compared to its For loop implementation.</p><p>With all these points, you might think that we should remove For loop from java and use streams everywhere. However, that is not the case. Streams have their disadvantages as well.</p><blockquote><strong>Performance</strong> -&gt;of course, performance-wise, a simple For loop is better than a stream as streams have quite a bit of overhead.<br> <strong>Readability</strong> -&gt; we are familiar with a simple For loop for long, and streams are not that old when we compare it with For loop. That’s one of the reasons we believe simple For loop is more readable, and to some extent, it is correct. For example, when we are using 2 For loops, one inside another, it is readable. Nevertheless, when we have to do the same thing in streams, you will feel it’s complex. So I believe it all comes down to how much familiar we are with streams.<br> D<strong>ebugging</strong> -&gt; simple For loops is more accessible to debug than streams as legacy debuggers are not equipped with the streams.</blockquote><p>As a conclusion, I feel that both streams or For loop are good in their own ways and we developers need to think about which one to use according to our requirements. We need to be equipped with the associated trade-offs and decide when to use streams and when to go for a For loop.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=624481d8ccae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/walmartglobaltech/is-stream-better-than-an-iterative-approach-like-for-loop-624481d8ccae">Is stream better than an iterative approach (e.g. For loop)?</a> was originally published in <a href="https://medium.com/walmartglobaltech">Walmart Global Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>