<?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: Digvijay Bhakuni</title>
    <description>The latest articles on DEV Community by Digvijay Bhakuni (@digvijay-bhakuni).</description>
    <link>https://dev.to/digvijay-bhakuni</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2419738%2F1d7ee45b-12f1-4263-90dd-02b88870786e.png</url>
      <title>DEV Community: Digvijay Bhakuni</title>
      <link>https://dev.to/digvijay-bhakuni</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/digvijay-bhakuni"/>
    <language>en</language>
    <item>
      <title>🧠 Understanding State Management in Web Applications</title>
      <dc:creator>Digvijay Bhakuni</dc:creator>
      <pubDate>Mon, 06 Oct 2025 09:59:16 +0000</pubDate>
      <link>https://dev.to/digvijay-bhakuni/understanding-state-management-in-web-applications-2gcl</link>
      <guid>https://dev.to/digvijay-bhakuni/understanding-state-management-in-web-applications-2gcl</guid>
      <description>&lt;h3&gt;
  
  
  From Cookies to Redux — A Complete Beginner’s Guide
&lt;/h3&gt;




&lt;h2&gt;
  
  
  🌍 Introduction
&lt;/h2&gt;

&lt;p&gt;When you open your favorite website, add items to a shopping cart, or log into an app — have you ever wondered &lt;strong&gt;how the website “remembers” you&lt;/strong&gt; even when you refresh or come back later?&lt;/p&gt;

&lt;p&gt;This “memory” is made possible by something called &lt;strong&gt;State Management&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this post, we’ll break down what &lt;em&gt;state&lt;/em&gt; means, why it’s hard to manage on the web, and explore &lt;strong&gt;all the ways developers handle it&lt;/strong&gt; — from simple cookies to advanced frontend libraries like Redux and Context API.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔄 What Is “State”?
&lt;/h2&gt;

&lt;p&gt;In simple terms, &lt;strong&gt;state&lt;/strong&gt; means the &lt;strong&gt;current data or situation&lt;/strong&gt; of your app at a given moment.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In a shopping app: items in your cart&lt;/li&gt;
&lt;li&gt;In a login system: which user is logged in&lt;/li&gt;
&lt;li&gt;In a to-do app: list of your tasks&lt;/li&gt;
&lt;li&gt;In a music app: which song is playing and at what time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whenever something changes (you add a new task, change a setting, or log out), the &lt;strong&gt;state&lt;/strong&gt; of your app changes too.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Why State Management Is Needed
&lt;/h2&gt;

&lt;p&gt;The web runs on &lt;strong&gt;HTTP&lt;/strong&gt;, which is a &lt;strong&gt;stateless protocol&lt;/strong&gt; — meaning:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Each request is independent, and the server doesn’t automatically remember what happened before.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you log into a website, and then open another page, the server doesn’t know it’s still &lt;em&gt;you&lt;/em&gt; — unless it’s managing your &lt;strong&gt;state&lt;/strong&gt; somehow.&lt;/p&gt;

&lt;p&gt;That’s why web developers use &lt;strong&gt;state management&lt;/strong&gt; techniques: to keep track of users, data, and app behavior &lt;strong&gt;across multiple requests, pages, and sessions.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🧩 Types of State in Web Apps
&lt;/h2&gt;

&lt;p&gt;There are generally &lt;strong&gt;two main categories&lt;/strong&gt; of state:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Client-side State&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Data stored and managed in the browser&lt;/td&gt;
&lt;td&gt;UI theme (dark/light), cart items, input fields&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Server-side State&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Data stored and managed on the server&lt;/td&gt;
&lt;td&gt;Logged-in user info, database records, session data&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Let’s go through all the common techniques used for both.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Part 1: Client-Side State Management
&lt;/h2&gt;

&lt;p&gt;Client-side state is all about what happens &lt;strong&gt;in the browser&lt;/strong&gt;.&lt;br&gt;
It’s fast, doesn’t require a network call, and is great for UI-related information.&lt;/p&gt;
&lt;h3&gt;
  
  
  1️⃣ &lt;strong&gt;JavaScript Variables / In-Memory State&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Simplest form — you store values in variables or React state hooks.&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;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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;increase&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="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="nx"&gt;count&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;✅ Pros:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fast and easy&lt;/li&gt;
&lt;li&gt;Great for temporary UI interactions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;❌ Cons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lost on refresh or page reload&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Used In: React, Vue, Angular component states.&lt;/p&gt;




&lt;h3&gt;
  
  
  2️⃣ &lt;strong&gt;Browser Storage&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  a) &lt;strong&gt;Local Storage&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Stores data &lt;strong&gt;permanently&lt;/strong&gt; in the browser, until manually deleted.&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="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;theme&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;dark&lt;/span&gt;&lt;span class="dl"&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;theme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;theme&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Persists even after closing the tab or browser&lt;br&gt;
❌ Accessible only by frontend JavaScript (no security layer)&lt;/p&gt;

&lt;p&gt;Good for: saving themes, preferences, small data.&lt;/p&gt;


&lt;h4&gt;
  
  
  b) &lt;strong&gt;Session Storage&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Similar to local storage, but cleared when the tab closes.&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="nx"&gt;sessionStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cart&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Isolated to one tab/session&lt;br&gt;
❌ Disappears after closing the tab&lt;/p&gt;

&lt;p&gt;Good for: temporary data like in-progress forms or checkout steps.&lt;/p&gt;


&lt;h4&gt;
  
  
  c) &lt;strong&gt;Cookies&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Small pieces of data stored in the browser, &lt;strong&gt;sent automatically&lt;/strong&gt; with every HTTP request.&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;username=John; expires=Fri, 31 Dec 2025 23:59:59 GMT&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Server can read cookies automatically&lt;br&gt;
✅ Can persist across sessions&lt;br&gt;
❌ Limited storage (~4KB), and needs security precautions&lt;/p&gt;

&lt;p&gt;Good for: sessions, authentication tokens, small preferences.&lt;/p&gt;


&lt;h3&gt;
  
  
  3️⃣ &lt;strong&gt;Frontend State Libraries&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Modern web apps are interactive and complex.&lt;br&gt;
That’s why frameworks like &lt;strong&gt;React&lt;/strong&gt;, &lt;strong&gt;Vue&lt;/strong&gt;, and &lt;strong&gt;Angular&lt;/strong&gt; introduced &lt;strong&gt;state management libraries&lt;/strong&gt; to handle component-level and app-wide state efficiently.&lt;/p&gt;
&lt;h4&gt;
  
  
  🌀 React Context API
&lt;/h4&gt;

&lt;p&gt;Used to share state across multiple components without passing props down manually.&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;ThemeContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Easy for small–medium apps&lt;br&gt;
❌ Can become messy for very large applications&lt;/p&gt;


&lt;h4&gt;
  
  
  ⚙️ Redux
&lt;/h4&gt;

&lt;p&gt;A &lt;strong&gt;centralized store&lt;/strong&gt; that holds the entire app state in one place.&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="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ADD_TODO&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Buy milk&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Predictable and debuggable&lt;br&gt;
✅ Works well in large apps&lt;br&gt;
❌ Slightly complex setup&lt;/p&gt;

&lt;p&gt;Used In: React, Angular, and even Flutter (through Redux-like libraries).&lt;/p&gt;


&lt;h4&gt;
  
  
  📦 Zustand, MobX, Pinia (Vue), NgRx (Angular)
&lt;/h4&gt;

&lt;p&gt;Modern alternatives for simpler or more reactive state management.&lt;/p&gt;

&lt;p&gt;✅ Less boilerplate&lt;br&gt;
✅ Easier learning curve&lt;br&gt;
❌ Often limited to the ecosystem they’re built for&lt;/p&gt;


&lt;h2&gt;
  
  
  🖥️ Part 2: Server-Side State Management
&lt;/h2&gt;

&lt;p&gt;Server-side state keeps track of &lt;strong&gt;who you are&lt;/strong&gt; and &lt;strong&gt;what you’re doing&lt;/strong&gt; on the server — essential for authentication, user sessions, and data persistence.&lt;/p&gt;


&lt;h3&gt;
  
  
  1️⃣ &lt;strong&gt;Sessions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When you log in:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Server creates a &lt;strong&gt;session object&lt;/strong&gt; and stores it in memory or a database.&lt;/li&gt;
&lt;li&gt;Server gives the browser a &lt;strong&gt;Session ID&lt;/strong&gt; (usually in a cookie).&lt;/li&gt;
&lt;li&gt;Each time the browser makes a request, it sends the session ID back.&lt;/li&gt;
&lt;li&gt;Server checks the session ID and retrieves your user data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example:&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="nb"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;Cookie&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;sessionId&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;abc123&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;HttpOnly&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Secure (data is stored server-side)&lt;br&gt;
❌ Can consume memory if many users are online&lt;/p&gt;

&lt;p&gt;Used In: Express.js, Django, Spring Boot (via session management).&lt;/p&gt;


&lt;h3&gt;
  
  
  2️⃣ &lt;strong&gt;JWT (JSON Web Tokens)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;JWTs are &lt;strong&gt;stateless tokens&lt;/strong&gt; that carry user information securely between client and server.&lt;/p&gt;

&lt;p&gt;When you log in:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Server creates a token:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"john"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"admin"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Server signs it with a secret key and sends it to the client.&lt;/li&gt;
&lt;li&gt;Client stores it (in cookies or localStorage).&lt;/li&gt;
&lt;li&gt;Each request includes the token in headers:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   Authorization: Bearer &amp;lt;token&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Server verifies the token — no session storage needed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;✅ Fast and scalable&lt;br&gt;
✅ Works well for APIs and mobile apps&lt;br&gt;
❌ Must handle token expiry and security carefully&lt;/p&gt;


&lt;h3&gt;
  
  
  3️⃣ &lt;strong&gt;Database State&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;All permanent data — user info, settings, orders — lives in a &lt;strong&gt;database&lt;/strong&gt;.&lt;br&gt;
State changes here are the most persistent form (they survive any restart or reload).&lt;/p&gt;


&lt;h2&gt;
  
  
  🧭 Putting It All Together
&lt;/h2&gt;

&lt;p&gt;Most real-world apps use &lt;strong&gt;a mix of all these techniques&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Frontend:&lt;/strong&gt; React manages UI state, Context stores theme mode.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser:&lt;/strong&gt; JWT stored in &lt;code&gt;localStorage&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server:&lt;/strong&gt; Uses JWT verification + database state for user data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Flow Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Login → Server creates JWT → Browser stores JWT
→ Every API request includes JWT → Server verifies → Returns data
→ React updates UI state → Local storage remembers preferences
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🚀 Best Practices
&lt;/h2&gt;

&lt;p&gt;✅ Use &lt;strong&gt;HTTP-only cookies&lt;/strong&gt; for storing tokens securely.&lt;br&gt;
✅ Don’t overuse global state — local state is simpler and faster.&lt;br&gt;
✅ Keep sensitive data on the &lt;strong&gt;server&lt;/strong&gt;, not in browser storage.&lt;br&gt;
✅ Use &lt;strong&gt;Redux or Context API&lt;/strong&gt; only when multiple components need the same data.&lt;br&gt;
✅ Clear session or localStorage on logout.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Summary Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Where Stored&lt;/th&gt;
&lt;th&gt;Lifespan&lt;/th&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;In-memory variables&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Browser RAM&lt;/td&gt;
&lt;td&gt;Until refresh&lt;/td&gt;
&lt;td&gt;Temporary UI logic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Local Storage&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Browser&lt;/td&gt;
&lt;td&gt;Persistent&lt;/td&gt;
&lt;td&gt;Preferences, tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Session Storage&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Browser&lt;/td&gt;
&lt;td&gt;Until tab close&lt;/td&gt;
&lt;td&gt;Temporary data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cookies&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Browser/Server&lt;/td&gt;
&lt;td&gt;Configurable&lt;/td&gt;
&lt;td&gt;Auth sessions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Sessions&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Server&lt;/td&gt;
&lt;td&gt;Until logout&lt;/td&gt;
&lt;td&gt;Login systems&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;JWT&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Client &amp;amp; Server&lt;/td&gt;
&lt;td&gt;Token expiry&lt;/td&gt;
&lt;td&gt;Stateless auth&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Redux / Context / MobX&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Browser memory&lt;/td&gt;
&lt;td&gt;Until refresh&lt;/td&gt;
&lt;td&gt;UI + app-wide state&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🧩 Conclusion
&lt;/h2&gt;

&lt;p&gt;State management is what makes your web app &lt;em&gt;feel alive&lt;/em&gt;.&lt;br&gt;
It keeps your experience smooth and personal — even across reloads, tabs, and devices.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Frontend&lt;/strong&gt; handles UI state (React, Redux, etc.).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backend&lt;/strong&gt; ensures security and persistence (Sessions, JWT, Databases).&lt;/li&gt;
&lt;li&gt;Together, they create a seamless, stateful web experience on top of the stateless web.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;“Without state management, every page refresh would be like meeting your app for the first time.”&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>html</category>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>🌐 Understanding the Client–Server Model, HTTP, and State Management in Web Apps</title>
      <dc:creator>Digvijay Bhakuni</dc:creator>
      <pubDate>Mon, 06 Oct 2025 09:55:42 +0000</pubDate>
      <link>https://dev.to/digvijay-bhakuni/understanding-the-client-server-model-http-and-state-management-in-web-apps-3ogj</link>
      <guid>https://dev.to/digvijay-bhakuni/understanding-the-client-server-model-http-and-state-management-in-web-apps-3ogj</guid>
      <description>&lt;h2&gt;
  
  
  🧠 1. What is the Client–Server Model?
&lt;/h2&gt;

&lt;p&gt;The Client–Server Model is a simple way computers communicate over the internet.&lt;/p&gt;

&lt;p&gt;Think of it like a restaurant:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;What It Does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Client&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;You (the customer)&lt;/td&gt;
&lt;td&gt;Sends requests (“I’d like a pizza”)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Server&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The kitchen&lt;/td&gt;
&lt;td&gt;Prepares and sends back what you asked for (“Here’s your pizza”)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In web apps, this communication happens using HTTP (Hypertext Transfer Protocol).&lt;br&gt;
HTTP is the “language” both the client and server use to talk.&lt;/p&gt;
&lt;h2&gt;
  
  
  🔗 2. What is HTTP?
&lt;/h2&gt;

&lt;p&gt;HTTP defines how messages are sent and received between a client (like Chrome, Firefox, or a mobile app) and a server (like Google’s or Amazon’s computers).&lt;/p&gt;

&lt;p&gt;Every website visit is an exchange of requests and responses:&lt;/p&gt;

&lt;p&gt;Client (Browser) → sends a Request (e.g., “Show me the homepage”).&lt;/p&gt;

&lt;p&gt;Server → sends a Response (e.g., “Here’s the homepage HTML file”).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client → GET /index.html HTTP/1.1
Server → HTTP/1.1 200 OK
          &amp;lt;html&amp;gt;Welcome!&amp;lt;/html&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ⚙️ 3. How Web Apps Work (Step by Step)
&lt;/h2&gt;

&lt;p&gt;Let’s walk through what happens when you open &lt;a href="https://www.example.com:" rel="noopener noreferrer"&gt;https://www.example.com:&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🖥️ Step 1: The Client Sends a Request
&lt;/h3&gt;

&lt;p&gt;Your browser sends a GET request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /index.html HTTP/1.1
Host: www.example.com

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🗄️ Step 2: The Server Processes the Request
&lt;/h3&gt;

&lt;p&gt;A web server (like Apache, Nginx, or Node.js) receives it and prepares a response — either by:&lt;/p&gt;

&lt;p&gt;Returning a file (like index.html)&lt;/p&gt;

&lt;p&gt;Or asking a backend app (e.g., built in Spring Boot, Django, or Express.js) to generate it dynamically.&lt;/p&gt;

&lt;h3&gt;
  
  
  📨 Step 3: The Server Sends a Response
&lt;/h3&gt;

&lt;p&gt;The server replies with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 200 OK
Content-Type: text/html

&amp;lt;html&amp;gt;&amp;lt;h1&amp;gt;Welcome!&amp;lt;/h1&amp;gt;&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🌐 Step 4: The Browser Displays the Page
&lt;/h3&gt;

&lt;p&gt;Your browser reads the HTML, then fetches more resources (CSS, JavaScript, images).&lt;br&gt;
All of this happens through multiple HTTP requests and responses.&lt;/p&gt;
&lt;h2&gt;
  
  
  🧩 4. Example: A Simple To-Do List Web App
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Client (Frontend)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;React web app&lt;/td&gt;
&lt;td&gt;Displays the to-do list and handles user actions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Server (Backend)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Spring Boot REST API&lt;/td&gt;
&lt;td&gt;Stores and retrieves tasks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Database&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;PostgreSQL&lt;/td&gt;
&lt;td&gt;Saves the actual task data&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Example Flow
&lt;/h3&gt;

&lt;p&gt;You click “Add Task”.&lt;/p&gt;

&lt;p&gt;Browser sends:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST /api/tasks
Content-Type: application/json

{ "task": "Buy milk" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Server saves the task and responds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 201 Created
{ "id": 1, "task": "Buy milk", "done": false }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Browser updates the visible list instantly — now you see “Buy milk”.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧠 5. What is State?
&lt;/h2&gt;

&lt;p&gt;In web development, state means the current data or condition of your app — what the user is seeing or interacting with at a given moment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples of State:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which user is logged in&lt;/li&gt;
&lt;li&gt;What items are in your shopping cart&lt;/li&gt;
&lt;li&gt;Whether dark mode is on or off&lt;/li&gt;
&lt;li&gt;The list of tasks currently displayed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each time you refresh the page, move to a new one, or log out, your state may change or reset — unless it’s managed carefully.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔄 6. State Management in Web Apps
&lt;/h2&gt;

&lt;p&gt;Because HTTP is stateless (it forgets everything after each request), web apps must manage state themselves.&lt;/p&gt;

&lt;h3&gt;
  
  
  💬 “Stateless” means:
&lt;/h3&gt;

&lt;p&gt;Each HTTP request is independent.&lt;br&gt;
The server doesn’t automatically remember you between requests.&lt;/p&gt;

&lt;p&gt;So web apps use state management techniques to keep track of users, preferences, and data.&lt;/p&gt;
&lt;h3&gt;
  
  
  ⚙️ Ways to Manage State
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Where Stored&lt;/th&gt;
&lt;th&gt;Used For&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cookies&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Browser&lt;/td&gt;
&lt;td&gt;Small user data, like login sessions&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Set-Cookie: sessionId=abc123&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Sessions&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Server&lt;/td&gt;
&lt;td&gt;Server stores user info; browser keeps a session ID&lt;/td&gt;
&lt;td&gt;Used for login systems&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Local Storage / Session Storage&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Browser&lt;/td&gt;
&lt;td&gt;Frontend-only state (preferences, temporary data)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;localStorage.setItem("theme", "dark")&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;JWT (JSON Web Token)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Browser &amp;amp; Server&lt;/td&gt;
&lt;td&gt;Securely keeps user identity between requests&lt;/td&gt;
&lt;td&gt;Used in modern APIs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Frontend State Management Libraries&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Browser memory&lt;/td&gt;
&lt;td&gt;Handles app-level UI data&lt;/td&gt;
&lt;td&gt;React’s Context, Redux, or Flutter’s Provider&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  🧭 Example: Login with State
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;You log into a website.
→ Browser sends username and password via POST.&lt;/li&gt;
&lt;li&gt;Server verifies them and creates a session or JWT token.&lt;/li&gt;
&lt;li&gt;Server sends this token to the browser.
→ Browser saves it in cookies or localStorage.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Next time you visit a protected page, your browser includes the token in the request header:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   Authorization: Bearer &amp;lt;token&amp;gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Server checks the token, confirms your identity, and serves your personalized content.&lt;/p&gt;&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;This way, your “logged-in” state is maintained even though HTTP itself is stateless.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧩 7. Visualization of the Full Cycle
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ Browser (Client) ]
      ↓  HTTP Request (GET /tasks)
[ Web Server (Backend) ]
      ↓  Reads database, prepares response
      ↑  HTTP Response (JSON Data)
[ Browser Updates UI ]
      ↓
State Updated (New task shown)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  📖 8. Summary
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Client&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The user’s device/browser that requests data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Server&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The program that processes requests and sends back data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;HTTP&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The communication language between client and server&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Stateless Protocol&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;HTTP doesn’t remember previous interactions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;State&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The current condition/data of the web app&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;State Management&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The methods used to maintain continuity between HTTP requests&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  💡 In Simple Terms
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The client asks, the server answers.&lt;/li&gt;
&lt;li&gt;HTTP is their shared language.&lt;/li&gt;
&lt;li&gt;Because HTTP forgets, we use state management (cookies, sessions, tokens, local storage, etc.) to make web apps feel continuous — like you’re always “logged in” or “in the same place.”&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>http</category>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Probabilistic Data Structures: How Bloom Filters Enhance Performance in Large Datasets</title>
      <dc:creator>Digvijay Bhakuni</dc:creator>
      <pubDate>Mon, 27 Jan 2025 16:20:21 +0000</pubDate>
      <link>https://dev.to/digvijay-bhakuni/probabilistic-data-structures-how-bloom-filters-enhance-performance-in-large-datasets-40e0</link>
      <guid>https://dev.to/digvijay-bhakuni/probabilistic-data-structures-how-bloom-filters-enhance-performance-in-large-datasets-40e0</guid>
      <description>&lt;h3&gt;
  
  
  What is a Bloom Filter and How Does It Work?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Bloom Filter&lt;/strong&gt; is a highly efficient, probabilistic data structure used to test whether an element is a member of a set. It is widely used in scenarios where the exactness of membership is not a strict requirement, but speed and space efficiency are important.&lt;/p&gt;

&lt;p&gt;Bloom Filters are particularly useful when we want to test whether an element is &lt;strong&gt;definitely not&lt;/strong&gt; in a set, or &lt;strong&gt;possibly&lt;/strong&gt; in a set, but without the need to store the entire set of elements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Properties of a Bloom Filter:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Space Efficient:&lt;/strong&gt; It uses a fixed amount of memory, regardless of the number of elements being inserted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;False Positive Rate:&lt;/strong&gt; Bloom Filters may occasionally indicate that an element is in the set when it’s not (a "false positive"), but they will never give a false negative.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Deletion:&lt;/strong&gt; Standard Bloom Filters don’t support deleting elements from the set once they’ve been added.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Probabilistic:&lt;/strong&gt; It trades off a small probability of false positives for better space and time efficiency.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How Does a Bloom Filter Work?
&lt;/h3&gt;

&lt;p&gt;A Bloom Filter uses multiple hash functions to map elements to positions in a &lt;strong&gt;bit array&lt;/strong&gt;. Here’s a simplified breakdown of how it works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Initialization:&lt;/strong&gt; Start with a bit array of size ( N ), initialized to 0 (all bits set to 0).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Insertion:&lt;/strong&gt; When an element is added, it is passed through multiple hash functions. Each hash function generates a different index in the bit array, and those indices are set to 1.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lookup:&lt;/strong&gt; To check whether an element is in the set, pass it through the same hash functions. If all the corresponding positions in the bit array are 1, the element is &lt;strong&gt;probably&lt;/strong&gt; in the set. If any of the positions are 0, the element is &lt;strong&gt;definitely not&lt;/strong&gt; in the set.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Example of Bloom Filter
&lt;/h3&gt;

&lt;p&gt;Let’s consider a simple example with a small bit array and two hash functions.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Initialize the Bloom Filter
&lt;/h4&gt;

&lt;p&gt;Imagine we have a Bloom Filter with a bit array of size 10, initialized to all zeros:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We’ll use two hash functions (for simplicity) that return indices from 0 to 9.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2: Insert Elements
&lt;/h4&gt;

&lt;p&gt;Let’s insert the element "apple" into the Bloom Filter. We pass "apple" through the two hash functions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hash function 1 maps "apple" to index 2.&lt;/li&gt;
&lt;li&gt;Hash function 2 maps "apple" to index 5.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We then set these positions in the bit array to 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0, 0, 1, 0, 0, 1, 0, 0, 0, 0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's insert another element, "banana":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hash function 1 maps "banana" to index 3.&lt;/li&gt;
&lt;li&gt;Hash function 2 maps "banana" to index 8.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After inserting "banana", the bit array looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0, 0, 1, 1, 0, 1, 0, 0, 1, 0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Check Membership
&lt;/h4&gt;

&lt;p&gt;Now, let’s check if an element like "apple" is in the set:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hash function 1 maps "apple" to index 2.&lt;/li&gt;
&lt;li&gt;Hash function 2 maps "apple" to index 5.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both of these indices are set to 1, so the Bloom Filter &lt;strong&gt;probably&lt;/strong&gt; contains "apple".&lt;/p&gt;

&lt;p&gt;If we check for an element like "grape":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hash function 1 maps "grape" to index 1.&lt;/li&gt;
&lt;li&gt;Hash function 2 maps "grape" to index 7.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both indices are 0, which means "grape" is &lt;strong&gt;definitely not&lt;/strong&gt; in the set.&lt;/p&gt;

&lt;p&gt;However, suppose we check for "cherry":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hash function 1 maps "cherry" to index 2.&lt;/li&gt;
&lt;li&gt;Hash function 2 maps "cherry" to index 5.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both of these positions are set to 1 (due to the previous insertions of "apple" and "banana"), so the Bloom Filter will incorrectly tell us that "cherry" is &lt;strong&gt;probably&lt;/strong&gt; in the set, even though it was never inserted. This is a &lt;strong&gt;false positive&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use Cases of Bloom Filters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Web Caching:&lt;/strong&gt; In web caching, Bloom Filters can be used to check if a page is cached. It helps in quickly determining if a cache lookup is necessary or if the page is likely not in the cache.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database Queries:&lt;/strong&gt; They are used in databases like HBase and Cassandra to quickly filter out rows that do not match certain conditions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spam Filters:&lt;/strong&gt; In email systems, Bloom Filters can be used to quickly check if an email address or domain has been flagged as spam.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Distributed Systems:&lt;/strong&gt; In distributed hash tables (DHT) and systems like Apache HBase, Bloom Filters are used to minimize disk I/O by filtering out unnecessary disk reads.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network Systems:&lt;/strong&gt; They are used in network protocols to check membership of IP addresses or blocks of IPs quickly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Java Implementation of Bloom Filter
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.BitSet&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.function.Function&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BloomFilter&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// The size of the bit array&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="no"&gt;SIZE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// The number of hash functions&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="no"&gt;NUM_HASH_FUNCTIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// BitSet to store the Bloom Filter's bit array&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;BitSet&lt;/span&gt; &lt;span class="n"&gt;bitSet&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Constructor initializes the bitSet with the given size&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;BloomFilter&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;bitSet&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;BitSet&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;SIZE&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Hash functions&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;hash1&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;hashCode&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="no"&gt;SIZE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;hash2&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="no"&gt;SIZE&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Insert an element into the Bloom Filter&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;hash1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hash1&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;hash2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hash2&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;bitSet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;set&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hash1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// Set the bit at the index of hash1&lt;/span&gt;
        &lt;span class="n"&gt;bitSet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;set&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hash2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// Set the bit at the index of hash2&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Check if an element is possibly in the set&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;hash1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hash1&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;hash2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hash2&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;element&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;bitSet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hash1&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;bitSet&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hash2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// Return true if both indices are set&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Main method to demonstrate the Bloom Filter&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;BloomFilter&lt;/span&gt; &lt;span class="n"&gt;bloomFilter&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;BloomFilter&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Adding elements to the Bloom Filter&lt;/span&gt;
        &lt;span class="n"&gt;bloomFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"apple"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;bloomFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"banana"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Checking for elements&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Contains 'apple': "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;bloomFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;contains&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"apple"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;  &lt;span class="c1"&gt;// Should return true&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Contains 'banana': "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;bloomFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;contains&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"banana"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;  &lt;span class="c1"&gt;// Should return true&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Contains 'grape': "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;bloomFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;contains&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"grape"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;  &lt;span class="c1"&gt;// Should return false (definitely not in set)&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Contains 'cherry': "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;bloomFilter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;contains&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"cherry"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;  &lt;span class="c1"&gt;// Should return false (probable false positive)&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Explanation:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;BitSet: A BitSet is used to represent the Bloom Filter. It’s essentially a bit array, where each bit can either be 0 or 1.&lt;/li&gt;
&lt;li&gt;Hash Functions: We have two simple hash functions:

&lt;ul&gt;
&lt;li&gt;hash1: Uses Java's built-in hashCode() method and takes modulo with the size of the Bloom Filter array.&lt;/li&gt;
&lt;li&gt;hash2: A secondary hash function based on the length of the string, which also takes modulo with the size.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Adding an element: When an element is added, both hash functions compute positions in the bit array, and we set those positions to 1.&lt;/li&gt;

&lt;li&gt;Checking membership: To check if an element is likely present, we compute the two hash positions again and check if both corresponding bits are 1. If both are set to 1, the element is probably in the set, but we can never be certain.
Output Example:
When you run the code, it might produce the following output:
&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Contains 'apple': true
Contains 'banana': true
Contains 'grape': false
Contains 'cherry': false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;"apple" and "banana" are present in the Bloom Filter and will return true.&lt;/li&gt;
&lt;li&gt;"grape" is definitely not in the set, so it will return false.&lt;/li&gt;
&lt;li&gt;"cherry" is not added, but may return false as a false positive depending on the hash function overlap. It should return false in this case.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Customization:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;You can increase the size of the bit array (SIZE) or the number of hash functions (NUM_HASH_FUNCTIONS) for better accuracy.&lt;/li&gt;
&lt;li&gt;This is a very simple Bloom Filter with just two hash functions. In a production setting, you’d likely want more hash functions and optimizations to reduce the false positive rate.
Let me know if you'd like to modify this or need further clarification!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Bloom Filters are a powerful tool for space and time-efficient membership testing. While they come with a trade-off of a small probability of false positives, their efficiency makes them invaluable in applications where speed and space are critical. If you can tolerate a small chance of false positives but need quick membership tests, the Bloom Filter is an excellent choice.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>java</category>
      <category>programming</category>
      <category>devchallenge</category>
    </item>
    <item>
      <title>Cracking the Proxy Puzzle: Forward vs Reverse 🧩</title>
      <dc:creator>Digvijay Bhakuni</dc:creator>
      <pubDate>Thu, 21 Nov 2024 13:50:00 +0000</pubDate>
      <link>https://dev.to/digvijay-bhakuni/cracking-the-proxy-puzzle-forward-vs-reverse-1ljg</link>
      <guid>https://dev.to/digvijay-bhakuni/cracking-the-proxy-puzzle-forward-vs-reverse-1ljg</guid>
      <description>&lt;p&gt;Hey there, developer! 👋 Welcome aboard! Today, let's unravel two powerful tools in web development: &lt;strong&gt;Forward Proxy&lt;/strong&gt; and &lt;strong&gt;Reverse Proxy&lt;/strong&gt;. By the end of this blog, you’ll understand how they work, when to use them, and see them in action with examples! 🌟&lt;/p&gt;




&lt;h3&gt;
  
  
  What is a Proxy? 🧱
&lt;/h3&gt;

&lt;p&gt;In the world of networking, a &lt;strong&gt;proxy&lt;/strong&gt; acts as an intermediary between a client and a server. Think of it like a middleman 📬 who helps deliver messages between two parties. Now, depending on where this middleman sits and &lt;em&gt;who&lt;/em&gt; they are helping, proxies can be of two types:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Forward Proxy&lt;/strong&gt;: Represents the client. 🧑‍💻➡️🌐
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reverse Proxy&lt;/strong&gt;: Represents the server. 🌐⬅️🏢
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s break these down further.&lt;/p&gt;




&lt;h3&gt;
  
  
  Forward Proxy 🔍
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Forward Proxy&lt;/strong&gt; is like a shield 🛡️ that sits in front of the client and makes requests on their behalf. It hides the client’s identity from the server.&lt;/p&gt;

&lt;h4&gt;
  
  
  How It Works:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;The client (browser or app) makes a request to the forward proxy.
&lt;/li&gt;
&lt;li&gt;The proxy forwards this request to the internet or target server.
&lt;/li&gt;
&lt;li&gt;The response comes back to the proxy, which then sends it to the client.
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Why Use It?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Privacy&lt;/strong&gt;: Hide the client’s IP address.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access Control&lt;/strong&gt;: Restrict what the client can access.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Caching&lt;/strong&gt;: Store frequently requested data to improve performance.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Real-Life Example:
&lt;/h4&gt;

&lt;p&gt;Imagine you're at work, and you want to browse Twitter 🐦. However, your company uses a forward proxy to block access to social media. When you type &lt;code&gt;twitter.com&lt;/code&gt;, your request goes to the proxy first. The proxy sees that Twitter is blocked and denies the request.  &lt;/p&gt;




&lt;h3&gt;
  
  
  Reverse Proxy 🚦
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Reverse Proxy&lt;/strong&gt; is like a gatekeeper 👮‍♂️ in front of a server. It handles incoming requests from clients and forwards them to one or more backend servers.&lt;/p&gt;

&lt;h4&gt;
  
  
  How It Works:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;The client makes a request to the reverse proxy instead of directly contacting the server.
&lt;/li&gt;
&lt;li&gt;The proxy decides which backend server should handle the request.
&lt;/li&gt;
&lt;li&gt;The response is sent back to the proxy, which then delivers it to the client.
&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Why Use It?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Load Balancing&lt;/strong&gt;: Distribute requests across multiple servers to handle more traffic.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security&lt;/strong&gt;: Hide backend server details from clients and protect against attacks.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSL Termination&lt;/strong&gt;: Manage SSL/TLS encryption on behalf of the servers.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Caching&lt;/strong&gt;: Reduce load on backend servers by serving cached responses.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Real-Life Example:
&lt;/h4&gt;

&lt;p&gt;Think of Netflix 🎥. Millions of users stream videos simultaneously. Netflix uses reverse proxies to distribute requests across their servers worldwide, ensuring smooth playback for everyone.  &lt;/p&gt;




&lt;h3&gt;
  
  
  Forward Proxy vs Reverse Proxy: The Key Differences 📖
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Feature&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Forward Proxy&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Reverse Proxy&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Represents&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The client 🧑‍💻&lt;/td&gt;
&lt;td&gt;The server 🏢&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Privacy, filtering, caching&lt;/td&gt;
&lt;td&gt;Load balancing, security, caching&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Client Interaction&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Knows the client's identity&lt;/td&gt;
&lt;td&gt;Hides the server's identity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Browsing blocked sites at work 🚫&lt;/td&gt;
&lt;td&gt;Netflix handling traffic 🎥&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  Example in Action:
&lt;/h3&gt;

&lt;p&gt;Let’s say your team builds a web app that’s getting popular (yay! 🎉). Traffic spikes, and one server can't handle it all. Here's how proxies can help:&lt;/p&gt;

&lt;h4&gt;
  
  
  Without Proxies (Problems):
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Single point of failure if the server goes down.
&lt;/li&gt;
&lt;li&gt;Slow response times as traffic grows.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  With Proxies (Solution):
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Use a &lt;strong&gt;Reverse Proxy&lt;/strong&gt; (e.g., Nginx or HAProxy) to distribute incoming traffic across multiple servers.
&lt;/li&gt;
&lt;li&gt;If you want to hide server details or optimize caching, the reverse proxy handles it seamlessly.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Meanwhile, if your users access your app via a corporate network, their IT might use a &lt;strong&gt;Forward Proxy&lt;/strong&gt; to monitor or filter their activities.&lt;/p&gt;




&lt;h3&gt;
  
  
  Tools for the Job 🛠️
&lt;/h3&gt;

&lt;p&gt;Here are some popular tools for implementing proxies:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Forward Proxy&lt;/strong&gt;: Squid 🦑, Privoxy, or custom scripts.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reverse Proxy&lt;/strong&gt;: Nginx, HAProxy, Apache, AWS Elastic Load Balancer.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Wrapping Up 🎁
&lt;/h3&gt;

&lt;p&gt;Proxies are powerful tools that make the internet smoother, faster, and more secure. As a developer, understanding when to use &lt;strong&gt;Forward&lt;/strong&gt; or &lt;strong&gt;Reverse Proxies&lt;/strong&gt; is like adding another superpower 💪 to your toolbox.&lt;/p&gt;

&lt;p&gt;Got questions or curious to try this out? Drop a comment below! Let's keep learning together. 🚀&lt;/p&gt;




&lt;p&gt;Does this make sense so far? Let me know if you'd like to see some code snippets or configurations! 😄&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Mastering API Pagination: Handle Big Data Like a Pro! 🚀</title>
      <dc:creator>Digvijay Bhakuni</dc:creator>
      <pubDate>Thu, 21 Nov 2024 11:23:24 +0000</pubDate>
      <link>https://dev.to/digvijay-bhakuni/mastering-api-pagination-handle-big-data-like-a-pro-d21</link>
      <guid>https://dev.to/digvijay-bhakuni/mastering-api-pagination-handle-big-data-like-a-pro-d21</guid>
      <description>&lt;p&gt;APIs often deal with massive amounts of data, and sending it all at once can overwhelm servers and clients. That’s where &lt;strong&gt;pagination&lt;/strong&gt; comes in, breaking data into smaller chunks for better performance and usability.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Types of Pagination:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Offset-Based&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Page-Size Based&lt;/em&gt;: Specify page number and size.
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Offset-Limit Based&lt;/em&gt;: Define a starting point and a limit.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Best For&lt;/strong&gt;: Simple, static datasets like product catalogs.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cursor-Based&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Key-Based&lt;/em&gt;: Use unique IDs to fetch the next batch.
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Time-Based&lt;/em&gt;: Use timestamps for consistent ordering.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Best For&lt;/strong&gt;: Real-time feeds and large, dynamic datasets.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Here’s a quick summary
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Criteria&lt;/th&gt;
&lt;th&gt;Offset-Based&lt;/th&gt;
&lt;th&gt;Cursor-Based&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Data Volume&lt;/td&gt;
&lt;td&gt;Small to medium&lt;/td&gt;
&lt;td&gt;Large datasets&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data Changes Often?&lt;/td&gt;
&lt;td&gt;Not ideal&lt;/td&gt;
&lt;td&gt;Excellent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Implementation Ease&lt;/td&gt;
&lt;td&gt;Simple&lt;/td&gt;
&lt;td&gt;Slightly complex&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Slower for large data&lt;/td&gt;
&lt;td&gt;Faster for large data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;UI Type&lt;/td&gt;
&lt;td&gt;Paged navigation&lt;/td&gt;
&lt;td&gt;Infinite scrolling&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each has pros and cons—Offset is simple but slower for large datasets, while Cursor is efficient but more complex. Choose wisely! 🎯&lt;br&gt;
&lt;a href="https://digvijay-bhakuni.medium.com/offset-or-cursor-choosing-the-right-pagination-for-your-api-needs-98caa13fd36e" rel="noopener noreferrer"&gt;Read More In Details &lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why Wait? Exploring Asynchronous and Non-Blocking Programming 🚦</title>
      <dc:creator>Digvijay Bhakuni</dc:creator>
      <pubDate>Sat, 16 Nov 2024 12:52:06 +0000</pubDate>
      <link>https://dev.to/digvijay-bhakuni/why-wait-exploring-asynchronous-and-non-blocking-programming-2m9j</link>
      <guid>https://dev.to/digvijay-bhakuni/why-wait-exploring-asynchronous-and-non-blocking-programming-2m9j</guid>
      <description>&lt;p&gt;If you've ever worked with code that juggles multiple tasks at the same time, you've probably come across the terms &lt;strong&gt;asynchronous&lt;/strong&gt; and &lt;strong&gt;non-blocking&lt;/strong&gt;. At first glance, they might seem like twins 👯‍♂️, but they are more like cousins. Let’s break it down in the simplest way possible, complete with examples and some fun emojis to keep things light!  &lt;/p&gt;




&lt;h2&gt;
  
  
  🌟 &lt;strong&gt;The Basics&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1️⃣ Asynchronous&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it means:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Asynchronous programming is like telling your friend to bake a cake 🍰 while you clean the house 🏠. Both tasks happen in parallel, and you don't wait for your friend to finish before you start.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Key idea:&lt;/strong&gt; &lt;strong&gt;Delegation&lt;/strong&gt; and &lt;strong&gt;waiting for results later&lt;/strong&gt;.  &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2️⃣ Non-Blocking&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;What it means:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Non-blocking programming is like using a microwave to heat your food 🍲. Instead of waiting in front of the microwave while it works, you start folding laundry 🧺.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Key idea:&lt;/strong&gt; &lt;strong&gt;No waiting around&lt;/strong&gt; while something is being processed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔍 &lt;strong&gt;Breaking It Down&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🚀 &lt;strong&gt;Asynchronous Programming Example&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Imagine you're ordering pizza 🍕 while working on your computer 💻.  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You call the pizza place and place your order (start a task).
&lt;/li&gt;
&lt;li&gt;While the pizza is being prepared and delivered, you continue working on your computer (you’re not sitting idle).
&lt;/li&gt;
&lt;li&gt;The pizza delivery person rings the doorbell, and you pause to answer (handle the result of the task).
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here’s what it might look like in code using &lt;strong&gt;async/await&lt;/strong&gt;:&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;orderPizza&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;Placing order for pizza...&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;pizza&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;preparePizza&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// This takes time, but we don’t wait here.&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;Pizza is ready: 🍕&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pizza&lt;/span&gt;&lt;span class="p"&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;preparePizza&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&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;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;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Delicious Pizza&lt;/span&gt;&lt;span class="dl"&gt;"&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;span class="c1"&gt;// Simulate a delay&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;orderPizza&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;Continuing to work on my project...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// This runs immediately&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 &lt;strong&gt;Key Takeaway:&lt;/strong&gt; Asynchronous means we can schedule tasks and be notified when they’re done, but our program doesn’t stop to wait.  &lt;/p&gt;




&lt;h3&gt;
  
  
  🌀 &lt;strong&gt;Non-Blocking Programming Example&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now imagine you’re at a restaurant 🏮. You place your order, and the server doesn’t stop everything to prepare your dish 🍜. Instead, they move on to serve the next customer.  &lt;/p&gt;

&lt;p&gt;Here’s how that looks in &lt;strong&gt;Node.js&lt;/strong&gt; with a non-blocking file read:&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;fs&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;fs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Non-blocking file read&lt;/span&gt;
&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;example.txt&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;utf8&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;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&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;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;Error reading file:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;err&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="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;File content:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&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;I can keep doing other stuff while the file is being read...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 &lt;strong&gt;Key Takeaway:&lt;/strong&gt; Non-blocking code doesn’t pause to wait for a task to finish—it moves on immediately.  &lt;/p&gt;




&lt;h2&gt;
  
  
  🔄 &lt;strong&gt;Asynchronous vs Non-Blocking&lt;/strong&gt;
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Asynchronous&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Non-Blocking&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Core Concept&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Schedule tasks and get results later&lt;/td&gt;
&lt;td&gt;Perform tasks without pausing the program&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Real-Life Analogy&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Ordering pizza while working&lt;/td&gt;
&lt;td&gt;Using a microwave and folding laundry&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Programming Example&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;async/await&lt;/code&gt;, promises, callbacks&lt;/td&gt;
&lt;td&gt;Event loops, non-blocking I/O&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Wait for Result?&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Yes, but only when you need it&lt;/td&gt;
&lt;td&gt;No, just keep moving forward!&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  💡 &lt;strong&gt;When to Use What?&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;asynchronous programming&lt;/strong&gt; when you need to run tasks concurrently but still want to process results later. Perfect for &lt;strong&gt;network requests&lt;/strong&gt;, &lt;strong&gt;database queries&lt;/strong&gt;, or &lt;strong&gt;background computations&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;non-blocking code&lt;/strong&gt; when you want to keep your program highly responsive, especially in &lt;strong&gt;I/O-heavy operations&lt;/strong&gt; like reading files, handling API calls, or responding to multiple users.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🏁 &lt;strong&gt;Wrapping It Up&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Asynchronous programming is about managing &lt;em&gt;when&lt;/em&gt; tasks complete, while non-blocking programming is about &lt;em&gt;not waiting&lt;/em&gt; for tasks to finish. Understanding the difference helps you build efficient, responsive apps that users ❤️.  &lt;/p&gt;

&lt;p&gt;So next time someone asks, you’ll know:&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Asynchronous is about the &lt;em&gt;future&lt;/em&gt;, and non-blocking is about the &lt;em&gt;now&lt;/em&gt;!&lt;/strong&gt; ⏳⚡  &lt;/p&gt;

&lt;p&gt;🚀 Happy coding!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>asynchronous</category>
      <category>nonblockingio</category>
    </item>
    <item>
      <title>🌊 Streaming vs. Batch Processing: Real-Time Waves or Scheduled Flows? ⏲️</title>
      <dc:creator>Digvijay Bhakuni</dc:creator>
      <pubDate>Tue, 12 Nov 2024 16:16:15 +0000</pubDate>
      <link>https://dev.to/digvijay-bhakuni/streaming-vs-batch-processing-real-time-waves-or-scheduled-flows-2cng</link>
      <guid>https://dev.to/digvijay-bhakuni/streaming-vs-batch-processing-real-time-waves-or-scheduled-flows-2cng</guid>
      <description>&lt;p&gt;Batch processing and stream processing are two key approaches to handling data, especially when dealing with large amounts of information. They differ in how they handle and process data over time.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. &lt;strong&gt;Batch Processing 🗃️&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In &lt;strong&gt;batch processing&lt;/strong&gt;, data is collected over a period of time, and then processed in bulk (a "batch") at a specific moment. You gather a large amount of data, then process it all at once.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Examples&lt;/strong&gt;: Payroll systems (monthly employee data) 🧾, nightly reports 🌙, or data aggregation for analysis 📊.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Latency&lt;/strong&gt;: &lt;strong&gt;High&lt;/strong&gt; ⏳. Because you’re waiting for a full batch to be ready, there’s usually a delay between data collection and processing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Flow&lt;/strong&gt;: Often static or finite; you have a clear start and end for each batch 🔁.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case&lt;/strong&gt;: Ideal when data isn’t time-sensitive. For example, if a company wants a daily or weekly summary of website user activity, they don’t need instant results, so processing in a batch later works well 🕰️.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. &lt;strong&gt;Stream Processing 🚰&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In &lt;strong&gt;stream processing&lt;/strong&gt;, data is processed in real-time as it flows in. You deal with each piece of data (or small groups) as soon as it arrives rather than waiting for a complete set.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Examples&lt;/strong&gt;: Fraud detection 🚨, stock price monitoring 📈, social media feeds 🐦.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Latency&lt;/strong&gt;: &lt;strong&gt;Low&lt;/strong&gt; ⚡. Data is processed almost instantly, allowing for quick reactions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Flow&lt;/strong&gt;: Continuous; the system handles a constant stream of data with no clear end 🔄.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case&lt;/strong&gt;: Perfect for real-time insights. For instance, a bank might use stream processing to detect unusual account activity (like fraud) as soon as it happens 🏦.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Differences Recap 📝
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Aspect&lt;/th&gt;
&lt;th&gt;Batch Processing 🗃️&lt;/th&gt;
&lt;th&gt;Stream Processing 🚰&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Data Handling&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Processes data in chunks at intervals 🕰️&lt;/td&gt;
&lt;td&gt;Processes data continuously ⚡&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Latency&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Higher latency ⏳&lt;/td&gt;
&lt;td&gt;Lower latency (real-time) ⚡&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Data Volume&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Suitable for large volumes at once 📊&lt;/td&gt;
&lt;td&gt;Handles data piece by piece 🔄&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Non-time-sensitive tasks 🕰️&lt;/td&gt;
&lt;td&gt;Real-time, instant reactions ⚡&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Choosing Between the Two 🤔
&lt;/h3&gt;

&lt;p&gt;Your choice will depend on the &lt;strong&gt;nature of the data&lt;/strong&gt; and &lt;strong&gt;how fast you need results&lt;/strong&gt;. Batch processing is generally simpler and more efficient for periodic tasks, while stream processing is crucial when immediate actions or insights are required. In modern systems, some setups even use a &lt;strong&gt;hybrid approach&lt;/strong&gt;—combining batch and stream processing—to meet different needs in the same architecture. 🛠️&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
