<?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: Saurav Pandey</title>
    <description>The latest articles on DEV Community by Saurav Pandey (@saurav_tb_pandey).</description>
    <link>https://dev.to/saurav_tb_pandey</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%2F4030684%2F00a97a98-d0c0-454d-9685-afb5d1a78a3f.png</url>
      <title>DEV Community: Saurav Pandey</title>
      <link>https://dev.to/saurav_tb_pandey</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saurav_tb_pandey"/>
    <language>en</language>
    <item>
      <title>Stop Overworking Your Code: A Guide to Debouncing</title>
      <dc:creator>Saurav Pandey</dc:creator>
      <pubDate>Mon, 14 Sep 2026 09:21:17 +0000</pubDate>
      <link>https://dev.to/saurav_tb_pandey/stop-overworking-your-code-a-guide-to-debouncing-4c04</link>
      <guid>https://dev.to/saurav_tb_pandey/stop-overworking-your-code-a-guide-to-debouncing-4c04</guid>
      <description>&lt;h3&gt;
  
  
  What is Debouncing?
&lt;/h3&gt;

&lt;p&gt;Debouncing is a programming practice that ensures a specific task is only executed after a set amount of time has passed since the last time it was triggered. Essentially, it waits for a "pause" in activity before performing an action, preventing a function from running too many times in quick succession.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Elevator Analogy
&lt;/h3&gt;

&lt;p&gt;Imagine you are standing in an elevator in a busy office building. As you step in, the door starts to close. Suddenly, a coworker runs up and taps the "open door" button. The door reopens, resetting the timer. This happens again and again—every time someone arrives, the door's automatic closing process is canceled and restarted. The elevator only actually begins its journey once there has been a lull in arrivals for, say, five seconds. That pause is your debounce window.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why It Matters
&lt;/h3&gt;

&lt;p&gt;In modern web development, users perform actions like typing into a search bar or resizing a browser window. If your application sends a network request to a database every single time a user presses a key, you are going to overwhelm your server and waste bandwidth. By using debouncing, we ensure the search request only triggers once the user has finished typing, making the experience smoother and the infrastructure much more stable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code Example
&lt;/h3&gt;

&lt;p&gt;Here is a simple JavaScript function that "debounces" an input event:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;timer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Usage: Only runs 500ms after the user stops typing&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;search&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fetching results...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Takeaway
&lt;/h3&gt;

&lt;p&gt;Debouncing is less about doing less work and more about doing work at the right time. By strategically choosing when to execute expensive operations, you bridge the gap between user intent and system performance, creating a highly responsive application that doesn't buckle under the weight of constant, redundant events.&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/Saurav-TB-Pandey/react-hook-lab" rel="noopener noreferrer"&gt;react-hook-lab&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-hook-lab:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/react-hook-lab" rel="noopener noreferrer"&gt;npm package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect with me on LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/pandeysaurav/" rel="noopener noreferrer"&gt;Saurav Pandey&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog. You can &lt;a href="https://sauravtbpandey.blogspot.com/2026/09/why-your-search-bar-needs-debouncing-to.html" rel="noopener noreferrer"&gt;read the alternative breakdown here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>debouncing</category>
      <category>performance</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Why Pressing the Button Twice Shouldn't Double Your Bill: Understanding Idempotency</title>
      <dc:creator>Saurav Pandey</dc:creator>
      <pubDate>Sun, 13 Sep 2026 08:32:46 +0000</pubDate>
      <link>https://dev.to/saurav_tb_pandey/why-pressing-the-button-twice-shouldnt-double-your-bill-understanding-idempotency-309j</link>
      <guid>https://dev.to/saurav_tb_pandey/why-pressing-the-button-twice-shouldnt-double-your-bill-understanding-idempotency-309j</guid>
      <description>&lt;p&gt;Have you ever clicked a "Submit Payment" button on an online shop, watched the page freeze, and felt a sudden wave of panic? You wonder: &lt;em&gt;Did it go through? Should I click it again, or will I be charged twice?&lt;/em&gt; The technology that protects you from this exact nightmare is called &lt;strong&gt;idempotency&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In computer science, idempotency is a property of an action or design where repeating the action multiple times produces the exact same result as doing it just once. In other words, if an operation is idempotent, running it a hundred times has no more effect on the system's final state than running it a single time. This concept acts as a vital safety guarantee across modern software architectures, preventing accidental duplicates and keeping data consistent.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Elevator Analogy
&lt;/h3&gt;

&lt;p&gt;To understand how this works in the physical world, consider an elevator call button. When you walk up to an elevator bank and press the "Up" button, the button illuminates, sending a signal to the elevator's controller to dispatch a car to your floor. If you get impatient and press that same button ten more times, the system does not dispatch ten separate elevators, nor does it charge the building's electrical system ten times over. The final state is exactly the same: one elevator is scheduled to stop at your floor. The elevator button is an everyday example of an idempotent interface.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why it Matters in Software Engineering
&lt;/h3&gt;

&lt;p&gt;In the technology sector, engineers rely on idempotency to build resilient systems that can survive unstable network connections. When you buy something online, your web browser communicates with a payment gateway (a secure service that processes credit cards). If your internet connection briefly drops after you press "Buy," your browser might fail to receive the confirmation signal from the payment gateway. Because the browser doesn't know if the transaction succeeded, it is programmed to automatically retry the request.&lt;/p&gt;

&lt;p&gt;Without idempotency, the payment gateway would treat each retry as a brand-new transaction, charging your credit card multiple times for a single order. To prevent this, software developers design API (Application Programming Interface, which is how systems talk to one another) endpoints to be idempotent. They do this by requiring an "idempotency key"—a unique, one-time identifier generated by the client application for that specific transaction. When the server receives a request, it checks its database to see if it has already processed a request with that specific key. If it has, it simply returns the cached response from the first successful attempt instead of running the billing logic again.&lt;/p&gt;

&lt;h3&gt;
  
  
  Idempotency in Code
&lt;/h3&gt;

&lt;p&gt;Here is a simple example in JavaScript demonstrating how this mechanism operates in code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// A simulated database of processed transaction IDs&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;processedTransactions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;processPayment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;idempotencyKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Check if we have already handled this exact request&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;processedTransactions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;idempotencyKey&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;success&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Duplicate request ignored. Returning previous transaction details.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// If it is a new request, process the payment and store the key&lt;/span&gt;
  &lt;span class="nx"&gt;processedTransactions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;idempotencyKey&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Imagine complex credit card processing logic happens here&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;success&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Successfully charged $&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; for new transaction.`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Final Takeaway
&lt;/h3&gt;

&lt;p&gt;Ultimately, idempotency is the silent architecture of reliability in a chaotic digital landscape. It shifts the burden of managing unpredictable internet dropouts away from anxious users and places it squarely on smart system design, ensuring that patience-testing screen freezes never translate into administrative or financial disasters.&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/Saurav-TB-Pandey/react-hook-lab" rel="noopener noreferrer"&gt;react-hook-lab&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-hook-lab:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/react-hook-lab" rel="noopener noreferrer"&gt;npm package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect with me on LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/pandeysaurav/" rel="noopener noreferrer"&gt;Saurav Pandey&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog. You can &lt;a href="https://sauravtbpandey.blogspot.com/2026/09/the-thermostat-rule-guide-to.html" rel="noopener noreferrer"&gt;read the alternative breakdown here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>idempotency</category>
      <category>architecture</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What is Web Hydration? How Static Pages Turn into Interactive Apps</title>
      <dc:creator>Saurav Pandey</dc:creator>
      <pubDate>Sat, 12 Sep 2026 08:07:55 +0000</pubDate>
      <link>https://dev.to/saurav_tb_pandey/what-is-web-hydration-how-static-pages-turn-into-interactive-apps-31bn</link>
      <guid>https://dev.to/saurav_tb_pandey/what-is-web-hydration-how-static-pages-turn-into-interactive-apps-31bn</guid>
      <description>&lt;h1&gt;
  
  
  The Magic of Web Hydration: How Static Pages Come to Life
&lt;/h1&gt;

&lt;p&gt;Imagine clicking a button on a beautifully loaded website, only for absolutely nothing to happen. You click again, harder this time, but the page is frozen. A few seconds later, the page suddenly reacts to all your clicks at once. This frustrating experience is directly tied to a process called &lt;strong&gt;hydration&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In web development, &lt;strong&gt;hydration&lt;/strong&gt; is the process where client-side JavaScript attaches event listeners and dynamic state to static HTML that was previously rendered on a server. It transforms a non-interactive, read-only webpage into a fully functional, dynamic web application. In simple terms, it bridges the gap between seeing a webpage and actually being able to interact with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Showroom Analogy
&lt;/h2&gt;

&lt;p&gt;To understand hydration, imagine visiting a brand-new housing development and stepping into a "model home" showroom. As you walk through the kitchen, everything looks perfect: the stainless-steel refrigerator is in place, the faucet is positioned over the sink, and the digital clock on the microwave is glowing.&lt;/p&gt;

&lt;p&gt;However, if you try to open the fridge, you find it is empty and unplugged. If you turn the faucet handle, no water flows because the pipes are not connected to the main water line. The display home looks completely ready, but it is entirely non-functional.&lt;/p&gt;

&lt;p&gt;For the home to be livable, a team of plumbers and electricians must go behind the walls to connect the pipes, wire the outlets, and turn on the main power. In this analogy, the beautifully designed but non-functional model home is the &lt;strong&gt;server-rendered HTML&lt;/strong&gt; sent to your browser. The plumbing and electrical installation process is &lt;strong&gt;hydration&lt;/strong&gt;, and the final, fully functioning home is the interactive &lt;strong&gt;web application&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Hydration Matters in Modern Web Development
&lt;/h2&gt;

&lt;p&gt;In the early days of the web, servers sent simple HTML pages, and browsers just displayed them. If you clicked a link, the server sent a whole new page. Today, we use complex JavaScript frameworks like React, Vue, and Angular to build highly interactive, single-page apps.&lt;/p&gt;

&lt;p&gt;However, loading massive JavaScript files can take time, leaving users staring at a blank screen. To solve this, developers use Server-Side Rendering (SSR). The server pre-builds the page into static HTML so the user sees text and images instantly.&lt;/p&gt;

&lt;p&gt;But there is a catch: that fast-loading HTML is just a picture. It has no brain. This is where hydration becomes critical. Engineers must optimize the hydration process to prevent the "uncanny valley" of web design—where a page &lt;em&gt;looks&lt;/em&gt; ready but refuses to respond to taps or clicks. If hydration takes too long on a slow mobile device, it tanks performance metrics like &lt;strong&gt;Interaction to Next Paint (INP)&lt;/strong&gt;, frustrating users and hurting search engine rankings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hydration in Action: A Simple Code Example
&lt;/h2&gt;

&lt;p&gt;Here is a simplified demonstration of how hydration works under the hood. Imagine the server sent this static HTML button to the browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Delivered by the server as static HTML --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"interactive-button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Likes: 0&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this stage, the button is visible, but clicking it does nothing. Here is the JavaScript "hydration" script that runs on the client side to make it work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The client-side script that "hydrates" the static HTML&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;hydrateApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// 1. Locate the existing static element in the DOM (Document Object Model)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;likeButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;interactive-button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;likeButton&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;likeCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// 2. Attach the "plumbing" (the event listener) to make it interactive&lt;/span&gt;
    &lt;span class="nx"&gt;likeButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;likeCount&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;likeButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`Likes: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;likeCount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;likeButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;backgroundColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#0070f3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hydration complete: Button is now fully functional!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Run the hydration script once the browser has loaded the page structure&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DOMContentLoaded&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;hydrateApp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Takeaway
&lt;/h2&gt;

&lt;p&gt;Hydration is the crucial bridge that allows modern websites to be both incredibly fast to display and highly responsive to use. By sending static layouts first and breathing life into them with JavaScript second, developers avoid forcing users to wait on blank screens, provided they manage the hydration budget carefully to keep the experience seamless.&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/Saurav-TB-Pandey/react-hook-lab" rel="noopener noreferrer"&gt;react-hook-lab&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-hook-lab:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/react-hook-lab" rel="noopener noreferrer"&gt;npm package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect with me on LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/pandeysaurav/" rel="noopener noreferrer"&gt;Saurav Pandey&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog. You can &lt;a href="https://sauravtbpandey.blogspot.com/2026/09/web-hydration-explained-breathing-life.html" rel="noopener noreferrer"&gt;read the alternative breakdown here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>hydration</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>Demystifying Content Delivery Networks (CDNs): Speeding Up the Web for Everyone</title>
      <dc:creator>Saurav Pandey</dc:creator>
      <pubDate>Fri, 11 Sep 2026 08:18:30 +0000</pubDate>
      <link>https://dev.to/saurav_tb_pandey/demystifying-content-delivery-networks-cdns-speeding-up-the-web-for-everyone-3afm</link>
      <guid>https://dev.to/saurav_tb_pandey/demystifying-content-delivery-networks-cdns-speeding-up-the-web-for-everyone-3afm</guid>
      <description>&lt;h2&gt;
  
  
  What is a Content Delivery Network?
&lt;/h2&gt;

&lt;p&gt;A Content Delivery Network (CDN) is a globally distributed group of servers strategically positioned to deliver internet content quickly and securely. By storing duplicate copies of a website's static assets—such as images, video files, stylesheets, and JavaScript scripts—on servers located closer to end-users, it minimizes the physical distance data must travel. This specialized infrastructure acts as an intermediate courier network, handling user requests locally so the central website server does not get overwhelmed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Warehouse Analogy
&lt;/h2&gt;

&lt;p&gt;Imagine a massive, world-famous board game manufacturer headquartered in Seattle, Washington. If they had only one factory and warehouse in Seattle, every single customer worldwide would have to wait weeks for their game to ship across oceans and continents. Shipping costs would be astronomical, and shipping routes would easily clog up during the holidays, resulting in delayed deliveries. &lt;/p&gt;

&lt;p&gt;To solve this, the manufacturer ships bulk containers of their games to local distribution warehouses in London, Tokyo, Frankfurt, and Sydney before the holiday rush. When a customer in Tokyo orders a game, it is shipped from the Tokyo warehouse, arriving at their doorstep the next afternoon. If a customer asks for a rare, custom game not stocked locally (which we call a 'cache miss'), the Tokyo warehouse requests it from Seattle, delivers it to the customer, and then keeps an extra copy on shelves for any future local orders (a 'cache hit'). In this scenario, the Seattle factory is the main website server, the regional warehouses are CDN servers, and the board games are the website files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why It Matters in Tech
&lt;/h2&gt;

&lt;p&gt;In modern web development, engineers leverage CDNs to solve severe performance bottlenecks and prevent catastrophic system downtime. When a website goes viral, millions of concurrent users requesting files simultaneously from a single origin server will crash it. By delegating static asset delivery to a CDN, developers ensure that over 80% of the traffic never reaches their primary databases, drastically reducing bandwidth hosting costs. &lt;/p&gt;

&lt;p&gt;Furthermore, CDNs protect sites from Distributed Denial of Service (DDoS) attacks—where malicious actors try to flood a website with fake traffic—by absorbing and distributing these massive traffic spikes across thousands of regional nodes. They also optimize user engagement: study after study shows that even a one-second delay in page load time directly translates to lost revenue, lower search engine rankings, and higher user abandonment.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Simple Code Simulation
&lt;/h2&gt;

&lt;p&gt;Below is a simple JavaScript class that demonstrates how a CDN edge server checks its local cache before requesting a file from a slow, central origin server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CDNCacheNode&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;originServer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;originServer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;originServer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;getAsset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;assetPath&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Check if the asset is already cached at the edge node (Cache Hit)&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;assetPath&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[Edge Node] HIT: Serving cached version of &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;assetPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;assetPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Asset not found locally (Cache Miss) - fetch from the central origin server&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[Edge Node] MISS: Fetching &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;assetPath&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; from central origin server...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;assetData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;originServer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchFromSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;assetPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Save a copy in the local edge cache for future requests&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;assetPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;assetData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;assetData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Mocking the central origin database/server&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;centralOrigin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;fetchFromSource&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Data for &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; (Generated at central origin)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Usage demonstration&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;localLondonNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CDNCacheNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;centralOrigin&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Takeaway
&lt;/h2&gt;

&lt;p&gt;Implementing a CDN is no longer a luxury for high-traffic enterprises; it is a fundamental pillar of modern web architecture that democratizes speed. By shifting the delivery load away from a single centralized server to an intelligent, distributed global network, developers can build fast, resilient, and highly available applications that feel instantaneous to users anywhere on the globe.&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/Saurav-TB-Pandey/react-hook-lab" rel="noopener noreferrer"&gt;react-hook-lab&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-hook-lab:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/react-hook-lab" rel="noopener noreferrer"&gt;npm package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect with me on LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/pandeysaurav/" rel="noopener noreferrer"&gt;Saurav Pandey&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog. You can &lt;a href="https://sauravtbpandey.blogspot.com/2026/09/how-content-delivery-networks-cdns-make.html" rel="noopener noreferrer"&gt;read the alternative breakdown here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>cdn</category>
      <category>webdev</category>
      <category>networking</category>
      <category>performance</category>
    </item>
    <item>
      <title>Smooth Scrolling and Fast Interfaces: A Plain-English Guide to Throttling</title>
      <dc:creator>Saurav Pandey</dc:creator>
      <pubDate>Thu, 10 Sep 2026 08:26:12 +0000</pubDate>
      <link>https://dev.to/saurav_tb_pandey/smooth-scrolling-and-fast-interfaces-a-plain-english-guide-to-throttling-3iie</link>
      <guid>https://dev.to/saurav_tb_pandey/smooth-scrolling-and-fast-interfaces-a-plain-english-guide-to-throttling-3iie</guid>
      <description>&lt;h2&gt;
  
  
  What is Throttling?
&lt;/h2&gt;

&lt;p&gt;Throttling is a technique used in programming to limit how often a specific function can run over a given period of time. Instead of letting an action trigger repeatedly and continuously, throttling enforces a maximum execution rate, ensuring the action only runs at set intervals (such as once every 200 milliseconds). This prevents system overloads and keeps applications running smoothly even when user actions are incredibly rapid.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Real-Life Analogy: The Buffet Chocolate Fountain
&lt;/h2&gt;

&lt;p&gt;Imagine you are at an all-you-can-eat buffet with a single, highly popular chocolate fountain. If every guest rushed up to dip a strawberry the split-second they felt like it, the area would become an absolute bottleneck of colliding plates and spilled chocolate. To manage the chaos, the buffet staff sets up a simple rule: a timer rings once every 30 seconds, and only when that bell chimes can the next person step up to use the fountain. No matter how many hungry guests line up or wave their plates in the meantime, the fountain is strictly accessed at that steady, pre-set interval.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Throttling Matters in Software Engineering
&lt;/h2&gt;

&lt;p&gt;In the digital world, certain user actions happen incredibly fast—such as scrolling down a long web page, typing rapidly in a search bar, or dragging an element across the screen. Each tiny pixel of movement triggers a browser event. If an application tries to recalculate page layouts, fetch new data, or redraw complex animations for every single pixel of a fast scroll, the browser will freeze, stutter, or crash. Software engineers use throttling to force these heavy calculations to run at a predictable, manageable pace (like 5 times a second instead of 150 times a second), protecting the user's device from overheating and ensuring a fluid, glitch-free user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Throttling in Action: JavaScript Example
&lt;/h2&gt;

&lt;p&gt;Below is a standard JavaScript implementation of throttling that uses a locking variable (a boolean flag) to control execution flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;throttle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;inThrottle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;inThrottle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;func&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;inThrottle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;inThrottle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Example: Limit scroll event logs to once every 500ms&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logScroll&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Page scrolled!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;throttledScroll&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;throttle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logScroll&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scroll&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;throttledScroll&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Key Takeaway
&lt;/h2&gt;

&lt;p&gt;Throttling is all about introducing intentional, controlled pacing to chaotic environments. By placing a reasonable speed limit on how fast programs react to rapid changes, developers can build interfaces that feel light, responsive, and robust, proving that sometimes the best way to move faster is to force things to slow down.&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/Saurav-TB-Pandey/react-hook-lab" rel="noopener noreferrer"&gt;react-hook-lab&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-hook-lab:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/react-hook-lab" rel="noopener noreferrer"&gt;npm package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect with me on LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/pandeysaurav/" rel="noopener noreferrer"&gt;Saurav Pandey&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog. You can &lt;a href="https://sauravtbpandey.blogspot.com/2026/09/why-your-apps-dont-crash-under-pressure.html" rel="noopener noreferrer"&gt;read the alternative breakdown here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>throttling</category>
      <category>javascript</category>
      <category>performance</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Demystifying Closures: JavaScript's Built-In Memory Backpacker</title>
      <dc:creator>Saurav Pandey</dc:creator>
      <pubDate>Wed, 09 Sep 2026 08:23:03 +0000</pubDate>
      <link>https://dev.to/saurav_tb_pandey/demystifying-closures-javascripts-built-in-memory-backpacker-h33</link>
      <guid>https://dev.to/saurav_tb_pandey/demystifying-closures-javascripts-built-in-memory-backpacker-h33</guid>
      <description>&lt;p&gt;Have you ever wondered how software remembers your preferences even after a process seems to have finished? In the world of programming, this magic is often performed by a core concept known as a &lt;strong&gt;closure&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Closure?
&lt;/h3&gt;

&lt;p&gt;A closure is a fundamental programming feature where an inner function retains access to the variables of its outer function, even after that outer function has finished executing. It acts as a persistent link between a function and the environment in which it was born. This prevents the outer variables from being cleared out of your computer's active memory.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Backpack Analogy
&lt;/h3&gt;

&lt;p&gt;To understand how this works, imagine you are planning a long hike. Before you walk out the front door of your house (which represents the &lt;strong&gt;outer function&lt;/strong&gt;), you pack a few essential items into your backpack (representing the &lt;strong&gt;variables&lt;/strong&gt;)—a water bottle, a compass, and some trail mix.&lt;/p&gt;

&lt;p&gt;Once you step outside, the door locks behind you. The house is closed, and you can no longer go back inside. However, as you walk down the trail (representing the &lt;strong&gt;inner function&lt;/strong&gt;), you still have complete access to the water bottle, compass, and trail mix. You do not need to reopen the house to use them because they are sealed in your backpack.&lt;/p&gt;

&lt;p&gt;In this analogy, the backpack is the closure. It is a portable envelope of data that the hiker (the inner function) carries along, regardless of where they travel or how much time has passed since they left home.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Closures Matter in Daily Software Engineering
&lt;/h3&gt;

&lt;p&gt;For software engineers, closures are not just an academic curiosity; they are a vital tool used daily to write safe, maintainable code.&lt;/p&gt;

&lt;p&gt;One of the biggest challenges in building large applications is avoiding "global namespace pollution." If every piece of data in an application is accessible to every function, it is highly likely that one function will accidentally overwrite data being used by another. This leads to unpredictable bugs.&lt;/p&gt;

&lt;p&gt;Engineers use closures to create &lt;strong&gt;private variables&lt;/strong&gt;. By nesting a function inside another, we can shield variables from the outside world. This is called encapsulation. It allows developers to build robust tools and software libraries where internal settings are protected from being modified by external scripts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Seeing Closures in Action
&lt;/h3&gt;

&lt;p&gt;Let's look at a simple JavaScript example that demonstrates how a closure keeps a variable alive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;createCounter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// This variable is protected inside the outer function&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// This inner function is returned, creating a closure&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// myCounter now holds the inner function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCounter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createCounter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;myCounter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Output: 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;myCounter&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Output: 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, when we run &lt;code&gt;createCounter()&lt;/code&gt;, it sets &lt;code&gt;count&lt;/code&gt; to &lt;code&gt;0&lt;/code&gt; and returns the inner function. Once it returns, the &lt;code&gt;createCounter&lt;/code&gt; function has finished executing. Normally, its internal variables would be deleted from memory. However, because the inner function still references &lt;code&gt;count&lt;/code&gt;, JavaScript creates a closure. Every time we call &lt;code&gt;myCounter()&lt;/code&gt;, it still has access to that private &lt;code&gt;count&lt;/code&gt; variable, updating it seamlessly.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Takeaway
&lt;/h3&gt;

&lt;p&gt;Closures are not a complex design pattern you need to manually install; they are a natural, built-in feature of how modern programming languages manage memory. By understanding that functions carry their original environment with them, you can write cleaner, self-contained code that keeps your data secure.&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/Saurav-TB-Pandey/react-hook-lab" rel="noopener noreferrer"&gt;react-hook-lab&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-hook-lab:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/react-hook-lab" rel="noopener noreferrer"&gt;npm package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect with me on LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/pandeysaurav/" rel="noopener noreferrer"&gt;Saurav Pandey&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog. You can &lt;a href="https://sauravtbpandey.blogspot.com/2026/09/locking-in-state-why-javascript.html" rel="noopener noreferrer"&gt;read the alternative breakdown here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>closures</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Demystifying ACID Transactions: How Databases Prevent Chaos and Keep Your Data Safe</title>
      <dc:creator>Saurav Pandey</dc:creator>
      <pubDate>Tue, 08 Sep 2026 08:20:04 +0000</pubDate>
      <link>https://dev.to/saurav_tb_pandey/demystifying-acid-transactions-how-databases-prevent-chaos-and-keep-your-data-safe-4840</link>
      <guid>https://dev.to/saurav_tb_pandey/demystifying-acid-transactions-how-databases-prevent-chaos-and-keep-your-data-safe-4840</guid>
      <description>&lt;p&gt;If you have ever used an online app to transfer money, buy a concert ticket, or update your profile, you have relied on a database. Behind the scenes, databases must process millions of instructions without making mistakes, even if the power suddenly cuts out or the server crashes. To guarantee this level of safety, databases rely on a concept called an ACID transaction, which is a set of four rules designed to keep your data perfectly accurate, clean, and trustworthy.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Analogy: The Vending Machine
&lt;/h3&gt;

&lt;p&gt;To understand how an ACID transaction works, imagine buying a bag of chips from a vending machine. This simple action relies on several rules to make sure nobody gets cheated:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Atomicity (All-or-Nothing):&lt;/strong&gt; You enter your money and press the button. Either you get your chips and the machine keeps your money, or the machine jams, returns your cash, and keeps the chips. You will never experience a state where the machine keeps your money but does not give you the chips.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Consistency (Rule Following):&lt;/strong&gt; The machine must always balance its books. If a bag of chips costs two dollars, the machine's internal tally must show exactly two dollars more in cash and one fewer bag of chips in inventory. It cannot end up with a random, unexplainable state.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Isolation (Privacy):&lt;/strong&gt; If two people press buttons on the vending machine at the exact same moment, the machine processes one transaction first, finishes it completely, and then processes the second. The two orders do not get mixed up, and you do not end up getting each other's snacks.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Durability (Permanence):&lt;/strong&gt; Once your chips drop into the retrieval slot, they are yours. If the power outlet is pulled from the wall a millisecond later, the chips do not magically fly back up into the machine. The physical transfer is permanent.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why It Matters in Tech
&lt;/h3&gt;

&lt;p&gt;Without ACID transactions, software development would be an absolute nightmare. Imagine writing code for a banking system without these guarantees. If a customer transfers fifty dollars from Account A to Account B, the system must perform two database updates: subtract fifty from Account A, and add fifty to Account B.&lt;/p&gt;

&lt;p&gt;If the server crashes exactly halfway through this process, fifty dollars could simply vanish into thin air. Engineers use ACID transactions to bundle these two updates into a single, bulletproof package. If any part of the process fails, the database automatically rolls back to the beginning, behaving as if the transfer never started, protecting the user's money and the business's reputation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Seeing It in Action
&lt;/h3&gt;

&lt;p&gt;Here is a simple example in JavaScript using a hypothetical database library. It shows how we bundle multiple database operations into a single, safe transaction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;transferMoney&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;senderId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;receiverId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// 1. Start the transaction block&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;BEGIN TRANSACTION&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// 2. Subtract the amount from the sender&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;UPDATE accounts SET balance = balance - $1 WHERE id = $2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;senderId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// 3. Add the amount to the receiver&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;UPDATE accounts SET balance = balance + $1 WHERE id = $2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;receiverId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// 4. If both succeeded, lock in the changes permanently&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;COMMIT&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Transfer completed successfully!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// 5. If ANY error occurred, cancel and reverse all changes&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ROLLBACK&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Transfer failed. System rolled back to safety:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Takeaway
&lt;/h3&gt;

&lt;p&gt;ACID transactions are the unsung heroes of software reliability, transforming chaotic and unpredictable environments into predictable, safe spaces. By ensuring that database operations either succeed completely or fail harmlessly without a trace, they give developers the confidence to build robust systems that users can trust with their most sensitive financial, personal, and operational data.&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/Saurav-TB-Pandey/react-hook-lab" rel="noopener noreferrer"&gt;react-hook-lab&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-hook-lab:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/react-hook-lab" rel="noopener noreferrer"&gt;npm package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect with me on LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/pandeysaurav/" rel="noopener noreferrer"&gt;Saurav Pandey&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog. You can &lt;a href="https://sauravtbpandey.blogspot.com/2026/09/the-guardian-of-data-integrity-why-your.html" rel="noopener noreferrer"&gt;read the alternative breakdown here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>acidtransactions</category>
      <category>database</category>
      <category>backend</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Demystifying CORS: The Browser Gatekeeper You Love to Hate</title>
      <dc:creator>Saurav Pandey</dc:creator>
      <pubDate>Mon, 07 Sep 2026 08:38:04 +0000</pubDate>
      <link>https://dev.to/saurav_tb_pandey/demystifying-cors-the-browser-gatekeeper-you-love-to-hate-m22</link>
      <guid>https://dev.to/saurav_tb_pandey/demystifying-cors-the-browser-gatekeeper-you-love-to-hate-m22</guid>
      <description>&lt;p&gt;Cross-Origin Resource Sharing (CORS) is a vital browser security mechanism that regulates how a website running in a user's browser is allowed to interact with servers located on entirely different domains. By default, web browsers strictly enforce a rule known as the Same-Origin Policy, which prevents scripts on one site from reading data from another. CORS serves as the official protocol that allows servers to safely opt out of this restriction by sending specific security headers, thereby authorizing trusted external websites to read their data.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Bank Teller and the Authorization Sheet
&lt;/h3&gt;

&lt;p&gt;To understand how CORS works, imagine you walk up to a bank teller window (representing the target server). You are a courier representing a local retail store (the requesting website) attempting to retrieve a sensitive financial report. Even if you know the account number and have standard credentials, the bank teller will not hand the document directly to you right away.&lt;/p&gt;

&lt;p&gt;Instead, the teller consults an internal authorization sheet associated with that bank account. The teller looks for the name of your specific retail store on that list. If your store's name is written on the document, the teller happily hands you the report. If your store is not listed, the teller politely but firmly refuses to hand over the file, shielding the account owner's private financial data from an unauthorized courier.&lt;/p&gt;

&lt;p&gt;In this analogy, your web browser is the strict bank teller. The website you are visiting is the courier, and the API holding the data is the bank account. The browser automatically checks the server's authorization sheet (CORS headers) before letting the website read the incoming data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why CORS Matters on a Daily Basis
&lt;/h3&gt;

&lt;p&gt;For modern software engineers, CORS is both a critical security shield and a frequent source of debugging headaches. Today's web architectures rarely rely on a single, isolated server. A standard setup often separates the frontend user interface (hosted on &lt;code&gt;https://myfrontend.app&lt;/code&gt;) from the backend data API (hosted on &lt;code&gt;https://api.mybackend.com&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Because these two systems live on different domains, the browser treats them as complete strangers. If you try to fetch user profiles from the API, the browser will block the response by default, throwing a notorious red console error: "No Access-Control-Allow-Origin header is present on the requested resource."&lt;/p&gt;

&lt;p&gt;Engineers must configure CORS correctly to prevent this breakdown. If they misconfigure it by using a wildcard symbol (&lt;code&gt;*&lt;/code&gt;) to allow &lt;em&gt;any&lt;/em&gt; website access to sensitive user data, they expose their systems to dangerous data-theft exploits. Developers must actively balance accessibility with strict security boundaries every time they connect a frontend application to an external data source.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuring CORS: A Practical Code Example
&lt;/h3&gt;

&lt;p&gt;To resolve CORS errors, engineers configure the backend server to explicitly state which origins are permitted to access its resources. Here is how a developer would configure this security policy using JavaScript and Express.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cors&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Define a list of allowed websites (origins)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;allowedOrigins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://myfrontend.app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://trustedpartner.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;corsOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Check if the requesting website is in our allowed list&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;origin&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;allowedOrigins&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Access granted!&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Blocked by security protocol (CORS)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Access denied!&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Apply the CORS security settings to our web server&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;corsOptions&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This data is secure and successfully shared!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Final Takeaway
&lt;/h3&gt;

&lt;p&gt;At its core, CORS is not a broken feature or an arbitrary annoyance; it is a fundamental guardrail built directly into our browsers to keep the web safe. By understanding CORS, developers can construct robust, multi-server applications that share data seamlessly with trusted partners while keeping malicious websites locked firmly on the outside.&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/Saurav-TB-Pandey/react-hook-lab" rel="noopener noreferrer"&gt;react-hook-lab&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-hook-lab:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/react-hook-lab" rel="noopener noreferrer"&gt;npm package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect with me on LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/pandeysaurav/" rel="noopener noreferrer"&gt;Saurav Pandey&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog. You can &lt;a href="https://sauravtbpandey.blogspot.com/2026/09/understanding-cors-how-web-browsers.html" rel="noopener noreferrer"&gt;read the alternative breakdown here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>cors</category>
      <category>security</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Stop Loading Everything at Once: An Introduction to Lazy Loading</title>
      <dc:creator>Saurav Pandey</dc:creator>
      <pubDate>Sun, 06 Sep 2026 08:08:42 +0000</pubDate>
      <link>https://dev.to/saurav_tb_pandey/stop-loading-everything-at-once-an-introduction-to-lazy-loading-14dl</link>
      <guid>https://dev.to/saurav_tb_pandey/stop-loading-everything-at-once-an-introduction-to-lazy-loading-14dl</guid>
      <description>&lt;p&gt;Imagine opening a webpage and having to wait for every single image, video, and script to download before you can read a single line of text. Lazy loading is a web development design pattern that solves this problem by delaying the download of non-essential resources until the exact moment they are actually needed. Instead of fetching the entire content of a page upfront, the browser only loads what is immediately visible to the user, loading the rest dynamically as the user scrolls.&lt;/p&gt;

&lt;p&gt;To understand how this works, imagine you are moving into a new house. You have one hundred cardboard boxes packed with your belongings. If you were to unpack all one hundred boxes in your living room the very first hour you arrive, your house would be an unusable, chaotic mess. You would also be completely exhausted before you could even sit down and relax.&lt;/p&gt;

&lt;p&gt;Instead, you practice a form of "lazy unpacking." You only unpack the box labeled "bedding" on the first night so you can sleep comfortably. The next morning, you unpack the "coffee maker" and "mugs" box. You leave the boxes of winter coats and holiday decorations sealed in the garage, only opening them months later when they are actually required. By deferring the effort of unpacking until each item is needed, you save valuable time, space, and energy during your first day in the new home. Lazy loading does the exact same thing with the data on a website.&lt;/p&gt;

&lt;p&gt;In modern software engineering, lazy loading is crucial for optimizing performance and user experience. When a webpage contains dozens of high-resolution images or heavy video files, loading them all at once can choke a user's internet connection, especially on mobile networks. &lt;/p&gt;

&lt;p&gt;Engineers use lazy loading to prevent high "bounce rates"—a term for when frustrated users leave a slow-loading site before it even finishes rendering. By loading only the "above-the-fold" content (the parts of the page visible on the screen without scrolling), the site becomes interactive almost instantly. Furthermore, this technique saves significant money. Mobile users do not waste expensive cellular data downloading images they never scroll down to see, and companies reduce their server bandwidth consumption, lowering their hosting bills.&lt;/p&gt;

&lt;p&gt;Implementing lazy loading used to require complex custom scripts, but modern web browsers now support it natively with a single HTML attribute. Here is how simple it is to lazy load an image today, followed by a lightweight JavaScript fallback for advanced control:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- The modern, native HTML way --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"high-res-photo.jpg"&lt;/span&gt; &lt;span class="na"&gt;loading=&lt;/span&gt;&lt;span class="s"&gt;"lazy"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"A beautiful landscape"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"800"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"600"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For custom behavior, engineers use JavaScript to detect when an element enters the screen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Using the browser's built-in Intersection Observer to load images on demand&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;imagesToLoad&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;img[data-src]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;imageObserver&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entry&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isIntersecting&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;image&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="c1"&gt;// Swap the placeholder with the real image URL&lt;/span&gt;
      &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="c1"&gt;// Stop watching this image once it has loaded&lt;/span&gt;
      &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unobserve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;imagesToLoad&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;imageObserver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The true value of lazy loading lies in its shift from a "just-in-case" delivery model to a "just-in-time" philosophy. It proves that software efficiency isn't always about making computers process data faster; sometimes, it is simply about teaching them to work smarter by doing absolutely nothing until they are forced to.&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/Saurav-TB-Pandey/react-hook-lab" rel="noopener noreferrer"&gt;react-hook-lab&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-hook-lab:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/react-hook-lab" rel="noopener noreferrer"&gt;npm package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect with me on LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/pandeysaurav/" rel="noopener noreferrer"&gt;Saurav Pandey&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog. You can &lt;a href="https://sauravtbpandey.blogspot.com/2026/09/the-smart-strategy-of-lazy-loading.html" rel="noopener noreferrer"&gt;read the alternative breakdown here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>lazyloading</category>
      <category>webdev</category>
      <category>performance</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Why Your Server Needs a Speed Limit: The Power of Rate Limiting</title>
      <dc:creator>Saurav Pandey</dc:creator>
      <pubDate>Sat, 05 Sep 2026 07:52:26 +0000</pubDate>
      <link>https://dev.to/saurav_tb_pandey/why-your-server-needs-a-speed-limit-the-power-of-rate-limiting-4gcp</link>
      <guid>https://dev.to/saurav_tb_pandey/why-your-server-needs-a-speed-limit-the-power-of-rate-limiting-4gcp</guid>
      <description>&lt;p&gt;Rate limiting is a critical architectural pattern that controls how often a user or a computer program can send requests to a server. Think of a request as any action that requires a server to do work, such as loading a webpage, submitting a login form, or searching a database. By setting a strict cap on the frequency of these incoming actions, the system guarantees that it can allocate its computer power fairly and remain operational for everyone. Without this vital boundary, a sudden flood of traffic can easily overwhelm a server, bringing down the entire application.&lt;/p&gt;

&lt;p&gt;To understand this concept, imagine walking into a busy local bank to speak with a teller. If fifty people burst through the front door simultaneously and shouted their transaction requests at the exact same teller, the system would collapse into chaos. No one would get served, the teller would be completely overwhelmed, and the bank might have to lock its doors. To prevent this, banks use a ticket dispenser at the front entrance. You pull a ticket, wait your turn, and the teller serves people one by one at a manageable, steady pace. Rate limiting does exactly this for web applications: it acts as a digital ticket dispenser that ensures clients wait their turn if they try to ask for too much, too fast.&lt;/p&gt;

&lt;p&gt;In the professional software industry, rate limiting is a vital shield that engineers use daily to protect servers from crashing. First, it blocks Distributed Denial of Service (DDoS) attacks, where malicious actors deploy thousands of automated bots to flood a website with fake traffic to force it offline. Second, it thwarts brute-force hacking attempts, where automated scripts try to guess a user’s password by trying thousands of combinations every single second. Third, it prevents "API hogging," which happens when a customer's poorly written, looping code accidentally floods your systems with redundant requests. By stopping these threats at the front gate, rate limiting saves companies thousands of dollars in unnecessary server fees and keeps systems fast for legitimate human visitors.&lt;/p&gt;

&lt;p&gt;Here is a simple JavaScript demonstration of a rate limiter using a sliding time window. It tracks requests using an IP address (the unique identifier for a device on the internet) and blocks them if they exceed the maximum allowance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// A simple database to track request timestamps per IP address&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;requestLog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;LIMIT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Maximum allowed requests&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;WINDOW_MS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Time window: 10 seconds&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;isRateLimited&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ipAddress&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;requestLog&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ipAddress&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;requestLog&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ipAddress&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Filter out timestamps older than our 10-second window&lt;/span&gt;
  &lt;span class="nx"&gt;requestLog&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ipAddress&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;requestLog&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ipAddress&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;timestamp&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;timestamp&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;WINDOW_MS&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// If the user has made more requests than allowed, block them&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;requestLog&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ipAddress&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;LIMIT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Rate limit exceeded! Block request.&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Otherwise, log the current request time and allow it&lt;/span&gt;
  &lt;span class="nx"&gt;requestLog&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ipAddress&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Request allowed!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Simulation&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isRateLimited&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;192.168.1.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// false (Allowed)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isRateLimited&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;192.168.1.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// false (Allowed)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isRateLimited&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;192.168.1.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// false (Allowed)&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isRateLimited&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;192.168.1.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// true (Blocked! Limit exceeded)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At its core, rate limiting is about preserving balance and equity in a shared digital environment. Instead of spending immense amounts of money building massive infrastructure to handle rare, chaotic spikes in automated traffic, software developers use rate limiting to manage flow intelligently. It establishes healthy boundaries, proving that sometimes the best way to keep a digital service fast, secure, and reliable is simply to teach it how to say, "Please slow down."&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/Saurav-TB-Pandey/react-hook-lab" rel="noopener noreferrer"&gt;react-hook-lab&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-hook-lab:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/react-hook-lab" rel="noopener noreferrer"&gt;npm package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect with me on LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/pandeysaurav/" rel="noopener noreferrer"&gt;Saurav Pandey&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog. You can &lt;a href="https://sauravtbpandey.blogspot.com/2026/09/traffic-control-for-web-introduction-to.html" rel="noopener noreferrer"&gt;read the alternative breakdown here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ratelimiting</category>
      <category>security</category>
      <category>webdev</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Don't Let Your Microservices Burn: Understanding the Circuit Breaker Pattern</title>
      <dc:creator>Saurav Pandey</dc:creator>
      <pubDate>Fri, 04 Sep 2026 08:20:08 +0000</pubDate>
      <link>https://dev.to/saurav_tb_pandey/dont-let-your-microservices-burn-understanding-the-circuit-breaker-pattern-f1d</link>
      <guid>https://dev.to/saurav_tb_pandey/dont-let-your-microservices-burn-understanding-the-circuit-breaker-pattern-f1d</guid>
      <description>&lt;p&gt;In modern software engineering, building a reliable system isn't just about preventing errors; it is about managing them gracefully when they occur. The &lt;strong&gt;Circuit Breaker Pattern&lt;/strong&gt; is a design pattern used in software development to prevent an application from repeatedly trying to execute an operation that is highly likely to fail. Instead of wasting resources on doomed requests, the system temporarily blocks them, allowing the failing service time to recover. Once the service is healthy again, the block is lifted and normal operations resume.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Real-World Analogy: The Household Breaker
&lt;/h3&gt;

&lt;p&gt;Think of a household electrical circuit breaker. If a faulty microwave draws too much current, the circuit breaker trips, instantly shutting off electricity to that part of the house. This prevents the wires from overheating and catching fire. Instead of continuously feeding dangerous levels of electricity into a broken appliance, the breaker pauses the flow. It stays open until you unplug the bad appliance and reset the switch.&lt;/p&gt;

&lt;p&gt;In software, the concept is identical. When a third-party API or server becomes slow or non-responsive, our virtual circuit breaker trips. It stops sending traffic to that broken service, saving the rest of our application from catching fire and crashing due to backlogged requests.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why It Matters in Tech
&lt;/h3&gt;

&lt;p&gt;In modern cloud architectures, systems constantly communicate with each other. If a database or a payment gateway goes down, and your application keeps hammering it with thousands of requests per second, you will exhaust your own server's memory and database connection pools. This causes a "cascading failure" where your entire platform goes offline because of one minor, non-critical dependency.&lt;/p&gt;

&lt;p&gt;Engineers use circuit breakers to "fail fast." Instead of letting a user wait 30 seconds for a timeout, the circuit breaker immediately throws an error or returns cached data. This protects downstream systems from being crushed while they are struggling, and keeps your primary application fast and responsive for other tasks.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Pattern in Action
&lt;/h3&gt;

&lt;p&gt;Here is a simple JavaScript implementation of a state-based circuit breaker. It wraps an API call and tracks failures:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CircuitBreaker&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;requestFunction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;failureThreshold&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;recoveryTime&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;requestFunction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;failureThreshold&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;failureThreshold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;recoveryTime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;recoveryTime&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;CLOSED&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// CLOSED, OPEN, HALF-OPEN&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;failures&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nextAttempt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;OPEN&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nextAttempt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;HALF-OPEN&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Circuit is OPEN. Request blocked.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;recordFailure&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;CLOSED&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;failures&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;recordFailure&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;failures&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;failures&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;failureThreshold&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;HALF-OPEN&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;OPEN&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nextAttempt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;recoveryTime&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, the breaker starts as &lt;code&gt;CLOSED&lt;/code&gt; (operational). If the nested request fails too many times, the state flips to &lt;code&gt;OPEN&lt;/code&gt;, blocking further attempts immediately. After the recovery time passes, it allows a single test request (&lt;code&gt;HALF-OPEN&lt;/code&gt;) to see if the dependency is back online. If it succeeds, the breaker resets to &lt;code&gt;CLOSED&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Takeaway
&lt;/h3&gt;

&lt;p&gt;The Circuit Breaker Pattern shifts our engineering mindset from trying to prevent all failures to gracefully managing them when they inevitably happen. By isolating broken parts of a system, you ensure that a single slow API call doesn't drag down your entire product, keeping your user experience stable even during partial outages.&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/Saurav-TB-Pandey/react-hook-lab" rel="noopener noreferrer"&gt;react-hook-lab&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-hook-lab:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/react-hook-lab" rel="noopener noreferrer"&gt;npm package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect with me on LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/pandeysaurav/" rel="noopener noreferrer"&gt;Saurav Pandey&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog. You can &lt;a href="https://sauravtbpandey.blogspot.com/2026/09/building-resilient-software-beginners.html" rel="noopener noreferrer"&gt;read the alternative breakdown here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>circuitbreaker</category>
      <category>devops</category>
      <category>microservices</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to Scale Your App: An Easy Guide to Database Sharding</title>
      <dc:creator>Saurav Pandey</dc:creator>
      <pubDate>Thu, 03 Sep 2026 08:17:32 +0000</pubDate>
      <link>https://dev.to/saurav_tb_pandey/how-to-scale-your-app-an-easy-guide-to-database-sharding-30ei</link>
      <guid>https://dev.to/saurav_tb_pandey/how-to-scale-your-app-an-easy-guide-to-database-sharding-30ei</guid>
      <description>&lt;p&gt;&lt;strong&gt;Database sharding&lt;/strong&gt; is a database architecture technique that splits a single, massive database into smaller, faster, and more easily managed pieces called shards. Instead of keeping all of your data on one giant computer, you distribute it across several separate machines. This ensures that as your user base grows, your system can still retrieve and save information without slowing to a painful crawl.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Filing Cabinet Analogy
&lt;/h3&gt;

&lt;p&gt;Imagine you run a busy medical clinic with a single, massive filing cabinet containing 100,000 patient records. Every time a doctor or nurse needs a file, they have to walk over to this one cabinet, wait in line behind other coworkers, search through thousands of folders, and eventually find the right one. The office quickly becomes a chaotic bottleneck because everyone is competing for the same physical drawer.&lt;/p&gt;

&lt;p&gt;To solve this, you decide to split the single filing cabinet into four smaller, independent cabinets: Cabinet A-F, Cabinet G-L, Cabinet M-R, and Cabinet S-Z. You place these cabinets in different corners of the office, each with its own dedicated administrative assistant. Now, if a nurse needs a file for "Bob Anderson," they walk straight to the A-F cabinet. The workload is split across four separate stations, the wait lines disappear, and patients are served four times faster.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Sharding Matters Daily in Tech
&lt;/h3&gt;

&lt;p&gt;In the tech industry, database sharding is a vital strategy for scaling applications that serve millions of active users, such as social networks, ride-sharing platforms, or financial institutions. When a database gets too big, a single machine runs out of memory (RAM) and processing power, leading to sluggish search queries or complete system outages. &lt;/p&gt;

&lt;p&gt;Engineers use database sharding to prevent these catastrophic database failures. Instead of buying an incredibly expensive, enterprise-grade supercomputer to hold a massive database (which has hard physical limits), companies can link together dozens of cheaper, standard servers to share the database load. This "horizontal scaling" allows systems to handle massive surges in user activity—like a viral tweet or a Black Friday shopping rush—without breaking a sweat.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mapping Data with a Sharding Router
&lt;/h3&gt;

&lt;p&gt;To make sharding work, the application needs a "router" function that determines which database server holds a specific user's information. A common way to do this is using a hash-based routing system, demonstrated in the JavaScript example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// A list of our independent database shard servers&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;databaseShards&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;us_east_shard&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;us_west_shard&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;eu_central_shard&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getShardForUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A valid username is required to route queries.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Convert the username into a numerical hash value based on character codes&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;hashValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;hashValue&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charCodeAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Use the modulo operator to map the hash value to one of our shards&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;shardIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;hashValue&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nx"&gt;databaseShards&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;databaseShards&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;shardIndex&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Example usage routing different users to their respective shards&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;alice_green&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bob_builder&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Routing &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user1&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; to database: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;getShardForUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Routing &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;user2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; to database: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;getShardForUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user2&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Core Takeaway
&lt;/h3&gt;

&lt;p&gt;Database sharding shifts the focus of software infrastructure from upgrading to a larger engine to building an organized fleet of vehicles. While it introduces additional complexity in how applications route and combine queries, it is the ultimate scaling tool that enables global apps to remain blazing fast, ensuring that a physical hardware limitation on one server never brings down an entire business.&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/Saurav-TB-Pandey/react-hook-lab" rel="noopener noreferrer"&gt;react-hook-lab&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;react-hook-lab:&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/react-hook-lab" rel="noopener noreferrer"&gt;npm package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connect with me on LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/pandeysaurav/" rel="noopener noreferrer"&gt;Saurav Pandey&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on my blog. You can &lt;a href="https://sauravtbpandey.blogspot.com/2026/09/breaking-bottleneck-demystifying.html" rel="noopener noreferrer"&gt;read the alternative breakdown here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>databasesharding</category>
      <category>backend</category>
      <category>scalability</category>
      <category>database</category>
    </item>
  </channel>
</rss>
