<?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>Forem: Hrishikesh Dalal</title>
    <description>The latest articles on Forem by Hrishikesh Dalal (@hrishikesh_dalal_ced8f95e).</description>
    <link>https://forem.com/hrishikesh_dalal_ced8f95e</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%2F3564172%2F53b92bbb-b5a6-4a39-bbe0-b13f02839490.png</url>
      <title>Forem: Hrishikesh Dalal</title>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hrishikesh_dalal_ced8f95e"/>
    <language>en</language>
    <item>
      <title>EP 15: Pub/Sub - Stop Chaining Your Services</title>
      <dc:creator>Hrishikesh Dalal</dc:creator>
      <pubDate>Wed, 18 Feb 2026 11:20:06 +0000</pubDate>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e/ep-15-pubsub-stop-chaining-your-services-53ng</link>
      <guid>https://forem.com/hrishikesh_dalal_ced8f95e/ep-15-pubsub-stop-chaining-your-services-53ng</guid>
      <description>&lt;p&gt;You just launched your dream startup, &lt;strong&gt;"DevEats"&lt;/strong&gt;—a food delivery app for developers who need serious fuel while debugging. Your signature item? The &lt;strong&gt;"Triple Stack Smash Burger with Truffle Fries."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the beginning, life was simple. You had one backend service (a monolith). A user ordered a burger, your code saved it to the database, and life was good.&lt;/p&gt;

&lt;p&gt;But you grew fast. Now, YOU are the owner of a scaling platform, and your code is turning into a tangled mess of spaghetti (pun intended).&lt;/p&gt;

&lt;p&gt;Here is why you need the &lt;strong&gt;Pub/Sub&lt;/strong&gt; pattern, explained through the lens of your own burger empire.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. What is the Need? (The "Smash Burger Panic")
&lt;/h2&gt;

&lt;p&gt;Let’s look at your current codebase. When a user clicks "Order Burger", your backend does this strictly in order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Payment Service:&lt;/strong&gt; Charge the credit card $25.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Order Service:&lt;/strong&gt; Save the order to the database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Notification Service:&lt;/strong&gt; Send a receipt email.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kitchen Service:&lt;/strong&gt; Print the ticket for the chef.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Analytics Service:&lt;/strong&gt; Update your admin dashboard sales graph.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The Problem:&lt;/strong&gt;&lt;br&gt;
One Friday night, your &lt;strong&gt;Email Provider goes down&lt;/strong&gt;.&lt;br&gt;
Because your code is sequential (A -&amp;gt; B -&amp;gt; C -&amp;gt; D), the entire process crashes at Step 3.&lt;/p&gt;

&lt;p&gt;The payment went through (Step 1), but the kitchen printer never got the ticket (Step 4).&lt;/p&gt;

&lt;p&gt;Now you have a hangry developer who paid for a Triple Stack Burger that isn't being made. They are angry, and your support inbox is flooding.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhgtok79omv8rofd7dxgw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhgtok79omv8rofd7dxgw.png" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Need:&lt;/strong&gt;&lt;br&gt;
You need a way for your system to say, &lt;em&gt;"Hey, a burger was just ordered!"&lt;/em&gt; without caring who is listening or if the email service is currently online. You need to &lt;strong&gt;decouple&lt;/strong&gt; the sender from the receivers.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The Solution: Pub/Sub Architecture
&lt;/h2&gt;

&lt;p&gt;In a Publish/Subscribe (Pub/Sub) model, we split your architecture into three parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The Publisher (You/The Order Service):&lt;/strong&gt; You simply shout a message ("Order #505: Triple Smash Burger!") into a channel. You don't know who is listening. You don't care.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Topic (The Channel):&lt;/strong&gt; A dedicated lane for specific types of messages (e.g., &lt;code&gt;events.burger_ordered&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Subscribers (The Listeners):&lt;/strong&gt; Independent services that have signed up to listen to that topic.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The New Flow:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;User orders the burger.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You (Order Service)&lt;/strong&gt; publish a message to the &lt;code&gt;events.burger_ordered&lt;/code&gt; topic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Done.&lt;/strong&gt; You return "Success" to the user immediately.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Meanwhile, in the background:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;Kitchen Service&lt;/strong&gt; hears the message and instantly prints the ticket on the grill station.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Notification Service&lt;/strong&gt; hears the message and &lt;em&gt;tries&lt;/em&gt; to send an email. If it fails (because the provider is down), it retries later. &lt;strong&gt;Crucially, it does not stop the kitchen from cooking.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Rewards Service&lt;/strong&gt; hears the message and adds 50 points to the user's account.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. When to Use It?
&lt;/h2&gt;

&lt;p&gt;You shouldn't use Pub/Sub for everything. Use it when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;1-to-Many Relationships:&lt;/strong&gt; One event (Burger Ordered) triggers multiple, unrelated actions (Email, Kitchen Display, Inventory Check).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decoupling is Vital:&lt;/strong&gt; You want to add a new "SMS Service" next week without rewriting your existing Order Service code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asynchronous Processing:&lt;/strong&gt; You don't want the user staring at a loading spinner while your server generates a PDF invoice.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. The Pros and Cons
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ✅ The Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; You can add 50 new subscribers (e.g., a "Surge Pricing Bot") without touching the original Publisher code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reliability:&lt;/strong&gt; If one subscriber crashes (e.g., the Email service), the others (Kitchen, Analytics) keep working perfectly. The burger still gets made.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Speed:&lt;/strong&gt; The Publisher fires the event and moves on. The user gets a "Your Order is Placed!" screen instantly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ❌ The Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complexity:&lt;/strong&gt; You are introducing a new component (a Broker like Redis, Kafka, or Google Pub/Sub) to manage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debugging is a Nightmare:&lt;/strong&gt; You can't just follow a linear stack trace anymore. You have to trace messages flying across a network.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistency Issues:&lt;/strong&gt; What if the message is delivered twice? (Does the customer get charged twice? Does the chef make two burgers?). You have to write code to handle these edge cases.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. Pub/Sub vs. Message Queue (The Confusion)
&lt;/h2&gt;

&lt;p&gt;This is where most devs get tripped up. Both use "Brokers," but the intent is different.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Scenario A: Pub/Sub (The "Megaphone")&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; You launch a &lt;strong&gt;New limited-edition Ghost Pepper Burger.&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Logic:&lt;/strong&gt; &lt;em&gt;1 Message -&amp;gt; Many Receivers.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Publisher:&lt;/strong&gt; The Menu Manager Service.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Subscribers:&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;App Notification Service:&lt;/strong&gt; Pushes "New Burger Alert!" to all users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inventory Service:&lt;/strong&gt; Reserves spicy peppers in the warehouse.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Marketing Service:&lt;/strong&gt; Posts automatically to Twitter/X.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why?&lt;/strong&gt; Everyone needs to know about this event to do their own specific job.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Scenario B: Message Queue (The "Grill Line")&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt; It's lunch rush. You have 500 burger orders coming in.&lt;br&gt;
&lt;strong&gt;Logic:&lt;/strong&gt; &lt;em&gt;1 Message -&amp;gt; 1 Receiver (Load Balancing).&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Producer:&lt;/strong&gt; The Order Service pushes 500 tickets to a &lt;strong&gt;Queue&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consumers (Chefs):&lt;/strong&gt; You have 5 Chefs (Chef A, B, C, D, E).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Flow:&lt;/strong&gt; Chef A grabs Ticket #1. Chef B grabs Ticket #2.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Why?&lt;/strong&gt; If Chef A is grilling the burger for Ticket #1, you &lt;strong&gt;do not&lt;/strong&gt; want Chef B to grill the same burger. That’s a waste of meat. You want to &lt;em&gt;distribute&lt;/em&gt; the work, not broadcast it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The Cheat Sheet&lt;/strong&gt;
&lt;/h3&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;Pub/Sub&lt;/th&gt;
&lt;th&gt;Message Queue&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Philosophy&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;"Everyone needs to know this happened."&lt;/td&gt;
&lt;td&gt;"Someone please do this job."&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Distribution&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Broadcast (One-to-All)&lt;/td&gt;
&lt;td&gt;Point-to-Point (One-to-One)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Burger Example&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;"New Menu Item Launched!" (Tell everyone)&lt;/td&gt;
&lt;td&gt;"Grill this patty" (One chef does it)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Final Words&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;As the owner of &lt;strong&gt;DevEats&lt;/strong&gt;, switching to Pub/Sub saved your Friday night rush. When your Email Service crashed, nobody noticed. The orders kept flowing, the smash burgers kept sizzling, and the emails were just queued up and sent an hour later.&lt;/p&gt;

&lt;p&gt;That is the power of decoupling. 🍔 code responsibly!&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>pubsub</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The Jungle Protocol: Turning my Professional Journey into an Adaptive Quest</title>
      <dc:creator>Hrishikesh Dalal</dc:creator>
      <pubDate>Sun, 01 Feb 2026 13:58:07 +0000</pubDate>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e/the-jungle-protocol-turning-my-professional-journey-into-an-adaptive-quest-3p4m</link>
      <guid>https://forem.com/hrishikesh_dalal_ced8f95e/the-jungle-protocol-turning-my-professional-journey-into-an-adaptive-quest-3p4m</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/new-year-new-you-google-ai-2025-12-31"&gt;New Year, New You Portfolio Challenge Presented by Google AI&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  About Me
&lt;/h2&gt;

&lt;p&gt;I’m Hrishikesh Dalal, a Computer Engineering student at Sardar Patel Institute of Technology (SPIT), Mumbai. I don't just write code; I build experiences. Currently, I’m engineering a Jumanji-themed gamified portfolio that turns the standard resume into an adventure.&lt;/p&gt;

&lt;p&gt;My focus lies in Full Stack Development (Next.js, React) and creating developer tools—I recently published envalyze and env-fault to the NPM registry to help devs manage environments better. When I'm not pushing commits to Open Source projects like Drupal or contributing to MDN Web Docs, I'm exploring the intersection of AI and law with projects like VerdictAI.&lt;/p&gt;

&lt;p&gt;I write about system design, open source, and the reality of building software.&lt;/p&gt;

&lt;h2&gt;
  
  
  Portfolio
&lt;/h2&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="ltag__cloud-run"&gt;
  &lt;iframe height="600px" src="https://hrishikesh-dalal-portfolio-571902073238.europe-west1.run.app"&gt;
  &lt;/iframe&gt;
&lt;/div&gt;




&lt;p&gt;Link: &lt;a href="https://hrishikesh-dalal-portfolio-571902073238.europe-west1.run.app" rel="noopener noreferrer"&gt;https://hrishikesh-dalal-portfolio-571902073238.europe-west1.run.app&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How I Built It
&lt;/h2&gt;

&lt;h3&gt;
  
  
  My Tech Stack
&lt;/h3&gt;

&lt;p&gt;To build an experience this immersive, I needed a stack that balanced performance with high-end visuals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Frontend: Next.js &amp;amp; Tailwind CSS&lt;/li&gt;
&lt;li&gt;Animations: GSAP (for that cinematic feel)&lt;/li&gt;
&lt;li&gt;3D Elements: Three.js (for the interactive globe and hero patterns)&lt;/li&gt;
&lt;li&gt;AI:Gemini API (powering the NPC-style chatbots)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Process: From Chaos to Clarity
&lt;/h3&gt;

&lt;p&gt;Building a portfolio is a trap. You want to show off everything, but if you're not careful, you end up with a bloated mess.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. The Affinity Mapping Phase
&lt;/h4&gt;

&lt;p&gt;Initially, I was drowning in ideas from my UI/UX course. I had a laundry list: a full 3D world, a terminal, hidden easter eggs, business-centric project stats, and a Jumanji-themed game. I used &lt;strong&gt;Affinity Mapping&lt;/strong&gt; to dump every "cool" idea onto a board and then ruthlessly segregated them.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. The "Reality Check"
&lt;/h4&gt;

&lt;p&gt;I had to ask the most important question: &lt;strong&gt;Why is someone here?&lt;/strong&gt;&lt;br&gt;
Hiring managers are busy. They might be tech-savvy, or they might not be. They might want to play a game, or they might just want to see my resume and leave in 30 seconds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Decision:&lt;/strong&gt; A "Clean &amp;amp; Clear" landing page with a defined Call to Action (CTA) is non-negotiable. The "wow" factor should enhance the info, not hide it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Design Breakdown: Section by Section
&lt;/h3&gt;

&lt;h4&gt;
  
  
  The Hero (The First 5 Seconds)
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhthw4dymw522shj11743.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhthw4dymw522shj11743.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I treated the Hero section like a movie opening. I implemented a preloader with a cinematic transition that drops you into an interactive dot pattern. It’s meant to grab attention immediately.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Impact (Big Numbers &amp;amp; Open Source)
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxuplswoqeglnkxh8ljth.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxuplswoqeglnkxh8ljth.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead of just saying "I build tools," I used big, bold typography to showcase my &lt;strong&gt;NPM stats&lt;/strong&gt;. I wanted the real-world impact of &lt;code&gt;envalyze&lt;/code&gt; and &lt;code&gt;env-fault&lt;/code&gt; to be unavoidable. I also dedicated space to my Open Source journey—showing my Hacktoberfest badges and my role as a project admin.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Experience Timeline
&lt;/h4&gt;

&lt;p&gt;I used a scroll-triggered timeline with GSAP micro-interactions. When you hover over an entry, there’s a slight movement—just enough to feel alive, but not enough to be distracting.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Terminal (For the Geeks)
&lt;/h4&gt;

&lt;p&gt;I built a fully functional terminal for my projects. You can change themes, run an &lt;code&gt;echo&lt;/code&gt;, or see animations.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt; Try typing &lt;code&gt;sudo&lt;/code&gt;. You’ve been warned.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;The Accessibility Switch:&lt;/strong&gt; If you aren't a terminal person, there's a toggle to switch back to a standard grid. No one gets left behind.&lt;/p&gt;

&lt;h3&gt;
  
  
  The "Jungle" Experience
&lt;/h3&gt;

&lt;p&gt;This was the hardest part to get right. My first version was just a collection of games, and the feedback from friends was brutal: &lt;em&gt;"It’s disconnected. I don't see YOU in this."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I went back to the drawing board and turned it into a narrative. I added:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A Prologue &amp;amp; Epilogue:&lt;/strong&gt; To give the "quest" a purpose.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Level 2 (The Jumper):&lt;/strong&gt; While you play, the character narrates my tech stack and experience journey.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secret Cheat Codes:&lt;/strong&gt; Because what's a game without them?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Bringing it to life with AI
&lt;/h3&gt;

&lt;p&gt;My main chatbot you have different answers queries, sample questions that you can ask to make it better. &lt;/p&gt;

&lt;p&gt;While the game chatbot is like NPC character answering you.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Architecture
&lt;/h3&gt;

&lt;p&gt;The diagram below shows how the game chatbot is integrated to handle context-aware queries, ensuring it knows where you are in the game and who I am as a developer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0z9vphjt0p8id5g9g8yk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0z9vphjt0p8id5g9g8yk.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The User Interaction Layer&lt;br&gt;
User Sends Message: The process begins with the user interacting with the interface. &lt;br&gt;
Frontend App (NEXT JS): The core UI is built using React. It features a React Markdown Renderer, which ensures that the AI's responses—often containing code snippets or formatted text—are displayed cleanly and professionally to the user.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Security and Traffic Management&lt;br&gt;
Backend API Gateway &amp;amp; Security Layer: Instead of calling the Gemini API directly from the frontend (which would expose your API keys), the app calls a secure backend gateway. This layer handles authentication and protects your credentials.&lt;br&gt;
Load Balancer: To prevent any single server from becoming overwhelmed, a load balancer sits in the middle. It analyzes incoming requests and routes them efficiently across multiple active instances.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Processing Core&lt;br&gt;
Chat Model Instances: The system uses multiple parallel instances (Instance 1, 2, and 3) to process requests.&lt;br&gt;
Least Used Routing: The load balancer is shown routing a request specifically to "Instance 1" because it is currently the "Least Used," ensuring optimal performance and low latency.&lt;br&gt;
Google's Gemini API: These instances act as the bridge to Google’s infrastructure. They send the processed user prompt to the Gemini API and receive the raw AI generation in return.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Response Loop&lt;br&gt;
Forwards Response: Once a chat instance receives the data from Google, it forwards that response back through the secure backend.&lt;br&gt;
Final Display: The message is sent back to the NEXT JS app, where it is rendered as Markdown, completing the loop and appearing on the user's screen.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Easter Eggs
&lt;/h3&gt;

&lt;p&gt;I have a game at the start where the user can press the "?" button and play that simple.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Stay Hungry, Stay Foolish."&lt;/strong&gt; My portfolio ends with this quote because it sums up my approach to engineering. Whether it's deep-diving into the Drupal source code or building a terminal from scratch, I’m always looking for the next thing that feels slightly impossible to build.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'm Most Proud Of
&lt;/h2&gt;

&lt;p&gt;If you’re a developer, you know the feeling: you spend 10% of your time on the features people see and 90% of your time on the "over-engineered" systems that make you feel like a wizard. Here are the pillars of this portfolio that I obsessed over.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The Terminal (Because real devs use a CLI)
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9wclxo5divqo63axsd66.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9wclxo5divqo63axsd66.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I didn't want a static "Projects" page; I wanted something that felt like home. I built a fully functional, web-based &lt;strong&gt;Terminal&lt;/strong&gt; where you can actually interact with my work.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Experience:&lt;/strong&gt; It’s a working CLI where you can navigate projects, change themes, or trigger animations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The "Sudo" Trap:&lt;/strong&gt; I’ve hidden easter eggs for people who like to poke around—try typing &lt;code&gt;sudo&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Hybrid UI:&lt;/strong&gt; I know recruiters aren't always looking to type commands, so I built a "safety net" toggle that instantly switches the terminal into a standard project grid.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Projects with a "Business First" Logic
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fffuih8dmbek5usvz4jbu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fffuih8dmbek5usvz4jbu.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc90f5dki8e2z7qd7c0g4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc90f5dki8e2z7qd7c0g4.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Most portfolios just show a screenshot and a GitHub link. I decided to treat my projects like real products.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Beyond the Code:&lt;/strong&gt; When you click into a project, I don't just list the tech stack. I break down the &lt;strong&gt;Business Perspective&lt;/strong&gt;, the &lt;strong&gt;Impact&lt;/strong&gt;, and the &lt;strong&gt;Stats&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The "Why" Factor:&lt;/strong&gt; I included the reasoning behind my architectural choices so that a non-technical stakeholder can understand the value I created, not just the code I wrote.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deep Dives:&lt;/strong&gt; Each project page is designed to show the journey from a pain point to a scalable solution.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. The Jumanji Game Engine
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8c48sfbpfgpbcbr5954.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj8c48sfbpfgpbcbr5954.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I turned my professional experience into a narrative quest. This wasn't just about putting a game on a website; it was about making the resume &lt;em&gt;playable&lt;/em&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Narrative:&lt;/strong&gt; I added a full prologue and epilogue to make sure it felt like a real quest, not just a random mini-game.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Career Jumper:&lt;/strong&gt; In Level 2, the character literally narrates my tech stack and my journey through different roles while you play.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recruiter Mode:&lt;/strong&gt; I even made the game adaptive—a recruiter can upload a job description, and the game will fine-tune the information it highlights to match what they need.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. The Chatbot Architecture
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd5jdp2hcjplottmv6nsh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd5jdp2hcjplottmv6nsh.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw6ywwj3qd4mhxof823go.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw6ywwj3qd4mhxof823go.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m most proud of what’s happening "under the hood" here. I built a production-ready pipeline for the Gemini-powered Chatbot.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Load Balancer:&lt;/strong&gt; My system uses three different chat model instances. I implemented a load balancer that routes traffic to the "least used" instance to keep things snappy, no matter the traffic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security &amp;amp; Scalability:&lt;/strong&gt; I kept the logic on the backend. The React frontend talks to a secure API Gateway, which handles the Gemini API calls to keep my keys safe.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The NPC Persona:&lt;/strong&gt; I used the &lt;strong&gt;Gemini API&lt;/strong&gt; to give the bot a specific "In-game NPC" persona—it knows it’s in the Jungle, but it also knows my GitHub stats.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>devchallenge</category>
      <category>googleaichallenge</category>
      <category>portfolio</category>
      <category>gemini</category>
    </item>
    <item>
      <title>System Design: EP 14 - The Coffee Shop Guide to Understanding Message Brokers</title>
      <dc:creator>Hrishikesh Dalal</dc:creator>
      <pubDate>Wed, 21 Jan 2026 11:17:47 +0000</pubDate>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e/system-design-ep-14-the-coffee-shop-guide-to-understanding-message-brokers-393b</link>
      <guid>https://forem.com/hrishikesh_dalal_ced8f95e/system-design-ep-14-the-coffee-shop-guide-to-understanding-message-brokers-393b</guid>
      <description>&lt;p&gt;If you are a developer moving from a monolith to microservices, you’ve probably hit &lt;strong&gt;The Problem&lt;/strong&gt;. Service A calls Service B, but Service B is slow, or down, or just busy. Suddenly, Service A hangs, the user sees a spinning wheel of death, and you get paged at 3 AM.&lt;/p&gt;

&lt;p&gt;The solution? Stop making your services talk directly. Introduce a &lt;strong&gt;Message Broker&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If that sounds abstract, let's talk about coffee.&lt;/p&gt;




&lt;h3&gt;
  
  
  The "Bad" Coffee Shop (Synchronous)
&lt;/h3&gt;

&lt;p&gt;Imagine a coffee shop where the person taking your order is also the &lt;em&gt;only&lt;/em&gt; person allowed to make your coffee.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;You&lt;/strong&gt; (The User) walk in and order a latte.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Cashier&lt;/strong&gt; (Service A) takes your money.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Cashier&lt;/strong&gt; then walks over to the espresso machine, steams the milk, pulls the shot, pours the art, and hands it to you.&lt;/li&gt;
&lt;li&gt;Only &lt;em&gt;then&lt;/em&gt; do they return to the register to take the next person's order.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The Result:&lt;/strong&gt; A massive line out the door. If the espresso machine breaks, the cashier is stuck waiting, and nobody can even &lt;em&gt;place&lt;/em&gt; an order. This is &lt;strong&gt;Synchronous Communication&lt;/strong&gt; (like HTTP REST calls). It creates tight coupling and bottlenecks.&lt;/p&gt;




&lt;h3&gt;
  
  
  The "Good" Coffee Shop (Asynchronous with a Broker)
&lt;/h3&gt;

&lt;p&gt;Now, let's look at how a Starbucks or a high-volume cafe actually works.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;You&lt;/strong&gt; (The User) order a latte.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Cashier&lt;/strong&gt; (Service A / Producer) takes your money and writes your order on a cup (or a ticket).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Cashier&lt;/strong&gt; places the cup on the &lt;strong&gt;Counter/Ticket Rail&lt;/strong&gt; (The Message Broker).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Cashier&lt;/strong&gt; immediately turns back to you and says, "Next please!"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Barista&lt;/strong&gt; (Service B / Consumer) sees the cup on the rail, picks it up, and makes the coffee.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The Result:&lt;/strong&gt; The cashier never stops working. They can take 50 orders in the time it takes the barista to make 5 drinks. The "Ticket Rail" acts as a buffer.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Technical Translation
&lt;/h3&gt;

&lt;p&gt;That "Ticket Rail" is your Message Broker (like RabbitMQ, Kafka, or AWS SQS). Here is the mapping for your next system design interview:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. The Producer (The Cashier)
&lt;/h4&gt;

&lt;p&gt;This is the service that sends the data. In the coffee shop, the cashier "produces" the order. They don't care &lt;em&gt;who&lt;/em&gt; makes the coffee or &lt;em&gt;when&lt;/em&gt; it gets made; they just need to know the order has been safely placed on the rail.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dev Term:&lt;/strong&gt; &lt;code&gt;Publish&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. The Message Broker (The Ticket Rail)
&lt;/h4&gt;

&lt;p&gt;This is the middleware that sits between your services. It holds the messages (orders) until a consumer is ready to take them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Queue:&lt;/strong&gt; The line of cups waiting on the machine. If the baristas get overwhelmed, the queue grows, but the cups aren't lost. They are safely stored until the backlog clears.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. The Consumer (The Barista)
&lt;/h4&gt;

&lt;p&gt;This is the service that processes the data. The barista "consumes" the order from the rail.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dev Term:&lt;/strong&gt; &lt;code&gt;Subscribe&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scaling:&lt;/strong&gt; If the line of cups gets too long, what do you do? You don't clone the cashier; you add a second barista. Message brokers allow you to scale your processing power (Consumers) independently of your intake power (Producers).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Why use a Message Broker?
&lt;/h3&gt;

&lt;p&gt;Using the coffee shop model, the benefits become obvious:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Decoupling:&lt;/strong&gt; The cashier doesn't need to know which barista is working today. If the barista quits (Service B crashes), the cashier can keep taking orders. The cups just pile up on the rail until a new barista is hired (Service B restarts). No data is lost.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Throttling (Load Leveling):&lt;/strong&gt; If 100 people rush the store at once, the cashier takes all the orders quickly. The baristas continue working at their normal, safe speed. They don't explode from stress; they just work through the backlog.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asynchronous Processing:&lt;/strong&gt; Heavy tasks (like roasting beans or baking pastries) don't block the customer from paying and leaving.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Direct HTTP calls are like a cashier making every drink themselves. It works for a lemonade stand, but it fails at scale.&lt;/p&gt;

&lt;p&gt;A Message Broker is the ticket rail that lets your services work at their own speeds, independently and reliably.&lt;/p&gt;

&lt;p&gt;So, the next time you're architecting a system, ask yourself: &lt;strong&gt;Are we building a lemonade stand, or are we building a coffee empire?&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>System Design - EP 13: Content Delivery Networks (CDNs)</title>
      <dc:creator>Hrishikesh Dalal</dc:creator>
      <pubDate>Fri, 16 Jan 2026 16:11:48 +0000</pubDate>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e/system-design-ep-13-content-delivery-networks-cdns-14ke</link>
      <guid>https://forem.com/hrishikesh_dalal_ced8f95e/system-design-ep-13-content-delivery-networks-cdns-14ke</guid>
      <description>&lt;p&gt;We’ve all been there. You click a link, and the page hangs. You stare at the loading spinner, your patience draining with every second. In 2026, a slow website isn't just annoying; it’s a dealbreaker.&lt;/p&gt;

&lt;p&gt;As developers, we know &lt;strong&gt;Speed = Revenue&lt;/strong&gt;. But how do you make a website fast for a user in Tokyo when your server is sitting in a basement in New York?&lt;/p&gt;

&lt;p&gt;Enter the &lt;strong&gt;CDN (Content Delivery Network)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you've ever nodded along while someone said "just put it behind Cloudflare" but were secretly fuzzy on the details, this article is for you. Let's break down CDNs using a scenario we can all understand: &lt;strong&gt;The Global Pizza Empire.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The Scenario: "Uncle Tony's Pizza"
&lt;/h2&gt;

&lt;p&gt;Imagine you run the world's best pizza shop, &lt;strong&gt;Uncle Tony's&lt;/strong&gt;, located in &lt;strong&gt;New York City&lt;/strong&gt;. Your pizza is legendary. People fly in from all over the world just to get a slice.&lt;/p&gt;

&lt;p&gt;In technical terms, your New York shop is the &lt;strong&gt;Origin Server&lt;/strong&gt;. It is the single source of truth where the pizza (content) is created.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Problem: The Latency Delivery
&lt;/h3&gt;

&lt;p&gt;One day, you decide to offer global delivery.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Customer A&lt;/strong&gt; lives in Brooklyn (5 miles away). They get their pizza hot and fresh in &lt;strong&gt;20 minutes&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customer B&lt;/strong&gt; lives in London (3,500 miles away). You have to bake the pizza in NY, put it on a supersonic jet, and fly it to London. It arrives 6 hours later, cold and soggy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This delay is &lt;strong&gt;Latency&lt;/strong&gt;. In the web world, even if your server (New York Kitchen) is super fast, the physical distance to the user (London Customer) creates unavoidable lag.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Solution: The Franchise Model (The CDN)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqqda18x3e6oyjcyji1sw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqqda18x3e6oyjcyji1sw.png" alt=" " width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You realize you can't defy physics. You can't make the jet faster. So, you change your strategy. You open small, reheating stations in major cities around the world: London, Tokyo, Mumbai, and Sydney.&lt;/p&gt;

&lt;p&gt;These stations are your &lt;strong&gt;Edge Servers&lt;/strong&gt;. They don't have the full kitchen setup of the NYC headquarters, but they are capable of holding inventory.&lt;/p&gt;

&lt;h3&gt;
  
  
  How the "Caching" Works
&lt;/h3&gt;

&lt;p&gt;You can't bake every single unique pizza at these small stations. Instead, you look at your data. You realize 80% of people just order &lt;strong&gt;Pepperoni&lt;/strong&gt; or &lt;strong&gt;Cheese&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The First Request (Cache Miss):&lt;/strong&gt;
A guy in London orders a Pepperoni pizza. The London station is empty. They call the NY HQ, get a Pepperoni pizza flown over, and deliver it. It’s slow, but now the London station keeps a stash of 50 frozen Pepperoni pizzas in their freezer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Second Request (Cache Hit):&lt;/strong&gt;
Ten minutes later, a girl in London orders a Pepperoni pizza. The London station checks its freezer. &lt;strong&gt;Bingo!&lt;/strong&gt; They grab one, heat it up, and deliver it in 10 minutes. They didn't even call New York.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  The Theory: Key Concepts in CDNs
&lt;/h2&gt;

&lt;p&gt;Now that we understand the pizza model, let's look at the actual technical terms you'll need for your system design interviews or cloud configs.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Edge Servers
&lt;/h3&gt;

&lt;p&gt;These are geographically distributed servers where CDN providers (like Cloudflare, Akamai, or Fastly) cache your content. Users are routed to the nearest edge server for faster delivery.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Pizza Translation:&lt;/em&gt; The local reheating stations in London or Tokyo.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Origin Server
&lt;/h3&gt;

&lt;p&gt;This is your main web server (e.g., an AWS EC2 instance or S3 bucket). The CDN fetches content from here &lt;em&gt;only&lt;/em&gt; if it’s not already cached at the edge server.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Pizza Translation:&lt;/em&gt; The main Uncle Tony's Kitchen in New York.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Caching
&lt;/h3&gt;

&lt;p&gt;CDNs store copies of your static content (e.g., images, videos, CSS, HTML) in their edge servers. Cached content is served directly to users, reducing the need for frequent requests to the origin server.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Pizza Translation:&lt;/em&gt; Storing frozen Pepperoni pizzas in the local freezer so you don't have to bake a fresh one every time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. TTL (Time to Live)
&lt;/h3&gt;

&lt;p&gt;The duration for which a file is cached on a CDN edge server.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; An image might have a TTL of 24 hours. This means it stays cached for 24 hours; after that, the Edge Server assumes it might be stale, deletes it, and fetches a fresh copy from the Origin.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Pizza Translation:&lt;/em&gt; The expiration date on the frozen pizza. You throw it out after 24 hours to ensure quality.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. GeoDNS
&lt;/h3&gt;

&lt;p&gt;CDNs use &lt;strong&gt;GeoDNS&lt;/strong&gt; to route users to the nearest edge server based on their geographic location. When a user types in your URL, the DNS resolver looks at their IP address and says, "You're in Germany? Okay, talk to the Frankfurt server, not the New York one."&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Pizza Translation:&lt;/em&gt; The call center routing your order to the nearest branch automatically.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why this Architecture Wins
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Speed (Performance)
&lt;/h3&gt;

&lt;p&gt;Your users in Tokyo aren't downloading images from New York anymore; they are downloading them from a server in Shinjuku. The data travels fewer miles, reducing the &lt;strong&gt;Time to First Byte (TTFB)&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Scalability (Traffic Spikes)
&lt;/h3&gt;

&lt;p&gt;Imagine it's Super Bowl Sunday. Everyone calls New York at once. The phone lines jam. The kitchen catches fire.&lt;br&gt;
With the Franchise model (CDN), the New York kitchen only handles the weird custom orders. The millions of standard Pepperoni orders are handled by the thousands of local branches. Your main kitchen survives.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Security (DDoS Protection)
&lt;/h3&gt;

&lt;p&gt;Imagine a competitor hires a million bots to prank call your New York Pizza shop so no real customers can get through.&lt;br&gt;
With a CDN, these prank calls hit the thousands of local branches first. The branches are smart—they realize it's a prank and hang up before the call ever reaches the New York HQ.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>System Design EP: 12 - Why Your Database Hates Your Images: A Guide to BLOBs</title>
      <dc:creator>Hrishikesh Dalal</dc:creator>
      <pubDate>Wed, 14 Jan 2026 14:34:27 +0000</pubDate>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e/system-design-ep-12-why-your-database-hates-your-images-a-guide-to-blobs-2k00</link>
      <guid>https://forem.com/hrishikesh_dalal_ced8f95e/system-design-ep-12-why-your-database-hates-your-images-a-guide-to-blobs-2k00</guid>
      <description>&lt;p&gt;Ummm, BLOBS. Everyone has heard that term somewhere sometime across their development journey, but what are those? &lt;/p&gt;

&lt;p&gt;In system design, a BLOB (Binary Large Object) is any unstructured data that doesn't fit neatly into a database row. Unlike integers or strings, the database engine doesn't "understand" this data,it just sees a massive chunk of bytes.&lt;/p&gt;

&lt;p&gt;Examples: User avatars (JPEG), video files (MP4), PDFs, Application Logs, Backup files.&lt;/p&gt;

&lt;p&gt;Size Range: From a few KBs (thumbnails) to TBs (genome sequencing data).&lt;/p&gt;

&lt;p&gt;So basically storing mp4 file directly as a file is difficult, how to store it say in MySQL but it becomes easier when we store in Blobs using 0 &amp;amp; 1s.&lt;/p&gt;

&lt;p&gt;When looking for the "definitive" resource on Blobs (Binary Large Objects) in System Design, most engineers end up piecing together chapters from different sources.&lt;/p&gt;

&lt;p&gt;Since a single perfect article is hard to find, I have synthesized the industry-standard approach below—essentially the article you are looking for—followed by links to the best external deep-dives.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The Great Debate: Database vs. Object Storage&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The most common interview question and real-world decision is: &lt;em&gt;"Should I store user uploads in my SQL database or on disk?"&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Option A: Storing BLOBs in the Database&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;You store the image directly in a column (e.g., &lt;code&gt;VARBINARY&lt;/code&gt; in MySQL or &lt;code&gt;BYTEA&lt;/code&gt; in PostgreSQL).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pros:&lt;/strong&gt; ACID compliance (the image and the user profile update commit together), easy backups (one dump file).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance Suicide:&lt;/strong&gt; Databases are optimized for small, random reads/writes. Reading a 10MB image consumes the same I/O as reading thousands of user rows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost:&lt;/strong&gt; Block storage (SSD for DBs) is 3-5x more expensive than Object Storage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; You cannot easily cache database responses at the edge (CDN) compared to static URLs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Option B: Storing BLOBs in Object Storage (The Standard)&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;You store the actual file in a service like Amazon S3, Google Cloud Storage, or Azure Blob, and store only the &lt;strong&gt;reference URL&lt;/strong&gt; in your database.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pros:&lt;/strong&gt; Infinite scalability, cheaper storage tiers, built-in redundancy, easy integration with CDNs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Loose consistency (you might delete the database row but forget to delete the S3 file, creating "orphan" data).&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The Verdict:&lt;/strong&gt; &lt;strong&gt;99% of the time, use Object Storage (Option B).&lt;/strong&gt; Only use Option A if your files are tiny (&amp;lt;20KB), strictly transactional, and security is paramount (e.g., encryption keys or sensitive legal docs that must never leak via a public URL).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The Architecture Pattern&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The standard design pattern for handling blobs involves decoupling metadata from storage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Workflow:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Client Request:&lt;/strong&gt; User uploads a profile picture.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API Gateway:&lt;/strong&gt; Authenticates the user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Presigned URL:&lt;/strong&gt; Instead of uploading to your server (which blocks your server's threads), your backend generates a "Presigned URL" from S3. This authorizes the client to upload &lt;em&gt;directly&lt;/em&gt; to the bucket for a limited time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Direct Upload:&lt;/strong&gt; Client uploads the binary data directly to S3/Blob Storage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Confirmation:&lt;/strong&gt; S3 returns a success code. The client notifies your backend: "Upload Complete."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Metadata Save:&lt;/strong&gt; Your backend saves the file path (e.g., &lt;code&gt;s3://my-bucket/users/123/avatar.png&lt;/code&gt;) into the SQL database &lt;code&gt;users&lt;/code&gt; table.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>systemdesign</category>
      <category>blobs</category>
      <category>aws</category>
    </item>
    <item>
      <title>EP 11: The Legend of ShopStream: The In-Memory Revolution</title>
      <dc:creator>Hrishikesh Dalal</dc:creator>
      <pubDate>Tue, 13 Jan 2026 10:15:59 +0000</pubDate>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e/ep-11-the-legend-of-shopstream-the-in-memory-revolution-9ic</link>
      <guid>https://forem.com/hrishikesh_dalal_ced8f95e/ep-11-the-legend-of-shopstream-the-in-memory-revolution-9ic</guid>
      <description>&lt;p&gt;Akash had fixed his database latency problems by using Redis as a cache. ShopStream was fast. But Akash was about to learn a hard lesson: &lt;strong&gt;Redis is not just a "dumb" cache.&lt;/strong&gt; It is a Ferrari engine that he was using to drive to the grocery store.&lt;/p&gt;

&lt;h3&gt;
  
  
  Chapter 1: The Day the Lights Went Out (Persistence)
&lt;/h3&gt;

&lt;p&gt;One stormy night, the power failed at the data center. The Redis server rebooted.&lt;/p&gt;

&lt;p&gt;When the lights came back on, Akash checked the dashboard.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;User Sessions:&lt;/strong&gt; Gone. Everyone was logged out.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shopping Carts:&lt;/strong&gt; Empty.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Revenue Impact:&lt;/strong&gt; Massive.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Akash panicked. &lt;em&gt;"I thought Redis stores data in RAM! If RAM loses power, data is gone!"&lt;/em&gt;&lt;br&gt;
He realized he needed &lt;strong&gt;Persistence&lt;/strong&gt;. He had two options:&lt;/p&gt;

&lt;h4&gt;
  
  
  Option A: The Photographer (RDB - Redis Database Backup)
&lt;/h4&gt;

&lt;p&gt;Akash configured Redis to take a "Snapshot" every hour.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;How it works:&lt;/strong&gt; Every hour, Redis forks a background process to save all data to a file (&lt;code&gt;dump.rdb&lt;/code&gt;) on the hard disk.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Trade-off:&lt;/strong&gt; It’s compact and fast to restore. &lt;em&gt;But&lt;/em&gt;, if the server crashes at 4:59 PM, he loses 59 minutes of data since the last snapshot at 4:00 PM.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Option B: The Stenographer (AOF - Append Only File)
&lt;/h4&gt;

&lt;p&gt;This wasn't enough for "Shopping Carts." So Akash turned on AOF.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;How it works:&lt;/strong&gt; Every time a command runs (e.g., &lt;code&gt;SET cart:123 "Apple"&lt;/code&gt;), Redis logs that command to a file on the disk immediately.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Trade-off:&lt;/strong&gt; No data loss! But the file grows huge over time because it records &lt;em&gt;every&lt;/em&gt; change.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Solution:&lt;/strong&gt; Akash used a hybrid approach. He used &lt;strong&gt;AOF&lt;/strong&gt; for critical data (carts/sessions) and &lt;strong&gt;RDB&lt;/strong&gt; for less critical cache data to balance speed and safety.&lt;/p&gt;




&lt;h3&gt;
  
  
  Chapter 2: The Data Structure Buffet (Beyond Strings)
&lt;/h3&gt;

&lt;p&gt;ShopStream was growing. Akash was building a "Live Leaderboard" for the most active shoppers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The "Newbie" Way:&lt;/strong&gt;&lt;br&gt;
Akash was storing the leaderboard as a JSON string in Redis:&lt;br&gt;
&lt;code&gt;"[{user: 'Alice', score: 10}, {user: 'Bob', score: 5}]"&lt;/code&gt;&lt;br&gt;
Every time Alice bought something, Akash had to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;GET the whole JSON string.&lt;/li&gt;
&lt;li&gt;Decode it in his backend code.&lt;/li&gt;
&lt;li&gt;Update Alice’s score.&lt;/li&gt;
&lt;li&gt;Sort the array again.&lt;/li&gt;
&lt;li&gt;SET the whole JSON string back to Redis.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This was slow and caused "Race Conditions" (two users updating at once).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The "Pro" Way (Redis Data Structures):&lt;/strong&gt;&lt;br&gt;
Akash realized Redis isn't just a Key-Value store; it's a &lt;strong&gt;Data Structure Server&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Sorted Sets (The Leaderboard Fix):&lt;/strong&gt;
He used the &lt;code&gt;ZSET&lt;/code&gt; data type.&lt;/li&gt;
&lt;li&gt;Command: &lt;code&gt;ZADD leaderboard 10 "Alice"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Command: &lt;code&gt;ZINCRBY leaderboard 5 "Alice"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Magic:&lt;/strong&gt; Redis automatically kept the list sorted in RAM. To get the top 3 users, Akash just ran &lt;code&gt;ZREVRANGE 0 2&lt;/code&gt;. No application code needed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hashes (The User Profile):&lt;/strong&gt;&lt;br&gt;
Instead of storing a user as a big blob of text, he used &lt;code&gt;HASH&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Command: &lt;code&gt;HSET user:101 name "Akash" email "a@test.com"&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Benefit: He could update &lt;em&gt;just&lt;/em&gt; the email without reading/writing the whole user object.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lists (The Job Queue):&lt;/strong&gt;&lt;br&gt;
When a user bought an item, the system needed to send an email. Instead of making the user wait, Akash pushed the "Send Email" task into a Redis &lt;code&gt;LIST&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Command: &lt;code&gt;LPUSH email_queue {user_id: 101}&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A background worker simply monitored the list (&lt;code&gt;BRPOP&lt;/code&gt;) and processed emails instantly.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Chapter 3: The Traffic Jam (Single Threaded Nature)
&lt;/h3&gt;

&lt;p&gt;One day, the app froze. CPU usage on the Redis server was at 100%.&lt;/p&gt;

&lt;p&gt;Akash looked at the logs. A junior developer had run a command: &lt;code&gt;KEYS *&lt;/code&gt; (Give me ALL keys).&lt;br&gt;
Because ShopStream had 10 million keys, Redis had to iterate through every single one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Critical Lesson:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Redis is Single-Threaded.&lt;/strong&gt; It processes one command at a time. It is incredibly fast (handling 100,000+ ops/sec), but if &lt;em&gt;one&lt;/em&gt; command takes 1 second (like &lt;code&gt;KEYS *&lt;/code&gt;), all other 99,999 requests are blocked waiting in line.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;The Fix:&lt;/strong&gt; Akash banned the &lt;code&gt;KEYS&lt;/code&gt; command and used &lt;code&gt;SCAN&lt;/code&gt; (which reads keys in small batches) to prevent blocking the main thread.&lt;/p&gt;




&lt;h3&gt;
  
  
  Chapter 4: Too Big to Fail (Sentinel vs. Cluster)
&lt;/h3&gt;

&lt;p&gt;The data grew to 500GB. But the server only had 64GB of RAM. The server crashed with an OOM (Out of Memory) error.&lt;/p&gt;

&lt;p&gt;Akash faced the ultimate architectural choice: &lt;strong&gt;Scale Up&lt;/strong&gt; or &lt;strong&gt;Scale Out&lt;/strong&gt;?&lt;/p&gt;

&lt;h4&gt;
  
  
  Scenario A: High Availability (Sentinel)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Problem:&lt;/strong&gt; "If my main Redis server dies, the app dies."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Solution:&lt;/strong&gt; Akash set up &lt;strong&gt;Redis Sentinel&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Architecture:&lt;/strong&gt; 1 Master Node (Write), 2 Slave Nodes (Read).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How it works:&lt;/strong&gt; Sentinel watches the Master. If the Master dies, Sentinel automatically votes for one of the Slaves to become the new Master.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limit:&lt;/strong&gt; The total data size is still limited to the RAM of &lt;em&gt;one&lt;/em&gt; node (64GB).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Scenario B: Infinite Scale (Redis Cluster)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Problem:&lt;/strong&gt; "I have 500GB of data. I need more RAM."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Solution:&lt;/strong&gt; Akash migrated to &lt;strong&gt;Redis Cluster&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How it works:&lt;/strong&gt; He bought 10 servers (nodes). Redis automatically split the data across them using &lt;strong&gt;Sharding&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Keys A-M go to Node 1.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keys N-Z go to Node 2.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Magic:&lt;/strong&gt; The client app doesn't need to know which node has the data. It asks the cluster, and the cluster routes the request to the right node.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  The Moral of the Story
&lt;/h3&gt;

&lt;p&gt;Akash learned that Redis is the "Swiss Army Knife" of backend engineering.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Persistence:&lt;/strong&gt; Use &lt;strong&gt;AOF&lt;/strong&gt; if you can't lose data; &lt;strong&gt;RDB&lt;/strong&gt; for backups.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logic:&lt;/strong&gt; Don't pull data to your code to sort it. Push your data into &lt;strong&gt;Sorted Sets&lt;/strong&gt; or &lt;strong&gt;Lists&lt;/strong&gt; and let Redis do the work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance:&lt;/strong&gt; Never block the single thread.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scaling:&lt;/strong&gt; Use &lt;strong&gt;Sentinel&lt;/strong&gt; for reliability, use &lt;strong&gt;Cluster&lt;/strong&gt; for massive data size.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Summary Cheat Sheet
&lt;/h3&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;Concept&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;String&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Basic Key-Value&lt;/td&gt;
&lt;td&gt;Caching HTML pages, Sessions.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;List&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Linked List&lt;/td&gt;
&lt;td&gt;Message Queues, Timelines (Twitter feed).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Set&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Unordered Unique&lt;/td&gt;
&lt;td&gt;Storing Followers, IP Whitelists (fast lookups).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Sorted Set (ZSet)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sorted by Score&lt;/td&gt;
&lt;td&gt;Leaderboards, Priority Queues.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Hash&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Field-Value Map&lt;/td&gt;
&lt;td&gt;Storing Objects (User Profiles, Product Details).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Pub/Sub&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Radio Station&lt;/td&gt;
&lt;td&gt;Real-time Chat, Notification Systems.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;TTL (Time to Live)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Expiry&lt;/td&gt;
&lt;td&gt;Auto-deleting OTPs or Cache data.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>architecture</category>
      <category>database</category>
      <category>performance</category>
    </item>
    <item>
      <title>EP 10: The Legend of ShopStream: The NFS (Caching)</title>
      <dc:creator>Hrishikesh Dalal</dc:creator>
      <pubDate>Mon, 12 Jan 2026 07:06:34 +0000</pubDate>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e/ep-10-the-legend-of-shopstream-the-nfs-caching-1ppm</link>
      <guid>https://forem.com/hrishikesh_dalal_ced8f95e/ep-10-the-legend-of-shopstream-the-nfs-caching-1ppm</guid>
      <description>&lt;p&gt;Akash, the founder of ShopStream, was feeling good. He had broken his Monolith into Microservices and set up a smart Load Balancer to handle the traffic. Ideally, the app should have been flying.&lt;/p&gt;

&lt;p&gt;But it wasn't.&lt;/p&gt;

&lt;p&gt;Users were complaining again. "The 'Trending Blogs' page takes forever to load!" they screamed in the reviews.&lt;/p&gt;

&lt;p&gt;Akash looked at the metrics. The servers were fine. The network was fine. The bottleneck was the &lt;strong&gt;Database&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Chapter 1: The Slow Librarian (The Problem)
&lt;/h3&gt;

&lt;p&gt;Every time a user opened the "Trending Blogs" page, the system did this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fetch Data:&lt;/strong&gt; It asked the MongoDB database for the top 10 blogs. (Time: &lt;strong&gt;500ms&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Calculate:&lt;/strong&gt; The backend formatted the dates and sorted the list. (Time: &lt;strong&gt;100ms&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Response:&lt;/strong&gt; The user finally got the page. (&lt;strong&gt;Total Time: 600ms&lt;/strong&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This 600ms delay happened for &lt;em&gt;every single user&lt;/em&gt;. If 10,000 people visited the page, the poor database had to answer the exact same question 10,000 times. It was like a librarian running to the basement to fetch the same book over and over again.&lt;/p&gt;

&lt;p&gt;Akash realized: &lt;em&gt;"Why am I calculating this every time? The trending blogs don't change every second!"&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Chapter 2: The Cheat Sheet (Enter Caching)
&lt;/h3&gt;

&lt;p&gt;Akash introduced a new layer to his architecture: &lt;strong&gt;The Cache&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;He set up a &lt;strong&gt;Redis&lt;/strong&gt; instance—a super-fast, in-memory storage. It acted like a "Cheat Sheet" or a sticky note on the librarian's desk.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The New Workflow:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;User A&lt;/strong&gt; visits the page. The system checks the Cache. It's empty (Cache Miss).&lt;/li&gt;
&lt;li&gt;The system goes to the Database (500ms) + Calculates (100ms) = &lt;strong&gt;600ms&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Crucially&lt;/em&gt;, before sending the response, the system &lt;strong&gt;saves a copy&lt;/strong&gt; of this final result in Redis.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The Magic:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;User B&lt;/strong&gt; visits the page 1 second later.&lt;/li&gt;
&lt;li&gt;The system checks the Cache. It finds the data! (Cache Hit).&lt;/li&gt;
&lt;li&gt;It serves the data directly from RAM. &lt;strong&gt;Total Time: 20ms.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Akash had just reduced the load time by &lt;strong&gt;96%&lt;/strong&gt;. The database stopped sweating, and the users were happy.&lt;/p&gt;




&lt;h3&gt;
  
  
  Chapter 3: The Ghost of Old Data (Cache Invalidation)
&lt;/h3&gt;

&lt;p&gt;Monday morning, Akash posted a breaking news blog: &lt;em&gt;"50% OFF SALE!"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;He refreshed the app. The new blog wasn't there.&lt;br&gt;
He refreshed again. Still the old list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem:&lt;/strong&gt; The Cache was doing its job &lt;em&gt;too&lt;/em&gt; well. It was still serving the "Trending Blogs" list it saved yesterday. It didn't know a new blog existed.&lt;/p&gt;

&lt;p&gt;Akash learned about &lt;strong&gt;Cache Invalidation&lt;/strong&gt;. He had to tell the cache when to update. He implemented two strategies:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The "Time to Live" (TTL):&lt;/strong&gt;
He told Redis: &lt;em&gt;"Only keep this data for 24 hours."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Day 1:&lt;/strong&gt; Cache serves fast data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Day 2 (24 hrs later):&lt;/strong&gt; Redis automatically deletes the data.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;First Request:&lt;/strong&gt; The system is forced to go back to the Database, get fresh data (including the new blog), and save it again.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Explicit Invalidation:&lt;/strong&gt;&lt;br&gt;
For critical things like "Product Price," 24 hours is too long. Akash wrote code so that whenever he updated a price in the admin panel, the system immediately &lt;strong&gt;nuked&lt;/strong&gt; that specific key from the cache.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Chapter 4: The Layers of Speed (Types of Caching)
&lt;/h3&gt;

&lt;p&gt;Akash realized he could cache things in more places than just the server. He built a "Defense in Depth" strategy for speed.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Client-Side Cache (The User's Pocket)
&lt;/h4&gt;

&lt;p&gt;Akash realized the browser was downloading the &lt;code&gt;logo.png&lt;/code&gt; and &lt;code&gt;style.css&lt;/code&gt; every time a user refreshed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Fix:&lt;/strong&gt; He told the user's browser (via HTTP headers): &lt;em&gt;"Keep this logo for a year. Don't ask me for it again."&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Result:&lt;/strong&gt; Zero network requests. Instant load.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. CDN Cache (The Delivery Trucks)
&lt;/h4&gt;

&lt;p&gt;ShopStream had users in London, but the main server was in Mumbai. Light takes time to travel that distance.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Fix:&lt;/strong&gt; Akash used a &lt;strong&gt;CDN (Content Delivery Network)&lt;/strong&gt; like Cloudflare. He stored copies of his static files (images, videos) on servers all over the world.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Result:&lt;/strong&gt; A user in London downloaded the images from a London server, not Mumbai.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Server-Side Cache (The RAM)
&lt;/h4&gt;

&lt;p&gt;This was his &lt;strong&gt;Redis&lt;/strong&gt; setup.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Fix:&lt;/strong&gt; Storing the results of heavy database queries or complex calculations in memory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Result:&lt;/strong&gt; The database could relax.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. Application-Level Cache
&lt;/h4&gt;

&lt;p&gt;Inside the code, Akash had a complex function that calculated shipping costs based on weight and distance.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Fix:&lt;/strong&gt; He used a local variable (memoization) to store the result of &lt;code&gt;calculateShipping(10kg, 5km)&lt;/code&gt;. If the code saw those inputs again, it just returned the saved number.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  The Moral of the Story
&lt;/h3&gt;

&lt;p&gt;By the end of the month, Akash looked at his dashboard.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Performance:&lt;/strong&gt; Latency dropped from 600ms to 60ms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost:&lt;/strong&gt; He actually &lt;em&gt;downgraded&lt;/em&gt; his database server because it had so little work to do, saving money.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; When traffic spiked, the Cache absorbed the hits, protecting the fragile database.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>redis</category>
      <category>database</category>
    </item>
    <item>
      <title>EP 9: The Legend of ShopStream: The Gatekeeper Chronicles</title>
      <dc:creator>Hrishikesh Dalal</dc:creator>
      <pubDate>Sun, 11 Jan 2026 04:42:10 +0000</pubDate>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e/ep-9-the-legend-of-shopstream-the-gatekeeper-chronicles-4dhp</link>
      <guid>https://forem.com/hrishikesh_dalal_ced8f95e/ep-9-the-legend-of-shopstream-the-gatekeeper-chronicles-4dhp</guid>
      <description>&lt;p&gt;Akash, the founder of ShopStream, had successfully split his massive Monolith into Microservices. The app was flexible, and the code was clean.&lt;/p&gt;

&lt;p&gt;But success brought a new problem: &lt;strong&gt;Traffic.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Chapter 1: The Crush (Why We Need a Load Balancer)
&lt;/h3&gt;

&lt;p&gt;It was the day of the "Mega Summer Sale." Millions of users flooded ShopStream to buy discounted headphones.&lt;/p&gt;

&lt;p&gt;Akash had prepared for this. He had spun up &lt;strong&gt;10 identical servers&lt;/strong&gt; for the &lt;em&gt;Checkout Service&lt;/em&gt;. He thought he was safe.&lt;/p&gt;

&lt;p&gt;But then, disaster struck.&lt;/p&gt;

&lt;p&gt;All the users were trying to connect to &lt;strong&gt;Server #1&lt;/strong&gt; because that was the only IP address the app knew. Server #1 caught fire (metaphorically) and crashed. The other 9 servers sat idle, doing absolutely nothing, while users stared at "404 Errors."&lt;/p&gt;

&lt;p&gt;Akash realized he didn't need just &lt;em&gt;more&lt;/em&gt; servers; he needed a &lt;strong&gt;Traffic Cop&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;He introduced a &lt;strong&gt;Load Balancer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Concept:&lt;/strong&gt;&lt;br&gt;
Imagine a popular nightclub. Inside, there are 5 bartenders (Servers). If everyone rushes to the first bartender, chaos ensues.&lt;br&gt;
The Load Balancer is the &lt;strong&gt;Host at the door&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Host stops you at the entrance.&lt;/li&gt;
&lt;li&gt;He looks inside to see which bartender is free.&lt;/li&gt;
&lt;li&gt;He points you to Bartender #3.&lt;/li&gt;
&lt;li&gt;If Bartender #2 passes out (Server Crash), the Host stops sending people to him. (This is called a &lt;strong&gt;Health Check&lt;/strong&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Suddenly, the traffic was spread evenly. No single server died. The system survived.&lt;/p&gt;

&lt;h3&gt;
  
  
  Chapter 2: The Decision Logic (Algorithms)
&lt;/h3&gt;

&lt;p&gt;Now that Akash had a "Host" at the door, he had to teach it &lt;em&gt;how&lt;/em&gt; to distribute the guests. This is where &lt;strong&gt;Load Balancing Algorithms&lt;/strong&gt; came in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The "Round Robin" (Taking Turns)&lt;/strong&gt;&lt;br&gt;
At first, Akash told the Host: &lt;em&gt;"Just send them in order. One for Server A, one for Server B, one for Server C."&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pros:&lt;/strong&gt; Simple and fair.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; It didn't account for strength. Server A was a powerful beast, while Server C was an old laptop. Server C got overwhelmed quickly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. The "Least Connections" (The Smart Observer)&lt;/strong&gt;&lt;br&gt;
Akash changed the rule: &lt;em&gt;"Look at who is busy. Send the new user to the server with the fewest active customers."&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pros:&lt;/strong&gt; Perfect for when user sessions have different lengths (e.g., one user buys quickly, another browses for hours).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cons:&lt;/strong&gt; Slightly more complex to calculate.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. The "IP Hash" (The Sticky Memory)&lt;/strong&gt;&lt;br&gt;
Some users complained: &lt;em&gt;"I put an item in my cart on Server A, but on my next click, the Load Balancer sent me to Server B, and my cart was empty!"&lt;/em&gt;&lt;br&gt;
Akash switched to IP Hashing. The Host now remembered the user's face (IP Address). &lt;em&gt;"Ah, I remember you. You go back to Server A."&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pros:&lt;/strong&gt; Essential for maintaining user sessions (Sticky Sessions).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Chapter 3: The Two Guardians (L4 vs. L7 Load Balancers)
&lt;/h3&gt;

&lt;p&gt;As ShopStream grew into a global empire, Akash realized not all traffic was the same. He had to choose between two types of Load Balancers: &lt;strong&gt;Layer 4 (L4)&lt;/strong&gt; and &lt;strong&gt;Layer 7 (L7)&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  The L4 Load Balancer: "The Bouncer"
&lt;/h4&gt;

&lt;p&gt;Akash hired a tough, fast Bouncer for the main entrance.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;How he works:&lt;/strong&gt; He only looks at the envelope of the message (IP Address and Port). He doesn't open the letter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Logic:&lt;/strong&gt; "Oh, you are coming from IP 192.168.1.5 trying to reach Port 80? Go to Server 3."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Pros:&lt;/strong&gt; He is incredibly &lt;strong&gt;fast&lt;/strong&gt;. He doesn't waste time reading the data. He can handle millions of requests per second.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Cons:&lt;/strong&gt; He is "dumb." He doesn't know if you are asking for a Video or a JPG image. He just forwards traffic blindly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  The L7 Load Balancer: "The Concierge"
&lt;/h4&gt;

&lt;p&gt;Inside the VIP area, Akash placed a sophisticated Concierge.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;How she works:&lt;/strong&gt; She actually opens the envelope and reads the request (HTTP Header, URL, Cookies).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Logic:&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;"I see you are requesting &lt;code&gt;/video/stream&lt;/code&gt;. I will send you to the high-performance &lt;strong&gt;Media Servers&lt;/strong&gt;."&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"I see you are requesting &lt;code&gt;/billing/invoice&lt;/code&gt;. I will send you to the highly secure &lt;strong&gt;Finance Servers&lt;/strong&gt;."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Pros:&lt;/strong&gt; She is &lt;strong&gt;smart&lt;/strong&gt;. She allows for "Content-Based Routing." She can even block hackers if she sees a suspicious SQL code in the URL.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Cons:&lt;/strong&gt; She is slower than the Bouncer because she has to read the message (Decrypt HTTPS, read headers, re-encrypt).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Moral of the Story
&lt;/h3&gt;

&lt;p&gt;Akash learned that a robust system usually needs &lt;strong&gt;both&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;L4 (The Bouncer)&lt;/strong&gt; sits at the very edge, taking the massive hit of incoming internet traffic and distributing it quickly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;L7 (The Concierge)&lt;/strong&gt; sits behind him, sorting that traffic into specific microservices (Checkout vs. Video vs. Reviews).&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>loadbalancer</category>
    </item>
    <item>
      <title>EP 8: The Legend of "ShopStream": A Tale of Two Architectures</title>
      <dc:creator>Hrishikesh Dalal</dc:creator>
      <pubDate>Sat, 10 Jan 2026 16:40:36 +0000</pubDate>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e/ep-8-the-legend-of-shopstream-a-tale-of-two-architectures-phn</link>
      <guid>https://forem.com/hrishikesh_dalal_ced8f95e/ep-8-the-legend-of-shopstream-a-tale-of-two-architectures-phn</guid>
      <description>&lt;p&gt;Once upon a time, in a small, dimly lit garage, a developer named Akash had a billion-dollar idea. He wanted to build &lt;strong&gt;ShopStream&lt;/strong&gt;, a revolutionary app that combined live video streaming with instant e-commerce.&lt;/p&gt;

&lt;p&gt;Akash had a deadline. He had investors to impress in two weeks. He needed to move fast.&lt;/p&gt;

&lt;h3&gt;
  
  
  Chapter 1: The Golden Monolith (The Early Days)
&lt;/h3&gt;

&lt;p&gt;Akash opened his code editor and created a single project folder.&lt;/p&gt;

&lt;p&gt;He built the &lt;strong&gt;User Auth&lt;/strong&gt;, the &lt;strong&gt;Video Player&lt;/strong&gt;, the &lt;strong&gt;Payment Gateway&lt;/strong&gt;, and the &lt;strong&gt;Inventory System&lt;/strong&gt; all in one massive codebase. They shared the same database and ran on a single server.&lt;/p&gt;

&lt;p&gt;It was a &lt;strong&gt;Monolith&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it worked:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Speed:&lt;/strong&gt; Akash could write a function in the &lt;em&gt;Video&lt;/em&gt; module and call it directly from the &lt;em&gt;Inventory&lt;/em&gt; module. No network lag, no API complexity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplicity:&lt;/strong&gt; Deployment was a breeze. He simply dragged his one executable file onto the server, restarted it, and &lt;em&gt;voilà&lt;/em&gt;—ShopStream was live.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost:&lt;/strong&gt; It ran on a cheap, $5/month virtual machine.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Lesson:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In the beginning, &lt;strong&gt;Monolithic is King&lt;/strong&gt;. When you are a startup or building an MVP (Minimum Viable Product), your priority is speed of delivery. You don't know if the product will succeed, so spending months architecting complex systems is a waste of time.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Chapter 2: The Spaghetti Monster (The Growth Phase)
&lt;/h3&gt;

&lt;p&gt;ShopStream became a viral hit. The user base exploded from 100 to 1,000,000 overnight.&lt;/p&gt;

&lt;p&gt;Akash hired 50 new developers. They all jumped into that same single project folder. Suddenly, the paradise turned into a nightmare.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The Merge Conflict Hell:&lt;/strong&gt; When the "Payment Team" tried to update the checkout logic, they accidentally overwrote code from the "Video Team."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The "Fragile Glass" Effect:&lt;/strong&gt; One Friday, a junior developer made a typo in the &lt;em&gt;Comments Section&lt;/em&gt; code. Because it was all one single process, the error caused a memory leak that crashed the &lt;em&gt;entire application&lt;/em&gt;. Users couldn't comment, but worse &lt;strong&gt;they couldn't buy anything either.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Scaling Problem:&lt;/strong&gt; On Black Friday, traffic spiked. The &lt;em&gt;Video Streaming&lt;/em&gt; part of the app was heavy and needed 100 extra servers. The &lt;em&gt;User Profile&lt;/em&gt; page was light and needed only one. But because it was a Monolith, Akash had to replicate the &lt;strong&gt;entire app&lt;/strong&gt; 100 times, wasting massive amounts of money on memory and CPU for parts of the app that weren't being used.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The Lesson:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Monoliths struggle at &lt;strong&gt;Scale&lt;/strong&gt;. When your team grows large, a single codebase becomes a bottleneck. When your traffic grows unevenly (some features are popular, others aren't), Monoliths scale inefficiently.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Chapter 3: The Great Migration (Enter Microservices)
&lt;/h3&gt;

&lt;p&gt;Desperate, Akash hired a seasoned Architect named Sasha. She looked at the giant, tangled ball of code and shook her head.&lt;/p&gt;

&lt;p&gt;"We need to break it apart," she said. "We need &lt;strong&gt;Microservices&lt;/strong&gt;."&lt;/p&gt;

&lt;p&gt;Over the next six months, they took a chainsaw to the Monolith.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They ripped out the &lt;strong&gt;Payment Logic&lt;/strong&gt; and made it a standalone service with its own database.&lt;/li&gt;
&lt;li&gt;They isolated the &lt;strong&gt;Video Transcoder&lt;/strong&gt; into its own service.&lt;/li&gt;
&lt;li&gt;They separated the &lt;strong&gt;Inventory System&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, these services talked to each other over a network (APIs), like distinct shops in a marketplace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why it worked:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fault Isolation:&lt;/strong&gt; A month later, the &lt;em&gt;Comments Service&lt;/em&gt; crashed again. But this time, the &lt;em&gt;Video Player&lt;/em&gt; and &lt;em&gt;Payments&lt;/em&gt; kept running perfectly. Users just saw a "Comments loading..." spinner, but they could still watch and buy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Independent Scaling:&lt;/strong&gt; When the Black Friday sale hit, Sasha set the &lt;em&gt;Payment Service&lt;/em&gt; to auto-scale to 500 servers, while leaving the &lt;em&gt;User Profile Service&lt;/em&gt; on just two. It was precise and cost-effective.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tech Freedom:&lt;/strong&gt; The Data Science team wanted to write the &lt;em&gt;Recommendation Engine&lt;/em&gt; in Python, while the core backend was in Java. With Microservices, they could do that easily.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Chapter 4: The Hidden Cost (The Reality Check)
&lt;/h3&gt;

&lt;p&gt;However, life wasn't perfect for Akash and Sasha.&lt;/p&gt;

&lt;p&gt;In the Monolith days, debugging was easy you just looked at the logs. Now, a user would report an error, and Akash had to chase the request through five different services to find where it failed.&lt;/p&gt;

&lt;p&gt;"Why is the site slow?" Akash asked.&lt;br&gt;
"Well," Sasha replied, "Service A is calling Service B, which is waiting for Service C, and the network between them is lagging."&lt;/p&gt;

&lt;p&gt;They had to hire a dedicated DevOps team just to manage the complexity of Kubernetes, Docker containers, and distributed tracing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Lesson:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Microservices are expensive.&lt;/strong&gt; They trade &lt;em&gt;development&lt;/em&gt; complexity for &lt;em&gt;operational&lt;/em&gt; complexity. You don't solve the problem; you just move it. You should only pay this price if you absolutely need the scale.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  The Moral of the Story
&lt;/h3&gt;

&lt;p&gt;So, which architecture won? Neither. They just served different chapters of the company's life.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stick with the Monolith if:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You are a startup or a small team (under 10-20 devs).&lt;/li&gt;
&lt;li&gt;You are building a new product (MVP).&lt;/li&gt;
&lt;li&gt;Your domain is simple.&lt;/li&gt;
&lt;li&gt;You want fast iteration and easy debugging.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgj645xacoep9vk07ni5w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgj645xacoep9vk07ni5w.png" alt=" " width="800" height="639"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Switch to Microservices if:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You are a large enterprise (Netflix, Uber, Amazon scale).&lt;/li&gt;
&lt;li&gt;You have multiple teams that need to work independently without blocking each other.&lt;/li&gt;
&lt;li&gt;You need to scale different parts of your app drastically differently.&lt;/li&gt;
&lt;li&gt;One part of your system crashing shouldn't take down the rest.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3doathyvdu8amhlihm7g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3doathyvdu8amhlihm7g.png" alt=" " width="800" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Golden Rule:&lt;/strong&gt; Start Monolithic. Stay Monolithic as long as you can. Only break it apart when the pain of managing the Monolith becomes greater than the pain of managing Microservices.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>webdev</category>
      <category>architecture</category>
      <category>microservices</category>
    </item>
    <item>
      <title>EP 7: The "Join" Tax vs. The "Storage" Tax</title>
      <dc:creator>Hrishikesh Dalal</dc:creator>
      <pubDate>Fri, 02 Jan 2026 04:37:24 +0000</pubDate>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e/ep-7-the-join-tax-vs-the-storage-tax-1jna</link>
      <guid>https://forem.com/hrishikesh_dalal_ced8f95e/ep-7-the-join-tax-vs-the-storage-tax-1jna</guid>
      <description>&lt;p&gt;When we talk about SQL vs. NoSQL in the context of system design, we’re moving past syntax and getting into the "meat" of the problem: Trade-offs. In a real-world system, you aren't choosing a database because you like the query language; you’re choosing it because of how it handles traffic, consistency, and failure. Here is how to think about this like a seasoned engineer.&lt;/p&gt;

&lt;h2&gt;
  
  
  The "Join" Tax vs. The "Storage" Tax
&lt;/h2&gt;

&lt;p&gt;In System Design, we care about &lt;strong&gt;latency&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SQL (Normalization):&lt;/strong&gt; We minimize redundancy. If a user changes their name, you update it in one place. But the "tax" you pay is in &lt;strong&gt;Joins&lt;/strong&gt;. If your dashboard needs data from five different tables, your database has to do a lot of heavy lifting at read-time to stitch that data back together.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NoSQL (Denormalization):&lt;/strong&gt; We embrace redundancy. You might store that user’s name in five different document collections. The "tax" here is &lt;strong&gt;Storage and Update Complexity&lt;/strong&gt;. Reads are lightning-fast because the data is already "pre-joined" in one document, but if the user changes their name, you might have to update five different places.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Ask yourself: &lt;em&gt;Is my app read-heavy or write-heavy?&lt;/em&gt; If you're building a social media feed where you read the same post a million times but only write it once, NoSQL’s "read-ready" format often wins.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkg17hva4c76519robyx5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkg17hva4c76519robyx5.png" alt="SQL v/s NoSQL" width="728" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The CAP Theorem: The Rule You Can't Break
&lt;/h2&gt;

&lt;p&gt;You can’t talk system design without the &lt;strong&gt;CAP Theorem&lt;/strong&gt;. It’s the ultimate reality check for distributed systems.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Consistency (C):&lt;/strong&gt; Every node sees the same data at the same time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Availability (A):&lt;/strong&gt; Every request gets a response (even if it's old data).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Partition Tolerance (P):&lt;/strong&gt; The system keeps working even if the network breaks between nodes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In a distributed world, you &lt;strong&gt;must&lt;/strong&gt; choose &lt;strong&gt;P&lt;/strong&gt;. That leaves you with a choice between &lt;strong&gt;CP&lt;/strong&gt; (SQL-like strictness) or &lt;strong&gt;AP&lt;/strong&gt; (NoSQL-like speed).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SQL (CP):&lt;/strong&gt; Better for banking or inventory. I’d rather the system "break" (be unavailable) than tell you that you have $100 when you actually have $0.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NoSQL (AP):&lt;/strong&gt; Better for "likes" on a post. If one server shows 100 likes and another shows 102, the world won't end.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Scaling: The "Wall" vs. The "Horizon"
&lt;/h2&gt;

&lt;p&gt;This is usually the biggest factor in high-level design interviews.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SQL Scaling (Vertical):&lt;/strong&gt; You’re basically buying a bigger engine for the same car. Once you hit the limit of the biggest server available, you have to do &lt;strong&gt;Manual Sharding&lt;/strong&gt;, which is a nightmare of architectural complexity. :(&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NoSQL Scaling (Horizontal):&lt;/strong&gt; These are built to be "sharded" by design. You just add more cheap servers (nodes) to the cluster. The database handles the distribution of data across those nodes automatically. :)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As we navigate the tech landscape of 2026, many of the world's most successful platforms aren't choosing one over the other, they are using both in tandem to handle different parts of their infrastructure.&lt;/p&gt;

&lt;p&gt;Here are some use cases and real-life examples of where these databases actually live in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Financial Integrity and Compliance
&lt;/h2&gt;

&lt;p&gt;When you are building a system where a single missing penny can cause a legal nightmare, &lt;strong&gt;SQL&lt;/strong&gt; is the only real choice. Financial systems rely on &lt;strong&gt;ACID compliance&lt;/strong&gt; to ensure that if a transaction starts, it either completes perfectly or fails entirely with no "middle ground."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-Life Example:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;JPMorgan Chase&lt;/strong&gt; uses relational databases (often heavily tuned versions of PostgreSQL or Oracle) to manage their core ledgers. They need strict schemas and strong consistency because they cannot afford "eventual consistency." If you check your balance after a deposit, it needs to be correct immediately, not "eventually" correct a few seconds later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Social Media Feeds and Real-Time Content
&lt;/h2&gt;

&lt;p&gt;Social media is the opposite of a bank ledger. It is "read-heavy" and deals with massive amounts of unstructured data like text, images, tags, and reactions. &lt;strong&gt;NoSQL&lt;/strong&gt; shines here because of its ability to scale horizontally. In a system design interview, if you are asked to design a "Twitter-like" feed, you'd likely use a &lt;strong&gt;Document Store&lt;/strong&gt; (like MongoDB) or a &lt;strong&gt;Wide-Column Store&lt;/strong&gt; (like Cassandra). These databases allow you to store a post and all its metadata together in one "blob," making it incredibly fast to serve to millions of users at once.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-Life Example:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Instagram&lt;/strong&gt; uses a hybrid approach, but they famously use a NoSQL-style architecture for their feed. When you scroll, the app isn't performing complex "joins" across ten different tables to find the photo, the caption, and the likes; it's pulling a pre-computed document from a NoSQL store that has everything ready to show you in milliseconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  High-Speed Caching and Session Management
&lt;/h2&gt;

&lt;p&gt;Sometimes you don't need a permanent home for data; you just need a place to store it for a few minutes at lightning speed. This is where &lt;strong&gt;Key-Value NoSQL stores&lt;/strong&gt; (like Redis) come in. In system design, we use these for things like user sessions, shopping carts, or leaderboards. If a user logs in, you don't want to query your main SQL database every single time they click a button just to verify who they are. Instead, you store their "session token" in a fast in-memory NoSQL database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-Life Example:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Gaming platforms like Riot Games (League of Legends)&lt;/strong&gt; use NoSQL key-value stores to manage live leaderboards and player sessions. When thousands of players finish a match at the same time, the system needs to update rankings instantly without waiting for a traditional SQL database to lock tables and process the writes.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>architecture</category>
      <category>database</category>
      <category>performance</category>
    </item>
    <item>
      <title>EP 6.4: What is SHARDING?</title>
      <dc:creator>Hrishikesh Dalal</dc:creator>
      <pubDate>Thu, 01 Jan 2026 12:03:25 +0000</pubDate>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e/ep-64-what-is-sharding-13am</link>
      <guid>https://forem.com/hrishikesh_dalal_ced8f95e/ep-64-what-is-sharding-13am</guid>
      <description>&lt;p&gt;In the world of system design, there is a common saying: "Don't shard until you absolutely have to." While sharding offers virtually unlimited scaling potential, it introduces a level of operational complexity that can cripple a small engineering team.&lt;/p&gt;

&lt;p&gt;This article I explore what sharding is, why it differs from simple partitioning, the strategies for implementing it. So let us get intoo it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Sharding? (We know Partitioning, so why need Sharding)
&lt;/h2&gt;

&lt;p&gt;To understand sharding, you must first understand Horizontal Partitioning. In partitioning, you take a massive table and split it into smaller "chunks" stored on the same server. The database engine (like PostgreSQL) handles the logic of finding which chunk holds your data.&lt;/p&gt;

&lt;p&gt;Sharding takes this a step further. Instead of keeping those chunks on one machine, you place them on entirely different database servers, known as Shards.&lt;/p&gt;

&lt;p&gt;The Core Difference: &lt;/p&gt;

&lt;p&gt;Partitioning -&amp;gt; database manages the complexity. &lt;br&gt;
Sharding -&amp;gt; you (the application developer) manage the complexity.&lt;/p&gt;

&lt;p&gt;Partitioning -&amp;gt; Tables&lt;br&gt;
Sharding -&amp;gt; Databases&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3o1c8ilg5rxdxa17s9f8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3o1c8ilg5rxdxa17s9f8.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Shard Key:)
&lt;/h2&gt;

&lt;p&gt;When you split a table across multiple servers, you need a rule to decide where each row goes. This is determined by the Sharding Key.&lt;/p&gt;

&lt;p&gt;If you shard based on user_id:&lt;/p&gt;

&lt;p&gt;Server 1 (Shard 1): Stores users with IDs 1–1000.&lt;/p&gt;

&lt;p&gt;Server 2 (Shard 2): Stores users with IDs 1001–2000.&lt;/p&gt;

&lt;p&gt;The Sharding Key is the most critical decision in this architecture. A poor key leads to "Hotspots", where one server is at 99% CPU while the others are idling at 5%.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Sharding Strategies
&lt;/h2&gt;

&lt;p&gt;There is no "one size fits all" way to distribute data. Here are the four primary strategies used in the industry:&lt;/p&gt;

&lt;h3&gt;
  
  
  A. Range-Based Sharding
&lt;/h3&gt;

&lt;p&gt;Data is divided into continuous ranges of the shard key.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ex: Shard A (A-M), Shard B (N-Z).&lt;/li&gt;
&lt;li&gt;Pros: Very easy to reason about and implement. &lt;/li&gt;
&lt;li&gt;Cons: Leads to &lt;strong&gt;Data Skew&lt;/strong&gt;. If you have 1 million users whose names start with 'S' and only 10 users starting with 'X', Shard B will be overloaded while Shard A sits empty.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  B. Hash-Based Sharding
&lt;/h3&gt;

&lt;p&gt;A hash function is applied to the shard key (), where  is the number of shards.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pros: Provides a very even distribution of data across all servers.&lt;/li&gt;
&lt;li&gt;Cons: &lt;strong&gt;Resharding is a nightmare.&lt;/strong&gt; If you grow from 3 shards to 4, the result of the modulo operation changes for almost every key, requiring you to move nearly all your data to new servers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  C. Geographic/Entity-Based Sharding
&lt;/h3&gt;

&lt;p&gt;Data is grouped by a logical attribute like region or country.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ex: European users on a Dublin server; Asian users on a Singapore server.&lt;/li&gt;
&lt;li&gt;Pros: Reduces latency for local users and helps with data residency laws (GDPR).&lt;/li&gt;
&lt;li&gt;Cons: If your app suddenly goes viral in one specific country, that shard becomes a bottleneck.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  D. Directory-Based Sharding
&lt;/h3&gt;

&lt;p&gt;A separate "Lookup Service" or "Mapping Table" keeps track of which shard holds which data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pros: Maximum flexibility. You can move a single user from Shard 1 to Shard 5 without changing any hashing logic.&lt;/li&gt;
&lt;li&gt;Cons: The directory itself becomes a &lt;strong&gt;Single Point of Failure&lt;/strong&gt; and a performance bottleneck. Every query now requires two hits: one to the directory and one to the shard.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Why Sharding is Difficult :(
&lt;/h2&gt;

&lt;p&gt;If sharding allows you to scale to billions of users, why do engineers avoid it? &lt;/p&gt;

&lt;h3&gt;
  
  
  I. Application Complexity
&lt;/h3&gt;

&lt;p&gt;Since the data is on different servers, the database can't help you find it. Your application code must become "Shard Aware." You have to write logic that says: &lt;em&gt;"If the user is trying to log in with ID 505, connect to Database Server 2."&lt;/em&gt; This makes your codebase significantly harder to maintain.&lt;/p&gt;

&lt;h3&gt;
  
  
  II. The "Join" Problem
&lt;/h3&gt;

&lt;p&gt;In a single database, joining two tables is easy. In a sharded environment, if the &lt;code&gt;Users&lt;/code&gt; table is on Shard A and the &lt;code&gt;Orders&lt;/code&gt; table is on Shard B, you &lt;strong&gt;cannot perform a SQL Join&lt;/strong&gt;. You must pull the data from both servers into your application memory and "join" them manually—an operation that is slow and memory-intensive.&lt;/p&gt;

&lt;h3&gt;
  
  
  III. Loss of Transactional Consistency
&lt;/h3&gt;

&lt;p&gt;Classic databases offer &lt;strong&gt;ACID&lt;/strong&gt; properties (Atomicity, Consistency, Isolation, Durability). In sharding, a "transaction" that spans two shards is nearly impossible to guarantee. If Shard A updates successfully but Shard B fails, your data is now in a corrupted, inconsistent state.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. When should you actually Shard?
&lt;/h3&gt;

&lt;p&gt;Before you choose sharding, you should have already exhausted these three steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Vertical Scaling:&lt;/strong&gt; Buy a bigger server with more RAM and CPU.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read Replicas (Master-Slave):&lt;/strong&gt; Use the architecture we discussed earlier to offload all "Read" traffic to Slaves.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Caching:&lt;/strong&gt; Use Redis to stop 80% of requests from even hitting your database.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>database</category>
      <category>resources</category>
    </item>
    <item>
      <title>EP 6.3: Master-Slave Architecture</title>
      <dc:creator>Hrishikesh Dalal</dc:creator>
      <pubDate>Thu, 01 Jan 2026 06:10:48 +0000</pubDate>
      <link>https://forem.com/hrishikesh_dalal_ced8f95e/ep-63-master-slave-architecture-15pf</link>
      <guid>https://forem.com/hrishikesh_dalal_ced8f95e/ep-63-master-slave-architecture-15pf</guid>
      <description>&lt;p&gt;In system design, the &lt;strong&gt;Master-Slave (or Leader-Follower)&lt;/strong&gt; architecture is one of the most fundamental patterns used to achieve scalability and high availability, particularly in database systems. :)&lt;/p&gt;

&lt;p&gt;Consider it like a leader asking its followers to do something and the followers comply with it.&lt;/p&gt;

&lt;p&gt;At its core, it is a model of communication where one device or process (the Master) has unidirectional control over one or more other devices or processes (the Slaves).&lt;/p&gt;

&lt;p&gt;MASTER -&amp;gt; SLAVE&lt;/p&gt;

&lt;h2&gt;
  
  
  1. HOW IT WORKS?
&lt;/h2&gt;

&lt;p&gt;In a data-driven application, this architecture separates the &lt;strong&gt;writing&lt;/strong&gt; of data from the &lt;strong&gt;reading&lt;/strong&gt; of data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxt7dyu1wioexdifinz9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxt7dyu1wioexdifinz9.png" alt=" " width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Master (The Leader)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Source of Truth:&lt;/strong&gt; The Master handles all &lt;strong&gt;Write&lt;/strong&gt; operations (INSERT, UPDATE, DELETE).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Coordination:&lt;/strong&gt; Records these changes in a log.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Propagation:&lt;/strong&gt; Resp. for pushing changes to Slaves so that they are i sync.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Slaves (The Followers)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Read-Only:&lt;/strong&gt; Generally restricted to &lt;strong&gt;Read&lt;/strong&gt; operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Replication:&lt;/strong&gt; They constantly pull or receive updates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability:&lt;/strong&gt; Add as many slaves as per the traffic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Basically, Master commands and the Slave Follows, like followers can be a lot, there can be a lot of slaves for one master.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Replication Methods
&lt;/h2&gt;

&lt;p&gt;To understand the "in-depth" side, you have to look at how data actually moves from Master to Slave:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Synchronous Replication:&lt;/strong&gt; The Master waits for all Slaves to confirm they have written the data before telling the user the "Write" was successful.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Pro: Zero data loss.&lt;/li&gt;
&lt;li&gt;Con: High latency (the system is only as fast as its slowest Slave).&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Asynchronous Replication:&lt;/strong&gt; The Master writes the data, sends a success message to the user immediately, and then sends the data to Slaves in the background.&lt;br&gt;
Pro: Very fast performance.&lt;br&gt;
Con: If the Master crashes before the data hits the Slaves, that data might be lost (Replication Lag).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Semi-Synchronous:&lt;/strong&gt; The Master waits for at least &lt;em&gt;one&lt;/em&gt; Slave to acknowledge the update before finishing.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  3. Why Use It? - Advs :)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Read Scalability:&lt;/strong&gt; If your app is "read-heavy" (like Twitter, where millions read a tweet but only one person writes it), you can spin up 10 Slaves to handle the load.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High Availability:&lt;/strong&gt; If a Slave dies, the system stays up. If the Master dies, one of the Slaves can be "promoted" to be the new Master.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Analytic Isolation:&lt;/strong&gt; You can run heavy, slow analytical queries on a Slave without slowing down the Master that is busy handling live user transactions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backups:&lt;/strong&gt; You can pause a Slave to take a full database backup without affecting the live performance of the Master.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. The Challenges - Dis Advs :(
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Eventual Consistency:&lt;/strong&gt; Because of replication lag, a user might write data to the Master and immediately try to read it from a Slave, but see the "old" data because the update hasn't arrived yet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write Bottleneck:&lt;/strong&gt; You can only have one Master for writes. If your app has massive write traffic (like a high-frequency trading bot), a single Master becomes a bottleneck.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Failover Complexity:&lt;/strong&gt; Promoting a Slave to a Master during a crash requires complex logic (often handled by tools like Sentinel or Zookeeper) to ensure no data is corrupted or "Split-Brain" scenarios occur.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Real-World Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A. Relational Databases (MySQL/PostgreSQL)
&lt;/h3&gt;

&lt;p&gt;A typical e-commerce site uses Master-Slave. When you update your profile (Write), it hits the Master. When you browse products (Read), the app queries one of the many Slaves.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs68jkltx53jpv5jpfxjj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs68jkltx53jpv5jpfxjj.png" alt=" " width="800" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  B. Redis (Caching)
&lt;/h3&gt;

&lt;p&gt;Redis uses this to ensure that if the primary cache node goes down, the data isn't lost from memory. Slaves provide high-speed read access to cached objects.&lt;/p&gt;

&lt;h3&gt;
  
  
  C. Distributed File Systems (HDFS)
&lt;/h3&gt;

&lt;p&gt;In the Hadoop Distributed File System, the &lt;strong&gt;NameNode&lt;/strong&gt; acts as the Master (holding the metadata/map of where files are), while &lt;strong&gt;DataNodes&lt;/strong&gt; act as Slaves (storing the actual chunks of data).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm019df4bjs0cr685alry.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm019df4bjs0cr685alry.png" alt=" " width="800" height="583"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;SO now finally, you can use the MASTER-SLAVE ARCHITECTURE&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>database</category>
      <category>systemdesign</category>
    </item>
  </channel>
</rss>
