<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Biswas Prasana Swain</title>
    <description>The latest articles on DEV Community by Biswas Prasana Swain (@biswasprasana001).</description>
    <link>https://dev.to/biswasprasana001</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%2F1286752%2Fc3cb46b8-660e-472c-8b97-9300c481495e.jpeg</url>
      <title>DEV Community: Biswas Prasana Swain</title>
      <link>https://dev.to/biswasprasana001</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/biswasprasana001"/>
    <language>en</language>
    <item>
      <title>RAG: The "Open Book" Exam for AI</title>
      <dc:creator>Biswas Prasana Swain</dc:creator>
      <pubDate>Thu, 19 Mar 2026 17:56:48 +0000</pubDate>
      <link>https://dev.to/biswasprasana001/rag-the-open-book-exam-for-ai-4p8a</link>
      <guid>https://dev.to/biswasprasana001/rag-the-open-book-exam-for-ai-4p8a</guid>
      <description>&lt;p&gt;Building a RAG (Retrieval-Augmented Generation) app is basically giving a genius-level intern (the LLM) a specific handbook so they stop making things up. If you build it with too much "enterprise" bloat, it’ll crawl. If you skimp, it’ll hallucinate. &lt;/p&gt;

&lt;p&gt;Here is the lean, mean architecture for a RAG full-stack app.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. What is a RAG System?
&lt;/h2&gt;

&lt;p&gt;Standard AI (like ChatGPT) works from memory, it's like a student taking a test based only on what they studied months ago. RAG (Retrieval-Augmented Generation) turns that test into an "open book" exam.&lt;/p&gt;

&lt;p&gt;Instead of the AI guessing or "hallucinating" when it doesn't know a fact about your specific business or private data, the system first retrieves the relevant page from your digital "book," hands it to the AI, and tells it: "Read this and then answer the question."&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The Ingestion Pipeline (The Wood Chipper)
&lt;/h2&gt;

&lt;p&gt;Before the user even opens the app, you have to prep your data. This is a one-way street where documents become searchable math.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Load &amp;amp; Chunk:&lt;/strong&gt; You take your messy PDFs or text files and chop them into bite-sized "chunks." If chunks are too big, they're noisy; too small, they lose context.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Embedding Model:&lt;/strong&gt; You run those chunks through a model (like OpenAI’s &lt;code&gt;text-embedding-3-small&lt;/code&gt;) to turn text into a long string of numbers (vectors). This represents the "meaning" of the text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vector Database:&lt;/strong&gt; You store those numbers in a specialized DB (Pinecone, Weaviate, or Chroma). This is your library where books are organized by "vibe" rather than title.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. The Backend Orchestrator (The Traffic Cop)
&lt;/h2&gt;

&lt;p&gt;This is usually a Python (FastAPI) or Node.js server. It’s the middleman that manages the "Retrieval" part of RAG.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;The Query:&lt;/strong&gt; User asks, "How do I fix my toaster?"&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Vectorization:&lt;/strong&gt; The backend sends that question to the same embedding model used in the ingestion phase. Now the question is a vector.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;The Search:&lt;/strong&gt; The backend asks the Vector DB: "Find me the 3 chunks of text that are mathematically closest to this question's vector."&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;The Prompt Stuffing:&lt;/strong&gt; The backend takes those 3 chunks and "stuffs" them into a prompt template for the LLM.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The Prompt looks like this:&lt;/strong&gt; &amp;gt; "You are a helpful assistant. Use the following context to answer the question. If it's not in the context, shut up and say you don't know. &lt;br&gt;
Context: [Chunk 1], [Chunk 2], [Chunk 3]&lt;br&gt;
Question: How do I fix my toaster?"&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  4. The LLM &amp;amp; Frontend (The Face)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Generation:&lt;/strong&gt; The LLM (GPT-4, Claude, Llama 3) reads the stuffed prompt and generates a coherent answer based &lt;em&gt;only&lt;/em&gt; on the provided context.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Frontend:&lt;/strong&gt; A React or Next.js app that displays the chat. It needs to handle "streaming" (where the text appears word-by-word) so the user doesn't think the app crashed while the LLM is thinking.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. Diagram*
&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%2F5o79uzdbimq12sxyyfhd.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%2F5o79uzdbimq12sxyyfhd.png" alt="RAG Architecture" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The Tech Stack Comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;Recommended (The "Gold Standard")&lt;/th&gt;
&lt;th&gt;Fast/Cheap (The "Hobbyist")&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Frontend&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Next.js + Tailwind&lt;/td&gt;
&lt;td&gt;Streamlit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Backend&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;FastAPI (Python)&lt;/td&gt;
&lt;td&gt;LangChain Expression Language (LCEL)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Vector DB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Pinecone or Weaviate&lt;/td&gt;
&lt;td&gt;PGVector (Postgres)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;LLM&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;GPT-4o or Claude 3.5 Sonnet&lt;/td&gt;
&lt;td&gt;Groq (Llama 3)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Why this works
&lt;/h2&gt;

&lt;p&gt;You aren't "retraining" the AI. You're just giving it a "Search" button. It stops the AI from lying because it has the source material sitting right in front of it. Anything more complex—like multi-agent workflows or graph-based retrieval—is usually overkill until you hit 100k+ documents.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Used AI for Diagram&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>vectordatabase</category>
      <category>fullstack</category>
    </item>
    <item>
      <title>The Invariance of Software Paradigms</title>
      <dc:creator>Biswas Prasana Swain</dc:creator>
      <pubDate>Sun, 15 Feb 2026 11:22:32 +0000</pubDate>
      <link>https://dev.to/biswasprasana001/the-invariance-of-software-paradigms-107a</link>
      <guid>https://dev.to/biswasprasana001/the-invariance-of-software-paradigms-107a</guid>
      <description>&lt;p&gt;In software engineering, the &lt;strong&gt;Invariance of Paradigms&lt;/strong&gt; is the concept that the fundamental way we build software remains constant, regardless of the specific programming language, library, or framework being used. While syntax (how you write it) changes every few years, the underlying architecture (what you are building) has not fundamentally changed in decades.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Frontend: The Component-Based Paradigm
&lt;/h2&gt;

&lt;p&gt;Whether you are using &lt;strong&gt;React&lt;/strong&gt;, &lt;strong&gt;Vue&lt;/strong&gt;, &lt;strong&gt;Angular&lt;/strong&gt;, or even mobile frameworks like &lt;strong&gt;SwiftUI&lt;/strong&gt;, the paradigm is &lt;strong&gt;Component-Based Architecture (CBA)&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Idea:&lt;/strong&gt; You don’t build a "page"; you build a collection of small, independent "blocks."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Blueprint:&lt;/strong&gt; A button is a block. A search bar is a block. You snap these blocks together to create a website.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Why it stays the same:&lt;/strong&gt; This approach ensures that if you fix the "button block," it updates everywhere. The framework is just the glue.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. Backend: The Service-Oriented Paradigm
&lt;/h2&gt;

&lt;p&gt;Whether the server is written in &lt;strong&gt;Node.js&lt;/strong&gt;, &lt;strong&gt;Python (Django)&lt;/strong&gt;, or &lt;strong&gt;Java (Spring)&lt;/strong&gt;, the paradigm is &lt;strong&gt;Service-Oriented&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Idea:&lt;/strong&gt; The backend acts as a "Request-Response" machine.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Workflow:&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Listener:&lt;/strong&gt; It waits for a specific URL (Route).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logic:&lt;/strong&gt; It checks if you’re allowed in (Auth) and does some math or data checking.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sender:&lt;/strong&gt; It sends back a standardized package, usually &lt;strong&gt;JSON&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Why it stays the same:&lt;/strong&gt; A server’s job is always to be a middleman between the user and the database.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Database: The Structured vs. Unstructured Paradigm
&lt;/h2&gt;

&lt;p&gt;Whether you use &lt;strong&gt;PostgreSQL&lt;/strong&gt; or &lt;strong&gt;MongoDB&lt;/strong&gt;, the paradigm is about &lt;strong&gt;Data Modeling&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Relational (SQL):&lt;/strong&gt; Think of an Excel spreadsheet. Everything has a strict place. If you change a column, you have to change the whole sheet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Document-Based (NoSQL):&lt;/strong&gt; Think of a folder full of Word documents. Each document can be slightly different, but they all live in the same folder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Why it stays the same:&lt;/strong&gt; We only have two ways to store things: in a strict list or a flexible pile.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. Comparison Across the Stack
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;Common Paradigm&lt;/th&gt;
&lt;th&gt;Tool Examples&lt;/th&gt;
&lt;th&gt;Core Responsibility&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Frontend&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Component-Based&lt;/td&gt;
&lt;td&gt;React, Vue, Svelte&lt;/td&gt;
&lt;td&gt;Presenting data to the human.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Backend&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;API / Service-First&lt;/td&gt;
&lt;td&gt;Express, Django, Go&lt;/td&gt;
&lt;td&gt;Business rules and security.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Database&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Relational / Document&lt;/td&gt;
&lt;td&gt;MySQL, MongoDB&lt;/td&gt;
&lt;td&gt;Remembering data forever.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;The "Tech Stack" is a fashion choice; the "Paradigm" is the physics. If you understand that the &lt;strong&gt;Frontend&lt;/strong&gt; is just a tree of components and the &lt;strong&gt;Backend&lt;/strong&gt; is just a series of pipes for data, you can switch from JavaScript to Python in a weekend. Stop chasing the newest library and start mastering the architecture.&lt;/p&gt;




&lt;h3&gt;
  
  
  Trustworthy References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;IBM Technology:&lt;/strong&gt; &lt;a href="https://www.ibm.com/think/topics/soa-vs-microservices" rel="noopener noreferrer"&gt;Microservices vs. SOA&lt;/a&gt; - Explaining the service paradigm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MDN Web Docs:&lt;/strong&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_components" rel="noopener noreferrer"&gt;Component-based architecture&lt;/a&gt; - The standard for modern UIs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Amazon AWS:&lt;/strong&gt; &lt;a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SQLtoNoSQL.WhyDynamoDB.html" rel="noopener noreferrer"&gt;SQL vs. NoSQL&lt;/a&gt; - Defining the two main storage paradigms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Martin Fowler:&lt;/strong&gt; &lt;a href="https://martinfowler.com/eaaCatalog/" rel="noopener noreferrer"&gt;Patterns of Enterprise Application Architecture&lt;/a&gt; - The "Bible" of why software patterns don't change.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>programming</category>
      <category>architecture</category>
      <category>software</category>
      <category>discuss</category>
    </item>
    <item>
      <title>From Monolith to Microservice</title>
      <dc:creator>Biswas Prasana Swain</dc:creator>
      <pubDate>Sun, 18 Jan 2026 12:38:59 +0000</pubDate>
      <link>https://dev.to/biswasprasana001/from-monolith-to-microservice-31ld</link>
      <guid>https://dev.to/biswasprasana001/from-monolith-to-microservice-31ld</guid>
      <description>&lt;p&gt;&lt;em&gt;A practical guide for people who have heard the word “microservices” too many times and finally want to do something about it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Most software systems don’t start as microservices. They start as a single application that does everything. User login, payments, emails, reports, admin screens, all tangled together like headphone wires in a pocket. That kind of system is called a monolith. It works fine until it doesn’t. Changes become risky, deployments feel like gambling, and one small bug can take down everything.&lt;/p&gt;

&lt;p&gt;Microservices are not magic. They are simply smaller applications that each do one job and communicate with others over the network. The mistake beginners make is trying to convert the entire monolith at once. That is how projects quietly die. The correct move is boring and slow: extract one microservice first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step one: understand what you already have
&lt;/h2&gt;

&lt;p&gt;Before touching code, you need to understand your monolith at a business level, not a technical one. Forget frameworks and folders for a moment. Ask a simple question: what does this system actually &lt;em&gt;do&lt;/em&gt; for users?&lt;/p&gt;

&lt;p&gt;Every monolith contains natural boundaries. User management, billing, notifications, inventory, reporting. These are not technical concepts, they are business capabilities. Your first microservice should represent one clear capability that can survive on its own.&lt;/p&gt;

&lt;p&gt;Good candidates share three traits. They have clear inputs and outputs, they change frequently or cause pain when changed, and they do not control the entire database. Authentication, email notifications, and file processing are common first picks because they are easy to isolate and rarely need direct access to everything else.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step two: define the responsibility, not the technology
&lt;/h2&gt;

&lt;p&gt;A microservice is not “a Spring Boot app” or “a Node service.” That thinking leads to messes. A microservice is a responsibility with rules.&lt;/p&gt;

&lt;p&gt;For example, instead of saying “I’ll create a User Service,” say “This service owns user creation, login, and password validation. No other part of the system is allowed to change users directly.” That sentence is more important than any code you will write.&lt;/p&gt;

&lt;p&gt;Once responsibility is clear, define how other parts of the system will talk to it. For beginners, HTTP with JSON is the safest choice. One endpoint to create a user, one to fetch user data, one to validate credentials. Simple, boring, reliable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step three: copy logic first, then remove it
&lt;/h2&gt;

&lt;p&gt;This part feels wrong but works.&lt;/p&gt;

&lt;p&gt;Do not delete code from the monolith immediately. First, copy the relevant logic into a new, separate application. Give it its own repository, its own build process, and its own runtime. At this stage, both systems can do the same thing. That duplication is temporary and acceptable.&lt;/p&gt;

&lt;p&gt;Once the new service works on its own, change the monolith so that instead of running the old code, it calls the new service over HTTP. It's called &lt;strong&gt;Strangler Fit Pattern&lt;/strong&gt;. If the behavior stays the same, users never notice. That is the goal. Silence.&lt;/p&gt;

&lt;p&gt;Only after this works reliably should you remove the old logic from the monolith. If something breaks, you know exactly where to look, which is a luxury in software.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step four: separate the data carefully
&lt;/h2&gt;

&lt;p&gt;Beginners often trip over databases. A true microservice owns its data. That means no other service should directly read or write its tables.&lt;/p&gt;

&lt;p&gt;For your first microservice, you have two realistic options. The safest is giving it its own database, even if it feels redundant. The second is letting it access the existing database but only specific tables, with a clear plan to move them later. What you must not do is allow multiple services to casually share tables. That recreates the monolith, just with more networking bills.&lt;/p&gt;

&lt;p&gt;Data duplication across services is normal. Synchronization is handled through APIs or events, not shared schemas.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step five: deploy it independently
&lt;/h2&gt;

&lt;p&gt;If your new service cannot be deployed without deploying the monolith, you have not created a microservice. You have created a distributed illusion.&lt;/p&gt;

&lt;p&gt;Deploy the service separately, even if it runs on the same server at first. Use a different port, a different process, and a different release cycle. The first time you fix a bug in the microservice without touching the monolith, the whole exercise finally makes sense.&lt;/p&gt;

&lt;p&gt;Monitoring and logging matter here. When things go wrong, and they will, you need to know which service failed and why. Centralized logs and basic health checks are enough for a first step. No need to summon Kubernetes gods yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step six: repeat slowly, or stop
&lt;/h2&gt;

&lt;p&gt;After your first success, resist the urge to extract everything. Microservices increase operational complexity. If the pain you removed is smaller than the pain you introduced, stop. One or two well-chosen services already deliver most of the benefit.&lt;/p&gt;

&lt;p&gt;Microservices are a tool, not a moral upgrade.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;The hardest part of moving from a monolith to microservices is not coding. It is discipline. Clear boundaries, patience, and the willingness to accept temporary duplication are what make the transition survivable.&lt;/p&gt;

&lt;p&gt;If you can extract one service cleanly, you can extract more. If you cannot extract one, extracting ten will not save you.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;These are trustworthy, widely cited, and written by people who have broken real systems before fixing them.&lt;/p&gt;

&lt;p&gt;Martin Fowler's Guide to Microservices: The "bible" of this topic. Fowler explains it clearly without the hype. &lt;a href="https://martinfowler.com/articles/microservices.html" rel="noopener noreferrer"&gt;martinfowler.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sam Newman's "Building Microservices" - This book is the gold standard. He coined many of the patterns used today.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aws.amazon.com/microservices/" rel="noopener noreferrer"&gt;AWS on Microservices&lt;/a&gt; - Practical, "how-to" guides from the people who host most of the world's services.&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>beginners</category>
      <category>distributedsystems</category>
      <category>architecture</category>
    </item>
    <item>
      <title>What's the solution to CAP theorem in Read Replicas?</title>
      <dc:creator>Biswas Prasana Swain</dc:creator>
      <pubDate>Thu, 25 Dec 2025 17:10:23 +0000</pubDate>
      <link>https://dev.to/biswasprasana001/whats-the-solution-to-cap-theorem-in-read-replicas-1ml2</link>
      <guid>https://dev.to/biswasprasana001/whats-the-solution-to-cap-theorem-in-read-replicas-1ml2</guid>
      <description>&lt;p&gt;CAP theorem says a distributed system can give you &lt;strong&gt;Consistency&lt;/strong&gt;, &lt;strong&gt;Availability&lt;/strong&gt;, or &lt;strong&gt;Partition tolerance&lt;/strong&gt;. Pick any two. Not three. Not “mostly three.” Two. The internet doesn’t care about your optimism.&lt;/p&gt;

&lt;p&gt;Now let’s talk about &lt;strong&gt;read replicas&lt;/strong&gt;, because this is where confusion usually starts.&lt;/p&gt;

&lt;h3&gt;
  
  
  The real-world story
&lt;/h3&gt;

&lt;p&gt;Imagine you run an e-commerce app. Nothing fancy. Users browse products, add to cart, place orders. You have one main database. Life is peaceful. Traffic grows. Database starts sweating. So you do the obvious grown-up thing: add &lt;strong&gt;read replicas&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;One &lt;strong&gt;primary database&lt;/strong&gt; handles writes. Multiple &lt;strong&gt;read replicas&lt;/strong&gt; handle reads. Suddenly your system feels faster. You feel smarter. LinkedIn post draft opens automatically.&lt;/p&gt;

&lt;p&gt;Then a user places an order and immediately refreshes the order page. Surprise: the order is missing. Panic. Bug? Race condition? Database haunted?&lt;/p&gt;

&lt;p&gt;No. Welcome to CAP.&lt;/p&gt;

&lt;h3&gt;
  
  
  What just happened
&lt;/h3&gt;

&lt;p&gt;The write went to the &lt;strong&gt;primary&lt;/strong&gt; database.&lt;br&gt;
The read went to a &lt;strong&gt;replica&lt;/strong&gt;.&lt;br&gt;
Replication is &lt;strong&gt;asynchronous&lt;/strong&gt;, because synchronous replication would make your system slow and fragile.&lt;/p&gt;

&lt;p&gt;So for a short time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Primary has the new order&lt;/li&gt;
&lt;li&gt;Replica does not&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is &lt;strong&gt;eventual consistency&lt;/strong&gt; in action. The system chose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Availability&lt;/strong&gt;: reads always work&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Partition tolerance&lt;/strong&gt;: network issues won’t kill you&lt;/li&gt;
&lt;li&gt;And it sacrificed &lt;strong&gt;strong consistency&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Read replicas don’t break CAP. They &lt;strong&gt;make a choice inside CAP&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  So what’s the “solution” in read replicas?
&lt;/h3&gt;

&lt;p&gt;Short answer: &lt;strong&gt;there is no single solution&lt;/strong&gt;. There are &lt;strong&gt;trade-offs&lt;/strong&gt;, and you pick based on business needs, not ego.&lt;/p&gt;

&lt;p&gt;Long answer, explained like a normal human.&lt;/p&gt;

&lt;h4&gt;
  
  
  Option 1: Accept eventual consistency (most common)
&lt;/h4&gt;

&lt;p&gt;This is what companies like Amazon, Netflix, Instagram do for many flows.&lt;/p&gt;

&lt;p&gt;You allow stale reads for a short time.&lt;br&gt;
You design UI and flows knowing data may lag.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Show “Order placed, updating details…” message&lt;/li&gt;
&lt;li&gt;Refresh after a few seconds&lt;/li&gt;
&lt;li&gt;Avoid instant read-after-write expectations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This gives you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High availability&lt;/li&gt;
&lt;li&gt;Massive scale&lt;/li&gt;
&lt;li&gt;Calm databases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You lose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Immediate correctness everywhere&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is not laziness. This is engineering maturity.&lt;/p&gt;

&lt;h4&gt;
  
  
  Option 2: Read-your-writes consistency (smart routing)
&lt;/h4&gt;

&lt;p&gt;For some critical flows, you cheat a little.&lt;/p&gt;

&lt;p&gt;If a user just wrote data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Route their next read to the &lt;strong&gt;primary&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Or use a session flag like “read from leader for 5 seconds”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is common in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Banking dashboards&lt;/li&gt;
&lt;li&gt;Order confirmation pages&lt;/li&gt;
&lt;li&gt;Profile update screens&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now you get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consistency where it matters&lt;/li&gt;
&lt;li&gt;Availability everywhere else&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Downside:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More complexity&lt;/li&gt;
&lt;li&gt;Primary database gets more load&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Still worth it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Option 3: Synchronous replication (rare, expensive)
&lt;/h4&gt;

&lt;p&gt;You force replicas to confirm writes before success.&lt;/p&gt;

&lt;p&gt;Now reads are always consistent.&lt;/p&gt;

&lt;p&gt;You also get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Higher latency&lt;/li&gt;
&lt;li&gt;Lower availability&lt;/li&gt;
&lt;li&gt;System crying during network hiccups&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Used only when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Incorrect data is worse than downtime&lt;/li&gt;
&lt;li&gt;Think financial ledgers, not social feeds&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most systems wisely avoid this.&lt;/p&gt;

&lt;h3&gt;
  
  
  The key realization
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Read replicas don’t solve CAP.&lt;br&gt;
They let you choose &lt;em&gt;where&lt;/em&gt; you want to bend.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CAP is not a bug to fix.&lt;br&gt;
It’s gravity.&lt;/p&gt;

&lt;p&gt;Good systems don’t fight it. They design around it.&lt;/p&gt;

&lt;h3&gt;
  
  
  The adult takeaway
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;If you want &lt;strong&gt;scale&lt;/strong&gt;, you accept &lt;strong&gt;eventual consistency&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;If you want &lt;strong&gt;correctness&lt;/strong&gt;, you sacrifice &lt;strong&gt;availability&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;If you want &lt;strong&gt;both&lt;/strong&gt;, you add &lt;strong&gt;complex routing logic&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;If you want all three, you’re selling a course, not building software&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Read replicas are not magic.&lt;br&gt;
They’re a very honest trade.&lt;/p&gt;

&lt;p&gt;And honesty is rare in distributed systems.&lt;/p&gt;




&lt;h3&gt;
  
  
  References (the boring but trustworthy kind)
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Eric Brewer, “CAP Twelve Years Later: How the Rules Have Changed”&lt;br&gt;
&lt;a href="https://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed/" rel="noopener noreferrer"&gt;https://www.infoq.com/articles/cap-twelve-years-later-how-the-rules-have-changed/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Martin Kleppmann, &lt;em&gt;Designing Data-Intensive Applications&lt;/em&gt;&lt;br&gt;
&lt;a href="https://dataintensive.net/" rel="noopener noreferrer"&gt;https://dataintensive.net/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Amazon Dynamo Paper&lt;br&gt;
&lt;a href="https://www.allthingsdistributed.com/files/amazon-dynamo-sosp2007.pdf" rel="noopener noreferrer"&gt;https://www.allthingsdistributed.com/files/amazon-dynamo-sosp2007.pdf&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Google Cloud Docs on Replication and Consistency &lt;a href="https://docs.cloud.google.com/datastore/docs/concepts/structuring_for_strong_consistency" rel="noopener noreferrer"&gt;https://docs.cloud.google.com/datastore/docs/concepts/structuring_for_strong_consistency&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Netflix Tech Blog on Eventual Consistency &lt;a href="https://netflixtechblog.com/s3mper-consistency-in-the-cloud-b6a1076aa4f8" rel="noopener noreferrer"&gt;https://netflixtechblog.com/s3mper-consistency-in-the-cloud&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>database</category>
      <category>architecture</category>
      <category>computerscience</category>
      <category>learning</category>
    </item>
    <item>
      <title>From Binary to Brilliance: How Compilers Learned to Write Compilers a.k.a Bootstrapping</title>
      <dc:creator>Biswas Prasana Swain</dc:creator>
      <pubDate>Mon, 27 Oct 2025 14:10:22 +0000</pubDate>
      <link>https://dev.to/biswasprasana001/from-binary-to-brilliance-how-compilers-learned-to-write-compilers-aka-bootstrapping-3ef3</link>
      <guid>https://dev.to/biswasprasana001/from-binary-to-brilliance-how-compilers-learned-to-write-compilers-aka-bootstrapping-3ef3</guid>
      <description>&lt;p&gt;Programming languages didn’t pop out of thin air. Humans painfully invented them so we could boss computers around without manually flipping switches like cavemen with PhDs. Here’s the story.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Early Days: Speaking Robot Grunt Language
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1940s–1950s&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Computers only understood &lt;strong&gt;machine code&lt;/strong&gt; (just 0s and 1s).&lt;/li&gt;
&lt;li&gt;Then humans realized life shouldn’t be torture, so they invented &lt;strong&gt;assembly language&lt;/strong&gt; (short words like ADD, MOV).&lt;/li&gt;
&lt;li&gt;These early languages were written &lt;em&gt;directly&lt;/em&gt; in machine code or assembly because what else was available? Exactly nothing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Languages: Machine Code, Assembly&lt;br&gt;
Implementation: Written in &lt;strong&gt;machine code or assembly&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. High-Level Languages: Humans Stop Suffering
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1950s–1960s&lt;/strong&gt;&lt;br&gt;
People said: “Let the computer do the boring work.”&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;FORTRAN&lt;/strong&gt; (science &amp;amp; math)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;COBOL&lt;/strong&gt; (business)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LISP&lt;/strong&gt; (AI, parentheses galore)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Compilers for these languages were mostly written in &lt;strong&gt;assembly&lt;/strong&gt;, because assembly was the only grown-up in the room back then.&lt;/p&gt;

&lt;p&gt;Languages: FORTRAN, COBOL, LISP&lt;br&gt;
Implementation: &lt;strong&gt;Assembly&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Compilers Learn to Write Compilers
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1970s&lt;/strong&gt;&lt;br&gt;
Here comes the big brain move.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;New languages started being written &lt;strong&gt;in the language itself&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;This trick is called &lt;strong&gt;bootstrapping&lt;/strong&gt; (more on that soon).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;C&lt;/strong&gt; became a superstar. First versions in assembly, then rewritten &lt;strong&gt;in C&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pascal&lt;/strong&gt;: similar path.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Languages: C, Pascal&lt;br&gt;
Implementation: Started in &lt;strong&gt;assembly&lt;/strong&gt;, later &lt;strong&gt;self-hosted&lt;/strong&gt; (written in themselves)&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Object-Oriented Show-Off Era
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1980s–1990s&lt;/strong&gt;&lt;br&gt;
Humans start organizing code like “objects,” because organizing life is too hard.&lt;/p&gt;

&lt;p&gt;Languages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;C++&lt;/strong&gt; (C but angry and complicated)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Java&lt;/strong&gt; (Write once, debug everywhere)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Python&lt;/strong&gt; (finally readable)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript&lt;/strong&gt; (only language people argue about daily)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Implementation languages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;C++: wrote itself using C++ (after initial C)&lt;/li&gt;
&lt;li&gt;Java: implemented in &lt;strong&gt;C/C++&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Python: implemented mostly in &lt;strong&gt;C&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;JavaScript: implemented in &lt;strong&gt;C/C++&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. The Modern Chaos
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;2000s–Now&lt;/strong&gt;&lt;br&gt;
Thousands of languages because developers love reinventing the wheel.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Rust&lt;/strong&gt;: implemented in Rust (after initial help from C++)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Go&lt;/strong&gt;: implemented in C first, later in Go itself&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Swift&lt;/strong&gt;: implemented in C++ and Swift&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kotlin&lt;/strong&gt;, &lt;strong&gt;TypeScript&lt;/strong&gt;, etc.: often implemented using existing languages like Java or JavaScript&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What is Bootstrapping?
&lt;/h2&gt;

&lt;p&gt;This part is actually cool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bootstrapping&lt;/strong&gt; is when a programming language is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First implemented using an older language (often C or assembly)&lt;/li&gt;
&lt;li&gt;Then rewritten using &lt;strong&gt;itself&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Then its own compiler builds the new compiler&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Like a kid growing up and then becoming their own parent’s boss.&lt;/p&gt;

&lt;p&gt;Example with C:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Write a tiny C compiler in assembly&lt;/li&gt;
&lt;li&gt;Use it to compile a better C compiler written in C&lt;/li&gt;
&lt;li&gt;Repeat until humans are free and the compiler is a beast&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Why do this?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Self-hosted compilers are easier to maintain&lt;/li&gt;
&lt;li&gt;They prove the language is powerful enough to build real systems&lt;/li&gt;
&lt;/ul&gt;




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

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;th&gt;First Compiler Implementation&lt;/th&gt;
&lt;th&gt;Later/Self Implementation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Assembly&lt;/td&gt;
&lt;td&gt;Machine code&lt;/td&gt;
&lt;td&gt;Itself (assembly)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;FORTRAN, COBOL&lt;/td&gt;
&lt;td&gt;Assembly&lt;/td&gt;
&lt;td&gt;Assembly/C&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;Assembly&lt;/td&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C++&lt;/td&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;C++&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Java&lt;/td&gt;
&lt;td&gt;C/C++&lt;/td&gt;
&lt;td&gt;Java (partially)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Python&lt;/td&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;Python/C&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Go&lt;/td&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;Go&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rust&lt;/td&gt;
&lt;td&gt;C++&lt;/td&gt;
&lt;td&gt;Rust&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Final Wisdom
&lt;/h2&gt;

&lt;p&gt;Programming language history is basically:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start from binary pain&lt;/li&gt;
&lt;li&gt;Invent slightly less painful systems&lt;/li&gt;
&lt;li&gt;Use those systems to build better systems&lt;/li&gt;
&lt;li&gt;End up with JavaScript frameworks that change every week anyway&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hope your brain upgraded a bit.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>learning</category>
      <category>resources</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>How React Native Talks to Your iPhone and Android… And How It’s Changed</title>
      <dc:creator>Biswas Prasana Swain</dc:creator>
      <pubDate>Sun, 07 Sep 2025 19:50:55 +0000</pubDate>
      <link>https://dev.to/biswasprasana001/how-react-native-talks-to-your-iphone-and-android-and-how-its-changed-4jn1</link>
      <guid>https://dev.to/biswasprasana001/how-react-native-talks-to-your-iphone-and-android-and-how-its-changed-4jn1</guid>
      <description>&lt;p&gt;React Native (RN) is a framework that lets developers write apps &lt;strong&gt;once&lt;/strong&gt; and run them on both iOS (iPhones) and Android. Sounds magical, right? But under the hood, there’s a lot of wizardry happening to make this possible.&lt;/p&gt;

&lt;p&gt;Let’s break it down, step by step.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. The Problem RN Solves
&lt;/h2&gt;

&lt;p&gt;Normally, iOS and Android apps speak completely different “languages.”&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;iOS apps speak &lt;strong&gt;Swift&lt;/strong&gt; or &lt;strong&gt;Objective-C&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Android apps speak &lt;strong&gt;Java&lt;/strong&gt; or &lt;strong&gt;Kotlin&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before React Native, if you wanted your app on both platforms, you basically had to &lt;strong&gt;build the same thing twice&lt;/strong&gt;, like doing your taxes in two different countries at the same time. Painful.&lt;/p&gt;

&lt;p&gt;React Native says: “Hey, write in &lt;strong&gt;JavaScript&lt;/strong&gt;—the language web developers already know, and I’ll handle translating it to what the phone understands.”&lt;/p&gt;




&lt;h2&gt;
  
  
  2. How It Used to Work (The Old Way)
&lt;/h2&gt;

&lt;p&gt;Originally, React Native used something called the &lt;strong&gt;bridge&lt;/strong&gt;. Think of it as a translator sitting between two people who speak completely different languages.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your code is written in &lt;strong&gt;JavaScript&lt;/strong&gt; (easy for web devs).&lt;/li&gt;
&lt;li&gt;The JavaScript runs in its own little world called a &lt;strong&gt;JavaScript engine&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Whenever your app needs to display something, like a button, or fetch data, the JS engine sends a message across the &lt;strong&gt;bridge&lt;/strong&gt; to the phone’s native code.&lt;/li&gt;
&lt;li&gt;Native code (Swift/Java) handles the actual work, drawing things on screen, accessing the camera, etc.&lt;/li&gt;
&lt;li&gt;The results get sent back across the bridge to JS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt; This bridge was slow for complex apps. Imagine ordering food through a translator who walks back and forth carrying messages for every tiny thing. It works, but if you want a smooth 60 FPS experience, it can choke.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. How It Works Now (The Modern Way)
&lt;/h2&gt;

&lt;p&gt;React Native has evolved. The bridge still exists, but now there’s &lt;strong&gt;direct compilation and new architectures&lt;/strong&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  a) &lt;strong&gt;Fabric (New UI Layer)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;React Native now talks to the native UI in a smarter, asynchronous way.&lt;/li&gt;
&lt;li&gt;Instead of messaging every tiny change one by one, it &lt;strong&gt;schedules changes in batches&lt;/strong&gt;. Think of it like ordering your entire meal at once instead of one forkful at a time.&lt;/li&gt;
&lt;li&gt;This makes animations smoother and apps faster.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  b) &lt;strong&gt;JSI (JavaScript Interface)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Previously, JS lived in a separate world. Now, with JSI, JS can &lt;strong&gt;directly call native functions&lt;/strong&gt; without going through the slow bridge.&lt;/li&gt;
&lt;li&gt;It’s like having the translator suddenly become a polyglot who understands both languages perfectly and speaks instantly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  c) &lt;strong&gt;TurboModules&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In the past, every native feature had to go through the bridge. Now, modules can be &lt;strong&gt;lazy-loaded and accessed directly&lt;/strong&gt;, so they only “wake up” when needed.&lt;/li&gt;
&lt;li&gt;Faster startup, less memory usage.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. What Does This Mean for Developers and Users?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  For Developers:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Less frustration with laggy updates between JS and native code.&lt;/li&gt;
&lt;li&gt;Can write more complex animations and UI interactions without the dreaded “jank.”&lt;/li&gt;
&lt;li&gt;Easier to maintain one codebase that feels native on both platforms.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  For Users:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Smoother apps, less battery drain.&lt;/li&gt;
&lt;li&gt;Faster launch times.&lt;/li&gt;
&lt;li&gt;Animations that don’t make you feel like your phone’s having a seizure.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. Analogy to Make Your Brain Happy
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Old RN:&lt;/strong&gt; JS is a tourist. Wants a burger. Asks a translator. Translator goes to the kitchen, grabs burger, comes back, repeats for fries, soda, napkins… painfully slow if there’s a lot to order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;New RN:&lt;/strong&gt; JS is now a multi-lingual chef. Orders can be spoken directly to the kitchen, batches are prepped efficiently, and the meal arrives hot and fast.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. TL;DR for the Lazy Brain
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;React Native = write JS once, run everywhere.&lt;/li&gt;
&lt;li&gt;Old RN = slow bridge, everything had to walk messages back and forth.&lt;/li&gt;
&lt;li&gt;Modern RN = JSI + Fabric + TurboModules = direct communication, smarter scheduling, faster apps.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result: apps that &lt;strong&gt;look and feel native&lt;/strong&gt;, without the headache of writing twice.&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>programming</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Understanding Core JavaScript Design Patterns</title>
      <dc:creator>Biswas Prasana Swain</dc:creator>
      <pubDate>Wed, 27 Aug 2025 18:14:10 +0000</pubDate>
      <link>https://dev.to/biswasprasana001/understanding-core-javascript-design-patterns-l4l</link>
      <guid>https://dev.to/biswasprasana001/understanding-core-javascript-design-patterns-l4l</guid>
      <description>&lt;p&gt;If you’ve been coding in JavaScript for a while, you might have heard about &lt;strong&gt;design patterns&lt;/strong&gt;. But what are they?&lt;/p&gt;

&lt;p&gt;Think of design patterns like &lt;strong&gt;recipes&lt;/strong&gt; for solving common problems in programming. Just like a cookie recipe tells you how to mix ingredients to get a perfect cookie, design patterns tell you how to structure your code so it works well, is easy to read, and doesn’t break easily.&lt;/p&gt;

&lt;p&gt;Here, we’ll look at four super important patterns: &lt;strong&gt;Singleton, Module, Factory, and Observer&lt;/strong&gt;. Let’s dive in!&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;1. Singleton Pattern&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Idea:&lt;/strong&gt; Only allow &lt;strong&gt;one instance&lt;/strong&gt; of something to exist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; Imagine the principal of a school. There’s only one principal, and everyone talks to that same person if they need help.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use it?&lt;/strong&gt; When you want one object to control something globally, like a game score manager, or a database connection.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;GameManager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// this will hold the single instance&lt;/span&gt;

  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;increaseScore&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Score: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="na"&gt;resetScore&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Score reset`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;game1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;GameManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;game1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;increaseScore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Score: 1&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;game2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;GameManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;game2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;increaseScore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Score: 2 (same instance!)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Notice how &lt;code&gt;game1&lt;/code&gt; and &lt;code&gt;game2&lt;/code&gt; are &lt;strong&gt;the same instance&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;2. Module Pattern&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Idea:&lt;/strong&gt; Keep code organized and hide some parts from the outside world.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; A backpack. You can keep some things inside (like a pencil case), but only let people see or use what you want them to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use it?&lt;/strong&gt; To &lt;strong&gt;encapsulate&lt;/strong&gt; code, keeping it neat and preventing accidental changes from outside.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Calculator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Private functions&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;subtract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Public API&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;difference&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;subtract&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;        &lt;span class="c1"&gt;// 8&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;difference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Here, &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;subtract&lt;/code&gt; are &lt;strong&gt;hidden inside the module&lt;/strong&gt;, but we can still use them through &lt;code&gt;Calculator.sum&lt;/code&gt; and &lt;code&gt;Calculator.difference&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;3. Factory Pattern&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Idea:&lt;/strong&gt; Create objects &lt;strong&gt;without specifying the exact class/type&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; A toy factory. You say "make me a toy," and it gives you a toy depending on your choice like car, doll, or robot, without you building it yourself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use it?&lt;/strong&gt; When you need &lt;strong&gt;lots of similar objects&lt;/strong&gt; but don’t want to manually create each one.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Woof!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Meow!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AnimalFactory&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nf"&gt;createAnimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dog&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cat&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Unknown animal type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myPet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;AnimalFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createAnimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dog&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myPet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Woof!&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;neighborPet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;AnimalFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createAnimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cat&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;neighborPet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Meow!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ You don’t need to know the details of &lt;code&gt;Dog&lt;/code&gt; or &lt;code&gt;Cat&lt;/code&gt;. The factory does the work.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;4. Observer Pattern&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Idea:&lt;/strong&gt; Let objects &lt;strong&gt;subscribe&lt;/strong&gt; to events and react when those events happen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analogy:&lt;/strong&gt; Think of YouTube notifications. You subscribe to a channel, and whenever the creator uploads a new video, &lt;strong&gt;you get notified&lt;/strong&gt; automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use it?&lt;/strong&gt; When one object changes and many others need to know about it.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Subject&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;unsubscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obs&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;obs&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Observer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; received: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;news&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Subject&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;alice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Observer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bob&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Observer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;news&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;alice&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;news&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bob&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;news&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New JavaScript tutorial!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="c1"&gt;// Alice received: New JavaScript tutorial!&lt;/span&gt;
&lt;span class="c1"&gt;// Bob received: New JavaScript tutorial!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Any observer subscribed to &lt;code&gt;news&lt;/code&gt; automatically gets updates.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Design patterns might sound fancy, but they’re really just &lt;strong&gt;smart ways to organize your code&lt;/strong&gt;. Here’s a quick recap:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;th&gt;Idea&lt;/th&gt;
&lt;th&gt;Example Use Case&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Singleton&lt;/td&gt;
&lt;td&gt;Only one instance&lt;/td&gt;
&lt;td&gt;Game manager, DB connection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Module&lt;/td&gt;
&lt;td&gt;Hide private stuff, expose public API&lt;/td&gt;
&lt;td&gt;Calculator, Utilities&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Factory&lt;/td&gt;
&lt;td&gt;Create objects without knowing details&lt;/td&gt;
&lt;td&gt;Toy factory, Animal creator&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Observer&lt;/td&gt;
&lt;td&gt;Notify objects of changes&lt;/td&gt;
&lt;td&gt;Chat apps, YouTube subs&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




</description>
      <category>designpatterns</category>
      <category>javascript</category>
      <category>programming</category>
      <category>cleancoding</category>
    </item>
    <item>
      <title>Designing a Ride Hailing Service System (e.g., Uber/Lyft): A Beginner-Friendly Guide</title>
      <dc:creator>Biswas Prasana Swain</dc:creator>
      <pubDate>Sat, 26 Jul 2025 20:18:16 +0000</pubDate>
      <link>https://dev.to/biswasprasana001/designing-a-ride-hailing-service-system-eg-uberlyft-a-beginner-friendly-guide-252o</link>
      <guid>https://dev.to/biswasprasana001/designing-a-ride-hailing-service-system-eg-uberlyft-a-beginner-friendly-guide-252o</guid>
      <description>&lt;h2&gt;
  
  
  🚖 &lt;strong&gt;What Is a Ride Hailing System?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;ride hailing service&lt;/strong&gt; (like Uber or Lyft) is a platform that connects &lt;strong&gt;passengers&lt;/strong&gt; with &lt;strong&gt;drivers&lt;/strong&gt; through an app or website. Instead of waving for a cab on the street, you can request a ride with a few taps on your phone.&lt;/p&gt;

&lt;p&gt;Behind the scenes, this simple experience is powered by a &lt;strong&gt;complex distributed system&lt;/strong&gt; involving real-time location tracking, matching algorithms, payments, notifications, and much more.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 &lt;strong&gt;Goal of This Article&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To explain, in simple terms, &lt;strong&gt;how to design the core components of a ride hailing service&lt;/strong&gt;, focusing on the most important of system design concepts that make up the real-world solution.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧱 &lt;strong&gt;Core Components of the System&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let's start with a &lt;strong&gt;high-level overview&lt;/strong&gt; of the major pieces involved in such a system:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;User App (Passenger)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Driver App&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Backend System&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Matching Engine&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Geolocation &amp;amp; Maps&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Trip Management&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Notifications&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Payments&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Database &amp;amp; Storage&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Monitoring &amp;amp; Logging&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🗺️ &lt;strong&gt;Step-by-Step: Designing the Core System&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. 🧍 &lt;strong&gt;User Signup &amp;amp; Authentication&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happens?&lt;/strong&gt;&lt;br&gt;
Both drivers and passengers need to &lt;strong&gt;register and log in&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Concepts:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;OAuth 2.0&lt;/strong&gt; or token-based authentication.&lt;/li&gt;
&lt;li&gt;Store user profiles (name, email, rating, etc.).&lt;/li&gt;
&lt;li&gt;Drivers may need additional verification (license, insurance).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧠 Simple user authentication with token validation (like JWT) covers the majority of access control needs.&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%2Frio3zm79qpi7blpc2kwr.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%2Frio3zm79qpi7blpc2kwr.png" alt="User Auth" width="800" height="616"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  2. 📍 &lt;strong&gt;Real-Time Location Tracking&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happens?&lt;/strong&gt;&lt;br&gt;
The app continuously updates the &lt;strong&gt;location&lt;/strong&gt; of drivers and passengers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Concepts:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the phone’s &lt;strong&gt;GPS&lt;/strong&gt; and &lt;strong&gt;mobile network&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Send location updates every few seconds.&lt;/li&gt;
&lt;li&gt;Backend uses &lt;strong&gt;WebSockets&lt;/strong&gt; or &lt;strong&gt;MQTT&lt;/strong&gt; for real-time updates.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧠 Focus on getting accurate, low-latency GPS updates to the backend efficiently.&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%2F2uppmpxq8dgwxep0z6bl.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%2F2uppmpxq8dgwxep0z6bl.png" alt="Real Time Location Track" width="800" height="1042"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  3. 🔄 &lt;strong&gt;Matching Engine (Dispatch System)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happens?&lt;/strong&gt;&lt;br&gt;
The system &lt;strong&gt;matches a passenger&lt;/strong&gt; with the &lt;strong&gt;nearest available driver&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A passenger sends a ride request.&lt;/li&gt;
&lt;li&gt;Backend queries nearby drivers (using location data).&lt;/li&gt;
&lt;li&gt;It selects the best one based on distance, rating, etc.&lt;/li&gt;
&lt;li&gt;Driver receives the request and accepts or declines.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tech used:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Geospatial indexing&lt;/strong&gt; (e.g., using Haversine formula + R-tree or GeoHash)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Priority queues&lt;/strong&gt; for driver selection.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;Redis&lt;/strong&gt; or &lt;strong&gt;Elasticsearch&lt;/strong&gt; for fast geo queries.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧠 Start by matching based on nearest distance and availability. Add complexity like surge pricing, ratings, or driver preferences later.&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%2F7zzjwnusv6w3np07ep3q.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%2F7zzjwnusv6w3np07ep3q.png" alt="Matching Engine" width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  4. 🗺️ &lt;strong&gt;Maps and Routing&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happens?&lt;/strong&gt;&lt;br&gt;
The system shows estimated time of arrival (ETA), routes, and pricing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Concepts:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use APIs like &lt;strong&gt;Google Maps&lt;/strong&gt; or &lt;strong&gt;OpenStreetMap&lt;/strong&gt; for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Directions&lt;/li&gt;
&lt;li&gt;Distance&lt;/li&gt;
&lt;li&gt;Estimated time&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Helps in fare calculation and trip display.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;🧠 Use a third-party API to handle maps and routes instead of building it from scratch.&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%2F4jkhaxqw05blx14mxk56.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%2F4jkhaxqw05blx14mxk56.png" alt="Maps &amp;amp; Routing" width="800" height="373"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  5. 🚘 &lt;strong&gt;Trip Lifecycle Management&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;States in a Trip:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ride requested&lt;/li&gt;
&lt;li&gt;Driver assigned&lt;/li&gt;
&lt;li&gt;Driver en route&lt;/li&gt;
&lt;li&gt;Passenger picked up&lt;/li&gt;
&lt;li&gt;Trip in progress&lt;/li&gt;
&lt;li&gt;Trip completed or cancelled&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Key Concepts:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;finite state machines&lt;/strong&gt; to track trip states.&lt;/li&gt;
&lt;li&gt;Log transitions to ensure traceability.&lt;/li&gt;
&lt;li&gt;Handle edge cases like timeouts, cancellations, or no-shows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧠 Managing trip states as a finite-state machine helps maintain a predictable flow and debug issues easily.&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%2F22e9rzxf8eaam6skb5eg.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%2F22e9rzxf8eaam6skb5eg.png" alt="Trip Lifecycle Mgmt" width="800" height="605"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  6. 🔔 &lt;strong&gt;Notifications System&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happens?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User gets real-time updates (e.g., “Driver arriving”, “Trip started”).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key Concepts:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;push notifications&lt;/strong&gt; (e.g., Firebase Cloud Messaging).&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;in-app alerts&lt;/strong&gt; or &lt;strong&gt;SMS&lt;/strong&gt; for redundancy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧠 Real-time push notifications with retries cover most of alerting needs.&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%2Fvkh5a1cqtww2wqbazijq.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%2Fvkh5a1cqtww2wqbazijq.png" alt="Notification System" width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  7. 💳 &lt;strong&gt;Payments and Fare Calculation&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What happens?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fare is calculated based on time, distance, surge, etc.&lt;/li&gt;
&lt;li&gt;Payment is processed automatically at the end.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key Concepts:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Integrate with payment gateways like &lt;strong&gt;Stripe&lt;/strong&gt; or &lt;strong&gt;PayPal&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Store payment methods securely (use &lt;strong&gt;PCI DSS&lt;/strong&gt; compliance).&lt;/li&gt;
&lt;li&gt;Split fare between platform and driver.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧠 Outsource payments to a trusted provider early on to avoid security risks.&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%2Ftg3vrxf5mua1fin9j8s9.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%2Ftg3vrxf5mua1fin9j8s9.png" alt="Payment &amp;amp; Fare Calculation" width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  8. 🧠 &lt;strong&gt;Database Design&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What to store?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Users&lt;/li&gt;
&lt;li&gt;Drivers&lt;/li&gt;
&lt;li&gt;Trips&lt;/li&gt;
&lt;li&gt;Locations&lt;/li&gt;
&lt;li&gt;Payments&lt;/li&gt;
&lt;li&gt;Ratings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tech Stack Example:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PostgreSQL&lt;/strong&gt; or &lt;strong&gt;MySQL&lt;/strong&gt; for relational data (users, trips).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redis&lt;/strong&gt; for caching and active drivers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MongoDB&lt;/strong&gt; or &lt;strong&gt;DynamoDB&lt;/strong&gt; for flexible trip logs or historical data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧠 Use relational DB for critical business logic, and Redis for fast access and geo-indexing.&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%2F7i8qvw3xjh210z7vbtfk.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%2F7i8qvw3xjh210z7vbtfk.png" alt="Database Design" width="800" height="176"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  9. 🧰 &lt;strong&gt;Scalability &amp;amp; Microservices&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Start with a &lt;strong&gt;monolith&lt;/strong&gt;, then move to &lt;strong&gt;microservices&lt;/strong&gt; for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Trip management&lt;/li&gt;
&lt;li&gt;Notifications&lt;/li&gt;
&lt;li&gt;Billing&lt;/li&gt;
&lt;li&gt;Driver tracking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Common Tools:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Docker + Kubernetes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Load balancers&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rate limiting&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Horizontal scaling&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧠 Only break into microservices when scaling becomes painful. Simplicity wins early.&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%2F24ldh87xf9rjeiepugor.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%2F24ldh87xf9rjeiepugor.png" alt="Scalability &amp;amp; Microservices" width="800" height="373"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  10. 📊 &lt;strong&gt;Monitoring, Logging &amp;amp; Analytics&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Track everything:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Driver activity&lt;/li&gt;
&lt;li&gt;System health&lt;/li&gt;
&lt;li&gt;Failed rides&lt;/li&gt;
&lt;li&gt;Payment errors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tools:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ELK Stack&lt;/strong&gt; (Elasticsearch, Logstash, Kibana)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prometheus + Grafana&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sentry or Datadog&lt;/strong&gt; for error tracking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧠 Logging key events (like trip start/end, matching failures) gives most of troubleshooting power.&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%2Fqomfwd7jxmmri4jpdyz8.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%2Fqomfwd7jxmmri4jpdyz8.png" alt="DevOps Tracker" width="800" height="322"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ &lt;strong&gt;Technology Stack (Example)&lt;/strong&gt;
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;Technology&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Frontend (Mobile)&lt;/td&gt;
&lt;td&gt;React Native / Swift / Kotlin&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Backend&lt;/td&gt;
&lt;td&gt;Node.js / Python / Go&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Database&lt;/td&gt;
&lt;td&gt;PostgreSQL, Redis&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Maps&lt;/td&gt;
&lt;td&gt;Google Maps API&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Real-time&lt;/td&gt;
&lt;td&gt;WebSockets / MQTT&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Payments&lt;/td&gt;
&lt;td&gt;Stripe&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deployment&lt;/td&gt;
&lt;td&gt;Docker, Kubernetes, AWS/GCP&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🧪 &lt;strong&gt;Bonus: Handling Edge Cases&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No drivers available?&lt;/strong&gt; Use waitlists or schedule feature.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Driver cancels?&lt;/strong&gt; Reassign another quickly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fake GPS?&lt;/strong&gt; Add fraud detection logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;App crashes?&lt;/strong&gt; Use crash analytics and retry mechanisms.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📌 &lt;strong&gt;Summary&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Designing a ride hailing system may seem huge, but you can &lt;strong&gt;cover most of the use case&lt;/strong&gt; by focusing on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-time location sharing&lt;/li&gt;
&lt;li&gt;Fast, accurate driver-passenger matching&lt;/li&gt;
&lt;li&gt;Smooth trip state transitions&lt;/li&gt;
&lt;li&gt;Reliable notifications and payments&lt;/li&gt;
&lt;li&gt;A simple, observable backend with scalable storage&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 Final Thought
&lt;/h2&gt;

&lt;p&gt;Every giant system like Uber started as a &lt;strong&gt;simple app that just connected drivers and riders&lt;/strong&gt;. One doesn't need to reinvent everything — use proven tools, start small, focus on reliability, and improve over time.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>beginners</category>
      <category>career</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Designing a URL Shortener</title>
      <dc:creator>Biswas Prasana Swain</dc:creator>
      <pubDate>Sat, 05 Jul 2025 12:50:43 +0000</pubDate>
      <link>https://dev.to/biswasprasana001/designing-a-url-shortener-122a</link>
      <guid>https://dev.to/biswasprasana001/designing-a-url-shortener-122a</guid>
      <description>&lt;p&gt;Imagine your friend sends you a super long link to a cat video:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://www.youtube.com/watch?v=dQw4w9WgXcQ&amp;amp;ab_channel=RickAstleyOfficial&amp;amp;list=PL1234567890ABCDEFGHIJK
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s ugly, right? What if we could turn it into something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://sho.rt/xyz123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s exactly what a &lt;strong&gt;URL shortener&lt;/strong&gt; does — and in this article, you’ll learn &lt;strong&gt;how to design such a system&lt;/strong&gt;, from scratch, even if you’ve never done any system design before.&lt;/p&gt;




&lt;h2&gt;
  
  
  🌐 What Is a URL Shortener?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;URL shortener&lt;/strong&gt; is a web service that turns long URLs into short ones. When someone clicks the short link, it redirects them to the original long URL.&lt;/p&gt;

&lt;p&gt;Popular examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;bit.ly&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tinyurl.com&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;t.co&lt;/code&gt; (used by Twitter)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎯 Goal of the System
&lt;/h2&gt;

&lt;p&gt;Design a system that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Accepts a long URL like &lt;code&gt;https://www.example.com/articles/2025/07/shorten-this-link&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Returns a short URL like &lt;code&gt;sho.rt/abc123&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;When someone visits &lt;code&gt;sho.rt/abc123&lt;/code&gt;, they’re redirected to the original URL.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🔨 Core Features
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Shorten URL&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Accept a long URL and generate a short one&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Redirect&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Given a short URL, redirect to the original long URL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Analytics (optional)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Count how many times a short URL was clicked&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Expiration (optional)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Make some short URLs valid only for a limited time&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🧠 Key Design Considerations
&lt;/h2&gt;

&lt;p&gt;Before we build anything, we must think about:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Scalability&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Can our system handle &lt;strong&gt;millions of links&lt;/strong&gt; and &lt;strong&gt;billions of redirects&lt;/strong&gt;?&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Availability&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Can people always access their links even if something crashes?&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Speed&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Can the system redirect people in &lt;strong&gt;milliseconds&lt;/strong&gt;?&lt;/p&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;Uniqueness&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;How do we ensure &lt;strong&gt;no two links&lt;/strong&gt; generate the same short code?&lt;/p&gt;




&lt;h2&gt;
  
  
  🧱 Basic Components
&lt;/h2&gt;

&lt;p&gt;Let’s break down the system into pieces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Client] -&amp;gt; [Load Balancer] -&amp;gt; [Application Servers] -&amp;gt; [Database]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Client&lt;/strong&gt;: The user who wants to shorten or open a link.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Load Balancer&lt;/strong&gt;: Distributes incoming requests to servers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Application Server&lt;/strong&gt;: Handles logic (generate/redirect).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database&lt;/strong&gt;: Stores mapping between short and long URLs.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🔢 How to Generate Short URLs
&lt;/h2&gt;

&lt;p&gt;Let’s say we want to shorten this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://example.com/my-very-long-article-about-space
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can generate a short URL code in several ways:&lt;/p&gt;

&lt;h3&gt;
  
  
  Option 1: &lt;strong&gt;Hashing&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Hash the original URL using a function like &lt;code&gt;SHA-256&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Take the first 6–8 characters of the hash.&lt;/li&gt;
&lt;li&gt;Map that to a short code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✅ Simple&lt;br&gt;
❌ Risk of collision (two URLs might get same short code)&lt;/p&gt;


&lt;h3&gt;
  
  
  Option 2: &lt;strong&gt;Auto-Increment ID + Base62&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Store each new URL in the database with a numeric ID (like 123456).&lt;/li&gt;
&lt;li&gt;Convert the ID to &lt;strong&gt;Base62&lt;/strong&gt; (0-9 + a-z + A-Z):
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  123456 → "abc123"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;✅ Unique, Compact&lt;br&gt;
✅ Easy to reverse&lt;br&gt;
❌ Not random (easy to guess next links)&lt;/p&gt;


&lt;h3&gt;
  
  
  Option 3: &lt;strong&gt;Random String&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Generate a random string of 6-8 characters.&lt;/li&gt;
&lt;li&gt;Check in DB if it's already taken. If not, save it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;✅ Harder to guess&lt;br&gt;
❌ Can collide, so we need retries&lt;/p&gt;


&lt;h2&gt;
  
  
  📦 Data Model (Database Schema)
&lt;/h2&gt;

&lt;p&gt;Let’s use a simple table:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;short_code&lt;/td&gt;
&lt;td&gt;VARCHAR(10)&lt;/td&gt;
&lt;td&gt;The generated code, like &lt;code&gt;abc123&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;long_url&lt;/td&gt;
&lt;td&gt;TEXT&lt;/td&gt;
&lt;td&gt;The original URL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;created_at&lt;/td&gt;
&lt;td&gt;DATETIME&lt;/td&gt;
&lt;td&gt;When the short URL was created&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;expiry_date&lt;/td&gt;
&lt;td&gt;DATETIME&lt;/td&gt;
&lt;td&gt;(Optional) Expiration date&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;click_count&lt;/td&gt;
&lt;td&gt;INT&lt;/td&gt;
&lt;td&gt;(Optional) Number of times clicked&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h2&gt;
  
  
  🚦 Redirect Flow
&lt;/h2&gt;

&lt;p&gt;When someone visits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://sho.rt/abc123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s what happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User’s browser sends a request to your server with code &lt;code&gt;abc123&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Server looks up the code in the database.&lt;/li&gt;
&lt;li&gt;If found, it sends a &lt;strong&gt;301 redirect&lt;/strong&gt; to the original long URL.&lt;/li&gt;
&lt;li&gt;Browser takes the user to the long URL.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🏗️ Putting It Together (Step-by-Step)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. URL Shortening API
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;POST /shorten&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Request:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"long_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://example.com/article/123"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"short_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://sho.rt/abc123"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  2. Redirection API
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;GET /abc123&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Action:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Find &lt;code&gt;abc123&lt;/code&gt; in the database.&lt;/li&gt;
&lt;li&gt;If found, return a 301 redirect to the long URL.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⚙️ Scaling the System
&lt;/h2&gt;

&lt;p&gt;If the system grows big, here’s how we keep it fast:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Caching&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Use &lt;strong&gt;Redis&lt;/strong&gt; or &lt;strong&gt;Memcached&lt;/strong&gt; to cache popular short codes in memory.&lt;br&gt;
This avoids hitting the database on every redirect.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Sharding&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Split the database into multiple machines to handle billions of entries.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Rate Limiting&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Prevent abuse by limiting how many links a user can create per minute.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;Load Balancing&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Distribute traffic across multiple servers using a &lt;strong&gt;load balancer&lt;/strong&gt; like Nginx or AWS ELB.&lt;/p&gt;




&lt;h2&gt;
  
  
  🛡️ Security and Edge Cases
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Problem&lt;/th&gt;
&lt;th&gt;Solution&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Malicious URLs (phishing, malware)&lt;/td&gt;
&lt;td&gt;Use a URL scanner like Google Safe Browsing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Abuse (spamming)&lt;/td&gt;
&lt;td&gt;Rate limit users, add CAPTCHA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Expired links&lt;/td&gt;
&lt;td&gt;Add TTL (Time-To-Live) logic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Editable links&lt;/td&gt;
&lt;td&gt;Let users log in and manage their links&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🏭 Diagram
&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%2Fh3yt8up9quswriu1njcx.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%2Fh3yt8up9quswriu1njcx.png" alt="URL Shortener Architecture" width="800" height="605"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  📊 Optional Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Analytics Dashboard&lt;/strong&gt;: Show users how many clicks, locations, devices, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Custom Short Codes&lt;/strong&gt;: Let users choose their code (e.g., &lt;code&gt;sho.rt/mybrand&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Link Previews&lt;/strong&gt;: Show metadata when sharing links on social media&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;QR Codes&lt;/strong&gt;: Auto-generate QR for each short link&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ✅ Summary
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Goal&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Shorten and redirect URLs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Short Code&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Can be generated using hashing, Base62, or random strings&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Storage&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Store code-to-URL mapping in a database&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Redirect&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Lookup short code and return 301 redirect&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Scaling&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Use cache, sharding, and load balancing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Security&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Scan for malicious URLs, rate limiting, CAPTCHA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Extra Features&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Analytics, custom codes, link expiration&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🧠 Final Thought
&lt;/h2&gt;

&lt;p&gt;Even though a URL shortener seems simple on the surface, designing it at scale teaches you many real-world software engineering concepts: databases, caching, hashing, APIs, distributed systems, and security.&lt;/p&gt;

&lt;p&gt;Whether you're building for a side project or preparing for a system design interview — mastering the design of a URL shortener is a &lt;strong&gt;perfect starting point&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>tutorial</category>
      <category>career</category>
      <category>learning</category>
    </item>
    <item>
      <title>Breaking Down Microservices Architecture</title>
      <dc:creator>Biswas Prasana Swain</dc:creator>
      <pubDate>Tue, 27 May 2025 14:15:08 +0000</pubDate>
      <link>https://dev.to/biswasprasana001/breaking-down-microservices-architecture-2ldk</link>
      <guid>https://dev.to/biswasprasana001/breaking-down-microservices-architecture-2ldk</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Imagine you’re organizing a big event. Would you prefer doing everything alone — cooking, decorating, sending invites — or hire a team where each person handles one job? That’s the basic idea behind &lt;strong&gt;microservices&lt;/strong&gt; — a smarter way to build software.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🌐 What Is Microservices Architecture?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Microservices Architecture&lt;/strong&gt; is a way of building software where each part of the system (called a &lt;em&gt;service&lt;/em&gt;) does &lt;strong&gt;one thing really well&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of one big “do-it-all” program (called a &lt;strong&gt;monolith&lt;/strong&gt;), we create &lt;strong&gt;many small, focused apps&lt;/strong&gt; that work together. Each microservice handles a &lt;strong&gt;specific task&lt;/strong&gt;, like managing users, showing products, or handling payments.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏗️ Real-Life Analogy: The Online Store
&lt;/h2&gt;

&lt;p&gt;Let’s say we’re building an &lt;strong&gt;online shopping app&lt;/strong&gt; like Amazon.&lt;/p&gt;

&lt;p&gt;In a &lt;strong&gt;traditional (monolithic)&lt;/strong&gt; approach, the app is one giant piece of code that handles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logging in users&lt;/li&gt;
&lt;li&gt;Showing products&lt;/li&gt;
&lt;li&gt;Managing the shopping cart&lt;/li&gt;
&lt;li&gt;Placing orders&lt;/li&gt;
&lt;li&gt;Processing payments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If anything goes wrong, it might break the &lt;strong&gt;whole app&lt;/strong&gt;. Yikes!&lt;/p&gt;

&lt;p&gt;Instead, in a &lt;strong&gt;microservices&lt;/strong&gt; approach, we split this into &lt;strong&gt;independent parts&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Microservice&lt;/th&gt;
&lt;th&gt;Responsibility&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;UserService&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Handles login and signup&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ProductService&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Lists products&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CartService&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Manages the shopping cart&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;OrderService&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Places orders&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PaymentService&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Processes payments&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each service is like a specialist in a team.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 How Do They Talk?
&lt;/h2&gt;

&lt;p&gt;These services &lt;strong&gt;talk to each other via APIs&lt;/strong&gt;. Think of APIs like &lt;strong&gt;sending messages&lt;/strong&gt; or making &lt;strong&gt;phone calls&lt;/strong&gt; between departments.&lt;/p&gt;

&lt;p&gt;When you click “Buy Now”:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Your app asks the &lt;code&gt;CartService&lt;/code&gt; what’s in the cart.&lt;/li&gt;
&lt;li&gt;It sends the info to &lt;code&gt;OrderService&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Then &lt;code&gt;PaymentService&lt;/code&gt; processes the payment.&lt;/li&gt;
&lt;li&gt;Boom — order placed.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🧾 Visual Flowchart
&lt;/h2&gt;

&lt;p&gt;Here's a visual of how everything connects:&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%2F38ynu64mtkrv7kd7zsbz.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%2F38ynu64mtkrv7kd7zsbz.png" alt="Microservices Architecture" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Simple Pseudocode Example
&lt;/h2&gt;

&lt;p&gt;Let’s write &lt;strong&gt;basic pseudocode&lt;/strong&gt; for each microservice to show how it works.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. 👤 UserService
&lt;/h3&gt;

&lt;p&gt;Handles user login and signup.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;signup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;save_user_to_database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;User created&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;validate_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Token123&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;  &lt;span class="c1"&gt;# Like a login session
&lt;/span&gt;        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Login failed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  2. 🛍️ ProductService
&lt;/h3&gt;

&lt;p&gt;Displays available products.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;list_products&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Shoes&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Laptop&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Headphones&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Laptop&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;price&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;999&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  3. 🛒 CartService
&lt;/h3&gt;

&lt;p&gt;Manages items in a user’s shopping cart.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CartService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;carts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;  &lt;span class="c1"&gt;# Example: {user_id: [product_ids]}
&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add_to_cart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;carts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Product added&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;view_cart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;carts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  4. 📦 OrderService
&lt;/h3&gt;

&lt;p&gt;Places orders using cart data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;place_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cart_items&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;order_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;save_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cart_items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Order &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; placed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  5. 💳 PaymentService
&lt;/h3&gt;

&lt;p&gt;Handles payment transactions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PaymentService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payment_details&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;process_payment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payment_details&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Payment successful&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Payment failed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🧰 Benefits of Microservices
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Benefit&lt;/th&gt;
&lt;th&gt;What It Means&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Independence&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Teams work on services separately&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Scalability&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Easily scale only the part you need&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Reliability&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;One service can fail, others keep running&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Faster Deployment&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Release updates quickly and independently&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🧱 Comparing to Monolithic Architecture
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Monolith&lt;/th&gt;
&lt;th&gt;Microservices&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;One big codebase&lt;/td&gt;
&lt;td&gt;Many small services&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shared database&lt;/td&gt;
&lt;td&gt;Each service has its own&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hard to scale&lt;/td&gt;
&lt;td&gt;Easily scalable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;One failure affects all&lt;/td&gt;
&lt;td&gt;Isolated failures&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🔧 Behind the Scenes: How It Works
&lt;/h2&gt;

&lt;p&gt;Here’s what happens when a customer places an order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Login&lt;/strong&gt; → &lt;code&gt;UserService.login()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browse&lt;/strong&gt; → &lt;code&gt;ProductService.list_products()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add to Cart&lt;/strong&gt; → &lt;code&gt;CartService.add_to_cart()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Checkout&lt;/strong&gt; → &lt;code&gt;OrderService.place_order()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payment&lt;/strong&gt; → &lt;code&gt;PaymentService.pay()&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each step is handled by a &lt;strong&gt;different microservice&lt;/strong&gt;, all coordinated through an &lt;strong&gt;API Gateway&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Microservices architecture is like &lt;strong&gt;running a team of experts&lt;/strong&gt;, each handling their job efficiently. While it’s more complex behind the scenes, it allows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Better flexibility&lt;/li&gt;
&lt;li&gt;Faster improvements&lt;/li&gt;
&lt;li&gt;More stable and secure systems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether you're building a shopping site, a mobile app, or a platform — &lt;strong&gt;microservices let you build smarter and scale faster&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>tutorial</category>
      <category>microservices</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Guide to Snapshot Testing React Native Components Using Jest</title>
      <dc:creator>Biswas Prasana Swain</dc:creator>
      <pubDate>Sun, 27 Apr 2025 18:44:00 +0000</pubDate>
      <link>https://dev.to/biswasprasana001/a-guide-to-snapshot-testing-react-native-components-using-jest-3ci7</link>
      <guid>https://dev.to/biswasprasana001/a-guide-to-snapshot-testing-react-native-components-using-jest-3ci7</guid>
      <description>&lt;p&gt;Imagine you build a beautiful React Native button, and you want to make sure &lt;strong&gt;its structure never accidentally changes&lt;/strong&gt; as your app grows.&lt;/p&gt;

&lt;p&gt;Wouldn't it be cool if there was a way to take a "photo" of your component, and later automatically check if it still looks the same?&lt;/p&gt;

&lt;p&gt;That's exactly what &lt;strong&gt;snapshot testing&lt;/strong&gt; does!&lt;/p&gt;

&lt;p&gt;In this guide, you’ll learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What snapshot testing is&lt;/li&gt;
&lt;li&gt;Why it’s useful&lt;/li&gt;
&lt;li&gt;How to set it up&lt;/li&gt;
&lt;li&gt;How to write your first snapshot test&lt;/li&gt;
&lt;li&gt;Common mistakes and best practices&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s start from scratch. 📸&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Snapshot Testing?
&lt;/h2&gt;

&lt;p&gt;Think of &lt;strong&gt;snapshot testing&lt;/strong&gt; like taking a &lt;strong&gt;picture&lt;/strong&gt; of your component’s output (its structure and UI code).&lt;/p&gt;

&lt;p&gt;Later, every time you run the test again, Jest will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Take a &lt;strong&gt;new snapshot&lt;/strong&gt; of the component&lt;/li&gt;
&lt;li&gt;Compare it to the &lt;strong&gt;old snapshot&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Tell you if anything has changed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If it changed unexpectedly, Jest will warn you:&lt;br&gt;&lt;br&gt;
"Hey! Your component looks different. Are you sure this is what you want?"&lt;/p&gt;

&lt;p&gt;✅ It’s a &lt;strong&gt;quick way&lt;/strong&gt; to detect &lt;strong&gt;unexpected changes&lt;/strong&gt; in how your components are built.&lt;/p&gt;


&lt;h2&gt;
  
  
  Why Use Snapshot Testing?
&lt;/h2&gt;

&lt;p&gt;Snapshot testing is great for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;UI components&lt;/strong&gt; like buttons, cards, screens, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Catching accidental UI changes&lt;/strong&gt; before shipping&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code reviews&lt;/strong&gt;: you can clearly see what changed in a component&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faster development&lt;/strong&gt;: no need to manually check everything visually&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s like having an automated "watchdog" for your app’s structure.&lt;/p&gt;


&lt;h2&gt;
  
  
  Setting Up Your Environment
&lt;/h2&gt;

&lt;p&gt;If you used &lt;code&gt;npx react-native init&lt;/code&gt; to create your app, &lt;strong&gt;Jest&lt;/strong&gt; is already set up for you!&lt;/p&gt;

&lt;p&gt;To be sure, check your &lt;code&gt;package.json&lt;/code&gt; for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"jest"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"devDependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"jest"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"@testing-library/react-native"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"react-test-renderer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If anything’s missing, install them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; jest @testing-library/react-native react-test-renderer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add &lt;span class="nt"&gt;--dev&lt;/span&gt; jest @testing-library/react-native react-test-renderer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Quick Overview: What Tools Are We Using?
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Jest&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Runs the tests&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;react-test-renderer&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Renders the component to pure JavaScript object (not real device)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;@testing-library/react-native&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;(Optional) Helps simulate user actions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For basic snapshot testing, we mainly use &lt;strong&gt;Jest&lt;/strong&gt; and &lt;strong&gt;react-test-renderer&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Writing Your First Snapshot Test
&lt;/h2&gt;

&lt;p&gt;Let's say you have a simple &lt;strong&gt;Button&lt;/strong&gt; component:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Button.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;TouchableOpacity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Text&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-native&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;onPress&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;TouchableOpacity&lt;/span&gt; &lt;span class="nx"&gt;onPress&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;onPress&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Text&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;white&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Text&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/TouchableOpacity&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s write a &lt;strong&gt;snapshot test&lt;/strong&gt; for it!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Button.test.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;renderer&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-test-renderer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// this is react-test-renderer&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Button renders correctly&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tree&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;renderer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Click me&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onPress&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;.toJSON&lt;/span&gt;&lt;span class="se"&gt;()&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toMatchSnapshot&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  What’s happening here?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;renderer.create()&lt;/code&gt; creates a fake "rendered" version of your component.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.toJSON()&lt;/code&gt; turns it into a plain JavaScript object (representing the structure).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;expect(tree).toMatchSnapshot()&lt;/code&gt; saves the output into a &lt;strong&gt;snapshot file&lt;/strong&gt; the first time.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The snapshot file looks like this (automatically generated):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Button.test.js.snap&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exports[`Button renders correctly 1`] = `
&amp;lt;TouchableOpacity
  onPress={[Function]}
  style={
    Object {
      "backgroundColor": "blue",
      "padding": 10,
    }
  }
&amp;gt;
  &amp;lt;Text
    style={
      Object {
        "color": "white",
      }
    }
  &amp;gt;
    Click me
  &amp;lt;/Text&amp;gt;
&amp;lt;/TouchableOpacity&amp;gt;
`;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't have to create this file manually — &lt;strong&gt;Jest&lt;/strong&gt; handles it!&lt;/p&gt;




&lt;h2&gt;
  
  
  What Happens When Things Change?
&lt;/h2&gt;

&lt;p&gt;Suppose you accidentally change the button’s color from blue to green in &lt;strong&gt;Button.js&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you run &lt;code&gt;npm test&lt;/code&gt;, Jest will tell you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Snapshot test failed!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will show you &lt;strong&gt;what changed&lt;/strong&gt; — just like a side-by-side "before and after" comparison.&lt;/p&gt;

&lt;p&gt;You’ll have two choices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the change was &lt;strong&gt;on purpose&lt;/strong&gt; (you &lt;strong&gt;wanted&lt;/strong&gt; it green), you can &lt;strong&gt;update&lt;/strong&gt; the snapshot.&lt;/li&gt;
&lt;li&gt;If the change was &lt;strong&gt;a mistake&lt;/strong&gt;, you can &lt;strong&gt;fix the component&lt;/strong&gt; to match the old snapshot.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How to Update Snapshots
&lt;/h2&gt;

&lt;p&gt;If you intentionally changed your component (and want to accept the new version), just run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-u&lt;/code&gt; flag tells Jest:&lt;br&gt;&lt;br&gt;
✅ "Update the snapshots with the new output."&lt;/p&gt;




&lt;h2&gt;
  
  
  When to Use Snapshot Testing (and When Not to)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Good for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple components (Buttons, Cards, Badges)&lt;/li&gt;
&lt;li&gt;Reusable UI components that don’t change often&lt;/li&gt;
&lt;li&gt;Detecting unexpected UI changes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Not good for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Components with &lt;strong&gt;lots of randomness&lt;/strong&gt; (e.g., random colors, dynamic IDs)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Highly dynamic&lt;/strong&gt; components (always different outputs)&lt;/li&gt;
&lt;li&gt;Very &lt;strong&gt;large and complicated&lt;/strong&gt; components (snapshots become hard to read)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔵 &lt;strong&gt;Rule of Thumb&lt;/strong&gt;:&lt;br&gt;&lt;br&gt;
Use snapshot testing for &lt;strong&gt;small to medium, stable UI components&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Best Practices for Snapshot Testing
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tip&lt;/th&gt;
&lt;th&gt;Why it helps&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Keep components &lt;strong&gt;small&lt;/strong&gt; and &lt;strong&gt;simple&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Easier-to-understand snapshots&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Name your tests clearly&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Easier to know what failed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Only snapshot &lt;strong&gt;important parts&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Don’t snapshot whole screens with tons of logic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Regularly &lt;strong&gt;review snapshots manually&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;Catch unwanted changes before accepting updates&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Combine with &lt;strong&gt;other types of tests&lt;/strong&gt; (like behavior tests)&lt;/td&gt;
&lt;td&gt;Don’t rely only on snapshots&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Common Beginner Mistakes
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mistake&lt;/th&gt;
&lt;th&gt;Solution&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Blindly updating snapshots (&lt;code&gt;-u&lt;/code&gt;) without checking&lt;/td&gt;
&lt;td&gt;Always check the &lt;strong&gt;diff&lt;/strong&gt; first before accepting&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Taking snapshots of huge, complex screens&lt;/td&gt;
&lt;td&gt;Break down into smaller components&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Snapshotting things that always change (e.g., timestamps, random IDs)&lt;/td&gt;
&lt;td&gt;Avoid snapshotting unstable output&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




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

&lt;p&gt;Snapshot testing is a &lt;strong&gt;simple but powerful tool&lt;/strong&gt; to catch unexpected UI changes in your React Native app.&lt;/p&gt;

&lt;p&gt;With just a few lines of code, you can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Capture your component's structure&lt;/li&gt;
&lt;li&gt;Be alerted when something changes&lt;/li&gt;
&lt;li&gt;Review and update your app's design with confidence&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Remember:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Snapshots are &lt;strong&gt;helpers&lt;/strong&gt;, not &lt;strong&gt;absolute proofs&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Always &lt;strong&gt;review snapshot changes&lt;/strong&gt; carefully.&lt;/li&gt;
&lt;li&gt;Start small and practice often!&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Quick Recap
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;You learned&lt;/th&gt;
&lt;th&gt;Key Point&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;What snapshot testing is&lt;/td&gt;
&lt;td&gt;Taking a "photo" of your component's structure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;How to set it up&lt;/td&gt;
&lt;td&gt;Jest + react-test-renderer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;How to write a snapshot test&lt;/td&gt;
&lt;td&gt;&lt;code&gt;expect(tree).toMatchSnapshot()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;How to handle changes&lt;/td&gt;
&lt;td&gt;Review, then &lt;code&gt;npm test -- -u&lt;/code&gt; if intentional&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best practices&lt;/td&gt;
&lt;td&gt;Keep components small, review snapshots&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>testing</category>
    </item>
    <item>
      <title>A Comprehensive Guide to Redux and Redux-Saga for Beginners</title>
      <dc:creator>Biswas Prasana Swain</dc:creator>
      <pubDate>Fri, 04 Apr 2025 18:26:47 +0000</pubDate>
      <link>https://dev.to/biswasprasana001/a-comprehensive-guide-to-redux-and-redux-saga-for-beginners-5cbc</link>
      <guid>https://dev.to/biswasprasana001/a-comprehensive-guide-to-redux-and-redux-saga-for-beginners-5cbc</guid>
      <description>&lt;p&gt;State management is a crucial aspect of modern frontend development, especially when working with large-scale applications. &lt;strong&gt;Redux&lt;/strong&gt; and &lt;strong&gt;Redux-Saga&lt;/strong&gt; are two popular libraries in the React ecosystem that help manage and handle application state efficiently. &lt;/p&gt;

&lt;p&gt;In this article, we'll explore &lt;strong&gt;Redux&lt;/strong&gt; and &lt;strong&gt;Redux-Saga&lt;/strong&gt; from the ground up, assuming no prior knowledge. By the end, you'll understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What Redux is and why it is needed&lt;/li&gt;
&lt;li&gt;The core principles of Redux&lt;/li&gt;
&lt;li&gt;How to implement Redux in a React application&lt;/li&gt;
&lt;li&gt;What Redux-Saga is and why it's useful&lt;/li&gt;
&lt;li&gt;How to handle side effects with Redux-Saga&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s get started!&lt;/p&gt;




&lt;h2&gt;
  
  
  🟢 What is Redux?
&lt;/h2&gt;

&lt;p&gt;Redux is a predictable &lt;strong&gt;state management library&lt;/strong&gt; that helps manage the global state of a React application. It allows you to store, update, and retrieve data efficiently while ensuring a &lt;strong&gt;single source of truth&lt;/strong&gt; for your app's state.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔥 Why Use Redux?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Centralized State&lt;/strong&gt; – Stores application data in a single location (Redux store).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Predictability&lt;/strong&gt; – The state is immutable and only updated in a controlled manner.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debugging &amp;amp; Testing&lt;/strong&gt; – With tools like Redux DevTools, debugging becomes easier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt; – Helps maintain state in large applications.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🟢 Core Concepts of Redux
&lt;/h2&gt;

&lt;p&gt;Redux follows a unidirectional data flow with three key components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Store&lt;/strong&gt; – The central place where the application state is stored.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Actions&lt;/strong&gt; – JavaScript objects that describe &lt;strong&gt;what should happen&lt;/strong&gt; in the app.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reducers&lt;/strong&gt; – Pure functions that take the current state and an action, then return a new state.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  📌 Understanding Redux Flow:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;A component &lt;strong&gt;dispatches&lt;/strong&gt; an &lt;strong&gt;action&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;reducer&lt;/strong&gt; processes the action and returns a &lt;strong&gt;new state&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;store&lt;/strong&gt; updates and provides the new state to the React components.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🟢 Setting Up Redux in React
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🔧 Installing Redux and React-Redux
&lt;/h3&gt;

&lt;p&gt;To use Redux in a React project, install the necessary libraries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;redux react-redux
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔹 Step 1: Define Actions
&lt;/h3&gt;

&lt;p&gt;Actions describe what happens in your app. Each action has a &lt;code&gt;type&lt;/code&gt; and an optional &lt;code&gt;payload&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// actions.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;INCREMENT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;INCREMENT&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;increment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;INCREMENT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔹 Step 2: Create a Reducer
&lt;/h3&gt;

&lt;p&gt;Reducers handle state changes based on the dispatched action:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// reducer.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;INCREMENT&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./actions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;counterReducer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="na"&gt;INCREMENT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;counterReducer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔹 Step 3: Create a Redux Store
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;store&lt;/strong&gt; holds the entire application state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// store.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createStore&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;counterReducer&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./reducer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;counterReducer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔹 Step 4: Connect Redux to React
&lt;/h3&gt;

&lt;p&gt;Use the &lt;code&gt;Provider&lt;/code&gt; component from &lt;code&gt;react-redux&lt;/code&gt; to make the Redux store accessible in your React app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// index.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Provider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./store&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Provider&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Provider&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;,
&lt;/span&gt;  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔹 Step 5: Access Redux State in Components
&lt;/h3&gt;

&lt;p&gt;Use &lt;code&gt;useSelector&lt;/code&gt; to read state and &lt;code&gt;useDispatch&lt;/code&gt; to dispatch actions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Counter.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useSelector&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useDispatch&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;increment&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./actions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useSelector&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useDispatch&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h2&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;())}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Increment&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Now, when you click the button, the counter updates using Redux!&lt;/p&gt;




&lt;h2&gt;
  
  
  🟢 What is Redux-Saga?
&lt;/h2&gt;

&lt;p&gt;Redux by itself is great for managing application state, but when dealing with &lt;strong&gt;asynchronous operations&lt;/strong&gt; like API calls, it requires middleware. This is where &lt;strong&gt;Redux-Saga&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔥 Why Use Redux-Saga?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Handles side effects elegantly&lt;/strong&gt; – Unlike Redux Thunk, Sagas use generator functions, making asynchronous flows more manageable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manages complex workflows&lt;/strong&gt; – Helps orchestrate multiple async tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Better control over API calls&lt;/strong&gt; – You can cancel, debounce, or retry actions.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🟢 Setting Up Redux-Saga
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🔧 Install Redux-Saga
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;redux-saga
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔹 Step 1: Create a Saga Function
&lt;/h3&gt;

&lt;p&gt;A saga listens for dispatched actions and performs side effects.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// sagas.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;takeEvery&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;put&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;redux-saga/effects&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;INCREMENT&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./actions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;incrementAsync&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Simulates API call delay&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;INCREMENT&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;watchIncrement&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nf"&gt;takeEvery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;INCREMENT_ASYNC&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;incrementAsync&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔹 Step 2: Connect Redux-Saga to Redux Store
&lt;/h3&gt;

&lt;p&gt;Modify the store to use &lt;code&gt;redux-saga&lt;/code&gt; middleware.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// store.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createStore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;applyMiddleware&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;createSagaMiddleware&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;redux-saga&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;counterReducer&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./reducer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;watchIncrement&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./sagas&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sagaMiddleware&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createSagaMiddleware&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;counterReducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;applyMiddleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sagaMiddleware&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="nx"&gt;sagaMiddleware&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;watchIncrement&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  🔹 Step 3: Dispatch Async Actions in Components
&lt;/h3&gt;

&lt;p&gt;Modify the component to trigger the async action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Counter.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useSelector&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useDispatch&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-redux&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useSelector&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useDispatch&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h2&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;INCREMENT_ASYNC&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;})}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nc"&gt;Increment &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Async&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when you click the button, Redux-Saga will handle the increment after a delay of &lt;strong&gt;1 second&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🟢 Comparing Redux-Saga and Redux Thunk
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Redux-Saga&lt;/th&gt;
&lt;th&gt;Redux Thunk&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Uses&lt;/td&gt;
&lt;td&gt;Generator functions&lt;/td&gt;
&lt;td&gt;Promises/async-await&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Complex async flows&lt;/td&gt;
&lt;td&gt;Simple async calls&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Middleware&lt;/td&gt;
&lt;td&gt;&lt;code&gt;redux-saga&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;redux-thunk&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Control&lt;/td&gt;
&lt;td&gt;Can cancel, debounce, retry&lt;/td&gt;
&lt;td&gt;Basic control over API calls&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For simple applications, Redux Thunk is sufficient, but for &lt;strong&gt;large-scale applications&lt;/strong&gt;, Redux-Saga provides &lt;strong&gt;better control over side effects&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🟢 Conclusion
&lt;/h2&gt;

&lt;p&gt;Redux simplifies state management, and Redux-Saga handles asynchronous operations efficiently. Together, they provide a &lt;strong&gt;powerful and scalable&lt;/strong&gt; solution for managing complex applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Key Takeaways:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Redux&lt;/strong&gt; manages application state centrally.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Actions&lt;/strong&gt; describe what happens, &lt;strong&gt;Reducers&lt;/strong&gt; update the state, and the &lt;strong&gt;Store&lt;/strong&gt; holds everything.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redux-Saga&lt;/strong&gt; handles side effects using generator functions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sagas&lt;/strong&gt; listen for actions, perform async tasks, and dispatch new actions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re working on a large-scale React application, &lt;strong&gt;Redux with Redux-Saga&lt;/strong&gt; is an excellent choice!&lt;/p&gt;

</description>
      <category>redux</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
