<?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"><channel><title><![CDATA[SDE Core]]></title><description><![CDATA[SDE Core]]></description><link>https://js-core.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sun, 20 Sep 2026 21:35:03 GMT</lastBuildDate><atom:link href="https://js-core.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[ACID Transactions in DBMS Explained (MongoDB)]]></title><description><![CDATA[If you're building out a full-stack application today maybe wiring up a Node.js backend or pulling server-side data in Next.js - you've probably had to make the database choice. For years, the convent]]></description><link>https://js-core.hashnode.dev/acid-transactions-in-dbms-explained-mongodb</link><guid isPermaLink="true">https://js-core.hashnode.dev/acid-transactions-in-dbms-explained-mongodb</guid><category><![CDATA[DBMS]]></category><category><![CDATA[ACID Transactions]]></category><category><![CDATA[ACID Properties]]></category><dc:creator><![CDATA[Divyanshu]]></dc:creator><pubDate>Thu, 17 Sep 2026 06:53:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/69516d562b3718c1163a85f2/83e0857a-f270-4645-9ef4-438bc9c80542.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you're building out a full-stack application today maybe wiring up a Node.js backend or pulling server-side data in Next.js - you've probably had to make the database choice. For years, the conventional wisdom in the developer community was rigid: <em>Use SQL if you care about your data integrity, use NoSQL if you just want to scale fast and dump JSON into a bucket.</em></p>
<p>But let's be real. That assumption is wildly outdated.</p>
<p>Scaling horizontally doesn't mean you have to sacrifice data integrity. I was recently digging through some architectural docs and realized how many developers still don't know that MongoDB has supported robust, multi-document ACID transactions for years.</p>
<p>Let's break down exactly what ACID means in the real world, how it evolved, and how MongoDB manages to deliver strict data guarantees without losing its NoSQL flexibility.</p>
<p><em>(Note: A lot of the foundational architecture in this post is based on</em> <a href="https://www.mongodb.com/resources/basics/databases/acid-transactions"><em>MongoDB's official guide to ACID transactions</em></a><em>, which is a fantastic resource if you want to go deeper).</em></p>
<hr />
<h2>A Quick History Lesson: Where Did ACID Come From?</h2>
<p>Before we talk about modern document databases, we need to look back at the late 1970s and early 1980s. As businesses started relying on digital records for banking and telecommunications, they needed absolute guarantees that their data wouldn't corrupt if a server crashed mid-operation.</p>
<p>In 1983, computer scientists Andreas Reuter and Theo Härder formally defined the four ACID properties. This framework became the undisputed gold standard for relational database management systems (RDBMS) like Oracle, IBM DB2, and eventually PostgreSQL.</p>
<p>When NoSQL databases rose to popularity in the 2010s to handle massive, unstructured datasets, early versions <em>did</em> relax consistency in favor of raw performance. That created the myth that NoSQL and ACID were mutually exclusive. But as distributed systems evolved, vendors like MongoDB figured out how to engineer multi-document transactions across distributed nodes.</p>
<hr />
<img src="https://cdn.hashnode.com/uploads/covers/69516d562b3718c1163a85f2/033c5acb-447a-4cc7-888e-f320cfab64e0.png" alt="" style="display:block;margin:0 auto" />

<h2>What is ACID, Exactly? (And How MongoDB Handles It)</h2>
<p>ACID stands for <strong>Atomicity, Consistency, Isolation, and Durability</strong>. Together, they ensure that a transaction - a grouped set of read/write operations - leaves your database in a valid state even if everything catches on fire.</p>
<p>Here is how a document database handles the classic RDBMS rules:</p>
<h3>1. Atomicity: The "All or Nothing" Rule</h3>
<p>Atomicity guarantees that if a transaction fails halfway through, the entire thing is rolled back. If a user is paying for a premium subscription in your app, the database needs to debit their account <em>and</em> upgrade their user role. If the role upgrade fails, the money shouldn't be deducted.</p>
<p><strong>The MongoDB Way:</strong> Because MongoDB is a document database, a write operation is atomic <em>at the document level</em>. If you embed arrays and sub-documents directly inside a single user document, updating all that nested data is fully atomic by default. For the rare cases where you absolutely must update multiple separate collections simultaneously, MongoDB supports distributed multi-document transactions across replica sets and sharded clusters.</p>
<h3>2. Consistency: Obeying the Laws of the Schema</h3>
<p>Consistency ensures that any transaction brings the database from one valid state to another, strictly adhering to defined rules and constraints.</p>
<p><strong>The MongoDB Way:</strong> MongoDB gives you flexibility in how you achieve this. If you have related data, you can:</p>
<ul>
<li><p><strong>Use Transactions:</strong> Updates to multiple collections occur in one atomic operation. You get perfect consistency, but it can impact performance if there's heavy read contention.</p>
</li>
<li><p><strong>Embed Related Data:</strong> Just shove the related data into a single document. This is highly performant and keeps everything consistent without complex joins.</p>
</li>
<li><p><strong>Use Atlas Database Triggers:</strong> Update one collection, and let a background trigger update the other. Great for performance, but you have to be okay with <em>eventual consistency</em> (users might see slightly stale data for a few milliseconds).</p>
</li>
</ul>
<h3>3. Isolation: Staying in Your Lane</h3>
<p>Isolation prevents concurrent transactions from interfering with each other. If two users try to book the exact same movie seat at the exact same millisecond, the database shouldn't crash or double-book.</p>
<p><strong>The MongoDB Way:</strong> MongoDB uses a technique called <strong>snapshot isolation</strong>. When a transaction starts, it takes a private, virtual snapshot of the database. The transaction operates on this isolated view. If it tries to commit and the lock manager detects that another operation has modified the same data in the meantime, the transaction is safely aborted to prevent a conflict.</p>
<h3>4. Durability: Written in Stone</h3>
<p>Durability means that once a transaction says "committed," it's permanent. Even if someone trips over the server's power cord a microsecond later, that data will be there when the machine boots back up.</p>
<p><strong>The MongoDB Way:</strong> MongoDB achieves this through a combination of write-ahead logging (the journal) and distributed replica sets. Before a change is finalized, it's written to an on-disk journal. Furthermore, you can configure your write concerns so that a transaction isn't considered "complete" until it has successfully replicated to a majority of your backup nodes.</p>
<hr />
<h2>When Should You Actually Use Distributed Transactions?</h2>
<p>Just because you <em>can</em> use multi-document transactions in MongoDB doesn't mean you always <em>should</em>.</p>
<p>If you are coming from a traditional SQL background (like PostgreSQL or MySQL), your instinct is usually to normalize everything into separate tables and use transactions to tie them together.</p>
<p><strong>In MongoDB, 80% to 90% of your transactional needs can be solved by simply designing a better schema.</strong> Because documents can contain rich, hierarchical data structures, you can often keep related data together.</p>
<p>Reserve multi-document transactions for the edge cases:</p>
<ol>
<li><p><strong>Financial Ledgers:</strong> Transferring balances between two isolated account documents.</p>
</li>
<li><p><strong>Complex Inventory Systems:</strong> Deducting stock from a central inventory collection while simultaneously creating a detailed order in an orders collection.</p>
</li>
<li><p><strong>Strict Regulatory Compliance:</strong> When the law dictates that multi-system data must be perfectly synced with zero tolerance for eventual consistency.</p>
</li>
</ol>
<h2>The Takeaway</h2>
<p>The database landscape isn't black and white anymore. You don't have to choose between the developer-friendly flexibility of document schemas and the iron-clad safety of ACID compliance. If you structure your data correctly, you get atomicity out of the box. And when you need to bring out the big guns for multi-collection transactions, the architecture is already there waiting for you.</p>
<p><em>For a deeper dive into the specific lock mechanisms and performance impacts, check out the</em> <a href="https://www.mongodb.com/resources/basics/databases/acid-transactions"><em>original MongoDB resource on ACID transactions</em></a><em>.</em></p>
]]></content:encoded></item><item><title><![CDATA[JavaScript Promises Explained]]></title><description><![CDATA[If you are diving deep into JavaScript, you know asynchronous code can get seriously tricky. Callbacks inevitably lead straight to callback hell, and async/await feels like pure magic right up until i]]></description><link>https://js-core.hashnode.dev/javascript-promises-explained</link><guid isPermaLink="true">https://js-core.hashnode.dev/javascript-promises-explained</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[ChaiCohort]]></category><category><![CDATA[chaicode webdev cohort 2026]]></category><category><![CDATA[WebDevCohort2026]]></category><category><![CDATA[webdev]]></category><dc:creator><![CDATA[Divyanshu]]></dc:creator><pubDate>Sat, 28 Feb 2026 22:57:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/69516d562b3718c1163a85f2/cf510898-c615-4e5a-a477-af0e0162bba3.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you are diving deep into JavaScript, you know asynchronous code can get seriously tricky. Callbacks inevitably lead straight to callback hell, and <code>async/await</code> feels like pure magic right up until it abruptly breaks.</p>
<p>Enter <strong>Promises</strong>.</p>
<p>Today, we are going to break down Promises using the most painfully relatable Indian contexts.</p>
<hr />
<p>In JavaScript, a <strong>Promise</strong> is an object representing the eventual completion (or failure) of an asynchronous operation and its resulting value.</p>
<h3>Think of it like one of the below...</h3>
<p>🔸 A placeholder for a value that will arrive in the future</p>
<p>🔸 A container for a future value</p>
<p>🔸 A wrapper around an async result</p>
<p>A Promise is always in one of these three states:</p>
<ul>
<li><p>🟡 <strong>Pending:</strong> The initial state. The outcome is unknown.</p>
</li>
<li><p>🟢 <strong>Fulfilled:</strong> The operation completed successfully.</p>
</li>
<li><p>🔴 <strong>Rejected:</strong> The operation failed.</p>
</li>
</ul>
<h2><strong>The Real-Life Definitions</strong></h2>
<p><strong>The "friend" Example:</strong> Imagine your Dost/Friend says: <em>"Bhai kal pakka ₹5000 bhej raha hoon."</em> That is a Promise.</p>
<ul>
<li><p>😅 <strong>Pending</strong> → <em>Kal aayega...</em></p>
</li>
<li><p>👌 <strong>Fulfilled</strong> → ₹5000 received in your bank account!</p>
</li>
<li><p>🏃 <strong>Rejected</strong> → <em>"Broo iss mahine thoda tight hai..."</em></p>
</li>
</ul>
<hr />
<h2><strong>How to Create a New Promise:</strong></h2>
<p>You create a custom Promise using the <code>new Promise()</code> constructor but 95% of real-world work uses <strong>consuming</strong>, not building. It takes one parameter: a <strong>callback function</strong> (often called the executor).</p>
<p>This executor function itself takes two parameters:</p>
<ol>
<li><p><code>resolve</code>: A function you call when your asynchronous task completes successfully.</p>
</li>
<li><p><code>reject</code>: A function you call when your task fails.</p>
</li>
</ol>
<pre><code class="language-javascript">const myPromise = new Promise((resolve, reject) =&gt; {
  let isSuccessful = true; // Setting a condition

  if (isSuccessful) {
    resolve("Yay! It worked!"); // Transitions state to Fulfilled
  } else {
    reject("Oops! Something went wrong."); // Transitions state to Rejected
  }
});
</code></pre>
<hr />
<h2><strong>Handling Promises:</strong></h2>
<p>Once a Promise settles, you need to handle the outcome. Here is how we do it, desi style.</p>
<h3><code>.then()</code> - Handle Success</h3>
<ul>
<li><p>Runs when the Promise is <strong>Fulfilled</strong>.</p>
<ul>
<li>Example: 💝If crush replies → smile automatically.</li>
</ul>
</li>
</ul>
<h3><code>.catch()</code> - Handle Failure</h3>
<ul>
<li><p>Runs when the Promise is <strong>Rejected</strong>.</p>
<ul>
<li>Example: 💔If crush leaves on seen → buy gym membership.</li>
</ul>
</li>
</ul>
<h3><code>.finally()</code> - Always Runs</h3>
<ul>
<li><p>Runs regardless of success or failure. The ultimate truth.</p>
<ul>
<li>Example: 💥Result kuch bhi ho… drama toh hoga.</li>
</ul>
</li>
</ul>
<p><strong>Example:</strong></p>
<pre><code class="language-javascript">const textCrush = new Promise((resolve, reject) =&gt; {
  const crushMood = Math.random() &gt; 0.5;

  setTimeout(() =&gt; {
    if (crushMood) {
      resolve("Crush replied: 'Hey 😊'");
    } else {
      reject("Crush left you on seen 💀");
    }
  }, 1000);
});

textCrush
  .then(message =&gt; {
    console.log(message);
    console.log("💝smiling at phone like idiot / Phas gaya aa 😌");
  })
  .catch(error =&gt; {
    console.log(error);
    console.log("💔Opening gym membership website 🏋️‍♂️");
  })
  .finally(() =&gt; {
    console.log("💥Result kuch bhi ho… drama toh hoga.");
  });

/*
Console Output (after 1 second):

IF RESOLVED:
Crush replied: 'Hey 😊'
💝smiling at phone like idiot / Phas gaya aa 😌
💥Result kuch bhi ho… drama toh hoga.

--------------------------------------------

IF REJECTED:
Crush left you on seen 💀
💔Opening gym membership website 🏋️‍♂️
💥Result kuch bhi ho… drama toh hoga.
*/
</code></pre>
<hr />
<h2><strong>Instant Gratification &amp; Disappointment</strong></h2>
<p>Sometimes you don't need to wait.</p>
<h3><code>Promise.resolve()</code> (Immediate Success)</h3>
<ul>
<li><p><strong>Example:</strong> Mom: <em>"Khane mein kya hai?"</em> Mom herself: <em>"Rajma Chawal bana diya."</em> Instant happiness.</p>
</li>
<li><pre><code class="language-javascript">const checkDinner = Promise.resolve("Rajma Chawal ready 🍛");

checkDinner.then(msg =&gt; console.log("Mood upgraded 😌:", msg));
</code></pre>
</li>
</ul>
<h3><code>Promise.reject()</code> <strong>(Immediate Disappointment)</strong></h3>
<ul>
<li><p><strong>Example:</strong> Asking Friend for Money</p>
</li>
<li><pre><code class="language-javascript">const askFriend = Promise.reject("Bhai khud broke hoon 💸");

askFriend.catch(err =&gt; console.log("Survival mode activated 🫠:", err));
</code></pre>
</li>
</ul>
<hr />
<h2><strong>Advanced Promise Methods: The Multi-Taskers</strong></h2>
<h3><code>Promise.all()</code> - Parallel, Fails Fast</h3>
<ul>
<li><p><em>Rule: All must succeed, or the whole thing fails.</em></p>
</li>
<li><p><strong>Example (Shaadi Plan):</strong> 💃Caterer booked. Band booked. Marriage hall booked. If the pandit cancels → entire wedding is in chaos!</p>
</li>
<li><pre><code class="language-javascript">const caterer = Promise.resolve("Caterer ready 🍛");
const band = Promise.resolve("Band ready 🥁");
const pandit = Promise.reject("Pandit cancelled ❌");

Promise.all([caterer, band, pandit])
  .then(res =&gt; console.log("Shaadi ON 🎉", res))
  .catch(err =&gt; console.log("Shaadi Cancelled 💀:", err));
</code></pre>
</li>
</ul>
<h3><code>Promise.allSettled()</code> - Waits for all, never fails</h3>
<ul>
<li><p><em>Rule: I want the full report. Drama included. I don't care if some failed.</em></p>
</li>
<li><p><strong>Example (Rishta Hunting):</strong> 👰‍♀️Rishta 1 → rejected. Rishta 2 → ghosted. Rishta 3 → interested. You still want the full status report from the matchmaker.</p>
</li>
<li><pre><code class="language-javascript">const rishta1 = Promise.reject("Rejected ❌");
const rishta2 = Promise.reject("Ghosted 👻");
const rishta3 = Promise.resolve("Interested 😊");

Promise.allSettled([rishta1, rishta2, rishta3])
  .then(report =&gt; console.log("Full Rishta Report 📋:", report));
</code></pre>
</li>
</ul>
<h3><code>Promise.race()</code> <strong>- First settled wins (Good or Bad)</strong></h3>
<ul>
<li><p><em>Rule: First to finish wins, whether it's a resolve or reject.</em></p>
</li>
<li><p><strong>Example (Swiggy vs Zomato):</strong> 📦Order from both. Whichever delivers first gets the tip.</p>
</li>
<li><pre><code class="language-javascript">const swiggy = new Promise(res =&gt; setTimeout(() =&gt; res("Swiggy Delivered 🚴"), 2000));
const zomato = new Promise(res =&gt; setTimeout(() =&gt; res("Zomato Delivered 🛵"), 1000));

Promise.race([swiggy, zomato])
  .then(winner =&gt; console.log("Food from:", winner));
</code></pre>
</li>
</ul>
<h2><code>Promise.any()</code> <strong>- First fulfilled wins</strong></h2>
<ul>
<li><p><em>Rule: First success wins. Ignore the failures.</em></p>
</li>
<li><p><strong>Example (Marriage Proposal Attempt):</strong> 😉Ask 3 people out. First "yes" wins. The others? Ignored 😌.</p>
</li>
<li><pre><code class="language-javascript">const crush1 = Promise.reject("No ❌");
const crush2 = Promise.reject("Already committed 💔");
const crush3 = Promise.resolve("Yes 😊");

Promise.any([crush1, crush2, crush3])
  .then(success =&gt; console.log("Success:", success))
  .catch(() =&gt; console.log("All rejected 😭"));
</code></pre>
</li>
</ul>
<hr />
<h2><strong>The TL;DR: Your Desi Cheat Sheet</strong></h2>
<p>Next time you are writing asynchronous JavaScript and start feeling lost, just close your eyes, take a deep breath, and remember these golden rules of Indian life:</p>
<ul>
<li><p><strong>A Promise</strong> is just your Chacha owing you money. It’s <code>Pending</code> until it’s either in your bank (<code>Fulfilled</code>) or he makes a solid excuse (<code>Rejected</code>).</p>
</li>
<li><p><code>.then()</code><strong>,</strong> <code>.catch()</code><strong>, and</strong> <code>.finally()</code> is the ultimate cycle of life: Hoping for the best, dealing with the heartbreak, and still having to eat dinner with your annoying siblings anyway.</p>
</li>
<li><p><code>Promise.all()</code> = The Shaadi Plan. If even one vendor cancels, the whole wedding is ruined.</p>
</li>
<li><p><code>Promise.allSettled()</code> = The Rishta Report. You want all the tea and gossip, whether they said yes, no, or totally ghosted.</p>
</li>
<li><p><code>Promise.race()</code> = Mom vs. Alarm Clock. Whoever triggers first, wins your attention.</p>
</li>
<li><p><code>Promise.any()</code> = Begging for notes at 11:59 PM. The very first person to send the PDF is literally God; the rest are ignored.</p>
</li>
</ul>
<p>Master these mental models, and you will never fear <code>async</code> code or Promises again. Your JavaScript fundamentals will be as solid and guaranteed as a mother's <code>Promise.resolve("Rajma Chawal")</code>.</p>
]]></content:encoded></item></channel></rss>