<?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: Khushi Patel</title>
    <description>The latest articles on DEV Community by Khushi Patel (@khushindpatel).</description>
    <link>https://dev.to/khushindpatel</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1055368%2Fe0780331-7974-49ea-ba06-89417152f136.jpg</url>
      <title>DEV Community: Khushi Patel</title>
      <link>https://dev.to/khushindpatel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khushindpatel"/>
    <language>en</language>
    <item>
      <title>Real-Time Communication: WebSockets vs. Polling</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Sat, 31 Oct 2026 14:16:01 +0000</pubDate>
      <link>https://dev.to/khushindpatel/real-time-communication-websockets-vs-polling-571l</link>
      <guid>https://dev.to/khushindpatel/real-time-communication-websockets-vs-polling-571l</guid>
      <description>&lt;h4&gt;
  
  
  Introduction
&lt;/h4&gt;

&lt;p&gt;Imagine sitting in a café and waiting for your order. You want to know&lt;br&gt;
as soon as it is ready. You could keep asking the cashier, "Is my order&lt;br&gt;
ready?", or ask the cashier to notify you when it is ready. This&lt;br&gt;
illustrates two ways applications receive updates: &lt;strong&gt;polling&lt;/strong&gt; and&lt;br&gt;
&lt;strong&gt;WebSockets&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  What Is Polling?
&lt;/h4&gt;

&lt;p&gt;Polling is a communication technique in which a client repeatedly sends&lt;br&gt;
requests to a server at regular intervals to check whether new&lt;br&gt;
information is available.&lt;/p&gt;

&lt;h5&gt;
  
  
  Café Example
&lt;/h5&gt;

&lt;p&gt;Imagine asking the cashier every five seconds whether your order is&lt;br&gt;
ready. Even if it is not ready, you keep asking.&lt;/p&gt;

&lt;h5&gt;
  
  
  How It Works
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt; The client sends an HTTP request.&lt;/li&gt;
&lt;li&gt; The server checks for new information and returns a response.&lt;/li&gt;
&lt;li&gt; The client waits for a configured interval.&lt;/li&gt;
&lt;li&gt; The client sends another request.&lt;/li&gt;
&lt;li&gt; This continues until the update arrives or polling stops.&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Short Polling
&lt;/h5&gt;

&lt;p&gt;The client sends requests at fixed intervals, such as every five&lt;br&gt;
seconds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Simple to implement, uses ordinary HTTP, and works when&lt;br&gt;
updates are occasional.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt; Requests may be wasted when nothing changes, and&lt;br&gt;
updates may be delayed until the next interval.&lt;/p&gt;

&lt;h5&gt;
  
  
  Long Polling
&lt;/h5&gt;

&lt;p&gt;The client sends a request, but the server holds it open until new data&lt;br&gt;
is available or a timeout occurs. After receiving a response, the client&lt;br&gt;
sends another request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Café example:&lt;/strong&gt; You ask the cashier to let you know when the order is&lt;br&gt;
ready. The cashier waits until there is an update, tells you, and you&lt;br&gt;
ask again if you are still waiting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Can reduce unnecessary empty responses compared with&lt;br&gt;
short polling and can deliver updates soon after they occur.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt; The server manages requests that remain open, and&lt;br&gt;
clients need to reconnect after each response. Timeouts and retries need&lt;br&gt;
careful handling.&lt;/p&gt;

&lt;h4&gt;
  
  
  What Are WebSockets?
&lt;/h4&gt;

&lt;p&gt;WebSockets provide a persistent, two-way communication channel between a&lt;br&gt;
client and server over a single connection. Once established, either&lt;br&gt;
side can send messages at any time without creating a new HTTP request&lt;br&gt;
for every message.&lt;/p&gt;

&lt;h5&gt;
  
  
  Café Example
&lt;/h5&gt;

&lt;p&gt;Instead of asking the cashier repeatedly, you say, "Please let me know&lt;br&gt;
as soon as my order is ready." The cashier notifies you when it is&lt;br&gt;
ready. You can also talk back through the same channel.&lt;/p&gt;

&lt;h5&gt;
  
  
  How It Works
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt; The client starts a WebSocket handshake, typically using an HTTP
request.&lt;/li&gt;
&lt;li&gt; The server accepts the handshake and upgrades the connection to the
WebSocket protocol.&lt;/li&gt;
&lt;li&gt; The connection stays open while both sides need it.&lt;/li&gt;
&lt;li&gt; Client and server can send messages independently.&lt;/li&gt;
&lt;li&gt; Either side can close the connection when it is no longer needed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Simple JavaScript Example
&lt;/h5&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;socket&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;WebSocket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;wss://example.com/socket&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onopen&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="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="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;join&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;roomId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;room-123&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onmessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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="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;New message:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onclose&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="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;Connection closed&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;p&gt;This is a simplified client example. A production application also needs&lt;br&gt;
authentication, message validation, error handling, reconnection logic,&lt;br&gt;
and authorization checks.&lt;/p&gt;

&lt;h5&gt;
  
  
  Advantages of WebSockets
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;  Supports two-way communication over one connection.&lt;/li&gt;
&lt;li&gt;  Enables low-latency updates without repeated polling requests.&lt;/li&gt;
&lt;li&gt;  Works well for frequent, interactive updates.&lt;/li&gt;
&lt;li&gt;  Reduces repeated HTTP request overhead when messages are frequent.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Disadvantages of WebSockets
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;  More complex to implement and operate than basic polling.&lt;/li&gt;
&lt;li&gt;  Servers must manage many long-lived connections.&lt;/li&gt;
&lt;li&gt;  Reconnection and connection state need careful handling.&lt;/li&gt;
&lt;li&gt;  Scaling across multiple application servers requires a strategy for
routing and distributing messages.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Polling vs.&amp;nbsp;WebSockets
&lt;/h4&gt;




&lt;p&gt;Feature                 Polling                 WebSockets&lt;/p&gt;




&lt;p&gt;Communication           Client repeatedly       Two-way communication&lt;br&gt;
                          requests updates        &lt;/p&gt;

&lt;p&gt;Connection              Separate HTTP requests  Persistent connection&lt;/p&gt;

&lt;p&gt;Server updates          Usually returned in     Server can send&lt;br&gt;
                          response to a client    messages whenever&lt;br&gt;
                          request                 needed&lt;/p&gt;

&lt;p&gt;Update latency          Depends on polling      Usually low when&lt;br&gt;
                          interval                connection is healthy&lt;/p&gt;

&lt;p&gt;Request overhead        Repeated requests,      Less repeated request&lt;br&gt;
                          including when nothing  overhead for frequent&lt;br&gt;
                          changes                 messages&lt;/p&gt;

&lt;p&gt;Implementation          Simple                  More complex&lt;/p&gt;

&lt;p&gt;Best for                Occasional updates      Frequent, interactive&lt;br&gt;
                                                  updates&lt;/p&gt;




&lt;p&gt;WebSockets are not automatically best for every real-time feature. If&lt;br&gt;
updates are rare, polling may be simpler and more cost-effective.&lt;/p&gt;

&lt;h4&gt;
  
  
  What Are Server-Sent Events (SSE)?
&lt;/h4&gt;

&lt;p&gt;Server-Sent Events (SSE) allow a server to send updates to a client over&lt;br&gt;
a long-lived HTTP connection. Communication is primarily one-way: server&lt;br&gt;
to client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Café example:&lt;/strong&gt; The cashier can notify you whenever your order is&lt;br&gt;
ready, but you cannot send messages back through that same notification&lt;br&gt;
channel.&lt;/p&gt;

&lt;h5&gt;
  
  
  When to Use SSE
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;  Live news feeds&lt;/li&gt;
&lt;li&gt;  Monitoring dashboards&lt;/li&gt;
&lt;li&gt;  Notifications&lt;/li&gt;
&lt;li&gt;  Streaming progress updates from a server&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the client also needs to send frequent messages, use normal HTTP&lt;br&gt;
requests alongside SSE or consider WebSockets.&lt;/p&gt;

&lt;h4&gt;
  
  
  When Should You Use Each Approach?
&lt;/h4&gt;




&lt;p&gt;Use case                            Suitable approach&lt;/p&gt;




&lt;p&gt;Checking order status every 30      Short polling&lt;br&gt;
  seconds                             &lt;/p&gt;

&lt;p&gt;Dashboard with occasional updates   Polling or SSE&lt;/p&gt;

&lt;p&gt;Live chat application               WebSockets&lt;/p&gt;

&lt;p&gt;Multiplayer online games            WebSockets&lt;/p&gt;

&lt;p&gt;Live stock price updates            WebSockets or streaming technology&lt;/p&gt;

&lt;p&gt;Collaborative document editing      WebSockets&lt;/p&gt;

&lt;p&gt;One-way live notifications          SSE&lt;/p&gt;

&lt;p&gt;Background job progress             SSE, WebSockets, or polling&lt;br&gt;
                                      depending on requirements&lt;/p&gt;




&lt;h4&gt;
  
  
  How to Choose the Right Approach
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Choose Polling When
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;  Updates are occasional.&lt;/li&gt;
&lt;li&gt;  A small delay is acceptable.&lt;/li&gt;
&lt;li&gt;  You want a simple implementation.&lt;/li&gt;
&lt;li&gt;  The client only needs to check status periodically.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Choose Long Polling When
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;  Updates are infrequent but should be delivered soon after they
occur.&lt;/li&gt;
&lt;li&gt;  You want to avoid frequent empty polling responses.&lt;/li&gt;
&lt;li&gt;  WebSockets are not available or are not justified.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Choose WebSockets When
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;  You need two-way communication.&lt;/li&gt;
&lt;li&gt;  Updates are frequent.&lt;/li&gt;
&lt;li&gt;  Low latency matters.&lt;/li&gt;
&lt;li&gt;  Users interact continuously, as in chat or multiplayer games.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Choose SSE When
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;  The server needs to stream updates to the client.&lt;/li&gt;
&lt;li&gt;  The client does not need a persistent two-way channel.&lt;/li&gt;
&lt;li&gt;  You want an HTTP-based streaming mechanism.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Real-World Example: A Chat Application
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Using Polling
&lt;/h5&gt;

&lt;p&gt;The client asks the server every few seconds whether a new message has&lt;br&gt;
arrived. This can work for a basic prototype, but it may cause&lt;br&gt;
unnecessary requests and delayed message delivery.&lt;/p&gt;

&lt;h5&gt;
  
  
  Using WebSockets
&lt;/h5&gt;

&lt;p&gt;The client establishes a WebSocket connection. When another user sends a&lt;br&gt;
message, the server can push it through the active connection.&lt;/p&gt;

&lt;p&gt;A production chat system also needs message persistence, delivery&lt;br&gt;
acknowledgements, offline message handling, authentication,&lt;br&gt;
reconnection, and a strategy for multiple server instances.&lt;/p&gt;

&lt;h4&gt;
  
  
  Important System Design Considerations for WebSockets
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. Connection Management
&lt;/h5&gt;

&lt;p&gt;Track active connections and clean them up when clients disconnect. Do&lt;br&gt;
not assume an open connection is always healthy.&lt;/p&gt;

&lt;h5&gt;
  
  
  2. Reconnection
&lt;/h5&gt;

&lt;p&gt;Clients should reconnect after temporary network failures. Use&lt;br&gt;
exponential backoff with jitter so many clients do not reconnect&lt;br&gt;
simultaneously after an outage.&lt;/p&gt;

&lt;h5&gt;
  
  
  3. Heartbeats
&lt;/h5&gt;

&lt;p&gt;Ping/pong messages can help detect dead or unresponsive connections and&lt;br&gt;
clean up stale connection state.&lt;/p&gt;

&lt;h5&gt;
  
  
  4. Scaling Across Multiple Servers
&lt;/h5&gt;

&lt;p&gt;A user's WebSocket connection may be held by one application server&lt;br&gt;
while an event is produced on another. A shared message broker or&lt;br&gt;
pub/sub system can distribute events to the server that owns the&lt;br&gt;
connection.&lt;/p&gt;

&lt;h5&gt;
  
  
  5. Authentication and Authorization
&lt;/h5&gt;

&lt;p&gt;Authenticate clients during connection setup and authorize each&lt;br&gt;
subscription or message. A connected user should not automatically be&lt;br&gt;
allowed to access every room or resource.&lt;/p&gt;

&lt;h5&gt;
  
  
  6. Load Balancing
&lt;/h5&gt;

&lt;p&gt;Configure infrastructure to support long-lived connections, appropriate&lt;br&gt;
timeouts, and connection limits. Sticky sessions may help in some&lt;br&gt;
designs, but they do not replace a cross-server messaging strategy.&lt;/p&gt;

&lt;h5&gt;
  
  
  7. Message Delivery
&lt;/h5&gt;

&lt;p&gt;A successful WebSocket send does not necessarily mean the recipient has&lt;br&gt;
processed or permanently stored the message. Applications that need&lt;br&gt;
reliable delivery require acknowledgements, message IDs, persistence,&lt;br&gt;
and retry or replay logic.&lt;/p&gt;

&lt;h4&gt;
  
  
  Quick Interview Question
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; You are designing a WhatsApp-like chat application. Would&lt;br&gt;
you use polling or WebSockets?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample answer:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;"I would choose WebSockets because chat requires low-latency, two-way&lt;br&gt;
communication. Once the connection is established, both users can&lt;br&gt;
exchange messages without repeatedly requesting updates. I would also&lt;br&gt;
design for reconnection, authentication, message delivery, persistence,&lt;br&gt;
and horizontal scaling."&lt;/p&gt;

&lt;h5&gt;
  
  
  Follow-Up: Are WebSockets Always Better Than Polling?
&lt;/h5&gt;

&lt;p&gt;No.&amp;nbsp;If updates are infrequent and a delay is acceptable, polling can be&lt;br&gt;
simpler and cheaper to operate. The communication pattern should match&lt;br&gt;
the product requirement.&lt;/p&gt;

&lt;h5&gt;
  
  
  Follow-Up: What If the User Goes Offline?
&lt;/h5&gt;

&lt;p&gt;The server should not rely on an active WebSocket connection to store&lt;br&gt;
messages. Persist messages, track delivery state, and deliver pending&lt;br&gt;
messages when the user reconnects.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Takeaway
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Short polling:&lt;/strong&gt; The client repeatedly asks, "Any updates?"&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Long polling:&lt;/strong&gt; The client asks, and the server waits until
something changes or a timeout occurs.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;WebSockets:&lt;/strong&gt; Client and server maintain an open, two-way
communication channel.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;SSE:&lt;/strong&gt; The server continuously sends updates to the client over a
one-way stream.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choose based on how frequently updates happen, how quickly they must&lt;br&gt;
arrive, whether communication is one-way or two-way, and the complexity&lt;br&gt;
your system can support.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Monolith vs. Microservices Explained Using a Cafe Example</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Thu, 29 Oct 2026 14:33:14 +0000</pubDate>
      <link>https://dev.to/khushindpatel/monolith-vs-microservices-explained-using-a-cafe-example-14jl</link>
      <guid>https://dev.to/khushindpatel/monolith-vs-microservices-explained-using-a-cafe-example-14jl</guid>
      <description>&lt;h4&gt;
  
  
  What Is a Monolith?
&lt;/h4&gt;

&lt;p&gt;Imagine a café where one kitchen handles everything: taking orders,&lt;br&gt;
preparing food, managing payments, and tracking inventory. All functions&lt;br&gt;
work together as one system.&lt;/p&gt;

&lt;p&gt;In software, a &lt;strong&gt;monolithic architecture&lt;/strong&gt; is an application where&lt;br&gt;
different features are built as part of one application and are&lt;br&gt;
typically packaged and deployed together.&lt;/p&gt;

&lt;p&gt;For example, an e-commerce application might include user login, product&lt;br&gt;
catalog, shopping cart, payments, and orders. These features can still&lt;br&gt;
be organized into separate modules; the key point is that they are&lt;br&gt;
usually deployed as one application.&lt;/p&gt;

&lt;h4&gt;
  
  
  What Are Microservices?
&lt;/h4&gt;

&lt;p&gt;Now imagine the café grows into a food court. One team manages orders,&lt;br&gt;
another handles payments, another manages inventory, and another handles&lt;br&gt;
delivery. Each team operates its own service and communicates with other&lt;br&gt;
services when needed.&lt;/p&gt;

&lt;p&gt;In software, &lt;strong&gt;microservices architecture&lt;/strong&gt; splits an application into&lt;br&gt;
smaller, independently deployable services, each responsible for a&lt;br&gt;
specific business capability.&lt;/p&gt;

&lt;p&gt;An e-commerce application could have user, product, order, payment, and&lt;br&gt;
inventory services. Each service can be deployed and scaled&lt;br&gt;
independently. Services often own their data and communicate through&lt;br&gt;
APIs or messages, depending on the design.&lt;/p&gt;

&lt;h4&gt;
  
  
  Monolith vs.&amp;nbsp;Microservices
&lt;/h4&gt;




&lt;p&gt;Feature                 Monolith                Microservices&lt;/p&gt;




&lt;p&gt;Structure               One application         Multiple independent&lt;br&gt;
                                                  services&lt;/p&gt;

&lt;p&gt;Deployment              Usually deployed        Services can be&lt;br&gt;
                          together                deployed separately&lt;/p&gt;

&lt;p&gt;Development             Simpler initially       More coordination and&lt;br&gt;
                                                  infrastructure&lt;/p&gt;

&lt;p&gt;Scaling                 Often scale the         Scale individual&lt;br&gt;
                          application as a whole  services&lt;/p&gt;

&lt;p&gt;Failure handling        A failure can affect    Failures can be&lt;br&gt;
                          the whole application   isolated, but not&lt;br&gt;
                                                  automatically&lt;/p&gt;

&lt;p&gt;Communication           Often in-process        Network calls or&lt;br&gt;
                          function calls          messages&lt;/p&gt;

&lt;p&gt;Data management         Often one shared        Services own data where&lt;br&gt;
                          database                appropriate&lt;/p&gt;

&lt;p&gt;Best fit                Early products and many Systems needing&lt;br&gt;
                          small-to-medium systems independent scaling or&lt;br&gt;
                                                  team ownership&lt;/p&gt;




&lt;h4&gt;
  
  
  Advantages of a Monolith
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. Simpler to Build
&lt;/h5&gt;

&lt;p&gt;The codebase and deployment process are often easier to understand when&lt;br&gt;
starting a new product.&lt;/p&gt;

&lt;h5&gt;
  
  
  2. Easier Local Development and Testing
&lt;/h5&gt;

&lt;p&gt;Developers can run much of the application in one place, and function&lt;br&gt;
calls within the application do not need network communication.&lt;/p&gt;

&lt;h5&gt;
  
  
  3. Straightforward Transactions
&lt;/h5&gt;

&lt;p&gt;When related data is stored in one database, transactions across related&lt;br&gt;
operations can be easier to implement.&lt;/p&gt;

&lt;h5&gt;
  
  
  4. Lower Operational Overhead
&lt;/h5&gt;

&lt;p&gt;You may need fewer deployment pipelines, monitoring configurations, and&lt;br&gt;
infrastructure components.&lt;/p&gt;

&lt;h4&gt;
  
  
  Disadvantages of a Monolith
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. Scaling Can Be Less Targeted
&lt;/h5&gt;

&lt;p&gt;If order processing receives heavy traffic but inventory does not, you&lt;br&gt;
may have to scale the entire application even when only one part needs&lt;br&gt;
more resources.&lt;/p&gt;

&lt;h5&gt;
  
  
  2. Releases Can Be Coupled
&lt;/h5&gt;

&lt;p&gt;A small change in one module may require deploying the whole&lt;br&gt;
application, depending on the architecture and deployment setup.&lt;/p&gt;

&lt;h5&gt;
  
  
  3. The Codebase Can Become Hard to Maintain
&lt;/h5&gt;

&lt;p&gt;Without clear module boundaries, features can become tightly coupled and&lt;br&gt;
changes can affect unexpected parts of the system.&lt;/p&gt;

&lt;p&gt;A monolith is not automatically poorly designed. A &lt;strong&gt;modular monolith&lt;/strong&gt;&lt;br&gt;
with clear boundaries can remain maintainable for a long time.&lt;/p&gt;

&lt;h4&gt;
  
  
  Advantages of Microservices
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. Independent Scaling
&lt;/h5&gt;

&lt;p&gt;If the order service receives much more traffic than the product&lt;br&gt;
service, you can scale the order service without scaling every other&lt;br&gt;
service.&lt;/p&gt;

&lt;h5&gt;
  
  
  2. Independent Deployment
&lt;/h5&gt;

&lt;p&gt;Teams can release a service separately when its interfaces and&lt;br&gt;
compatibility are managed carefully.&lt;/p&gt;

&lt;h5&gt;
  
  
  3. Clear Ownership
&lt;/h5&gt;

&lt;p&gt;Teams can own specific business capabilities, code, and operational&lt;br&gt;
responsibilities.&lt;/p&gt;

&lt;h5&gt;
  
  
  4. Technology Flexibility
&lt;/h5&gt;

&lt;p&gt;Different services can use different technologies when there is a real&lt;br&gt;
reason to do so. This flexibility also introduces more maintenance work.&lt;/p&gt;

&lt;h4&gt;
  
  
  Disadvantages of Microservices
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. More Operational Complexity
&lt;/h5&gt;

&lt;p&gt;You need to manage service discovery, deployment, configuration,&lt;br&gt;
observability, security, and networking across multiple services.&lt;/p&gt;

&lt;h5&gt;
  
  
  2. Network Failures
&lt;/h5&gt;

&lt;p&gt;A service call can time out or fail even when the calling service is&lt;br&gt;
healthy. Systems need timeouts, retries, and sometimes circuit breakers.&lt;/p&gt;

&lt;h5&gt;
  
  
  3. Data Consistency Is Harder
&lt;/h5&gt;

&lt;p&gt;A business operation may involve several services and databases.&lt;br&gt;
Distributed transactions are complex, so systems often use eventual&lt;br&gt;
consistency, events, or sagas where appropriate.&lt;/p&gt;

&lt;h5&gt;
  
  
  4. Debugging Can Be Harder
&lt;/h5&gt;

&lt;p&gt;A single user request may travel through several services. Distributed&lt;br&gt;
tracing and centralized logs can help teams understand what happened.&lt;/p&gt;

&lt;h5&gt;
  
  
  5. More Infrastructure and Cost
&lt;/h5&gt;

&lt;p&gt;Each service needs appropriate deployment, monitoring, scaling, and&lt;br&gt;
operational support. For a small team, this overhead may outweigh the&lt;br&gt;
benefits.&lt;/p&gt;

&lt;h4&gt;
  
  
  When Should You Use a Monolith?
&lt;/h4&gt;

&lt;p&gt;A monolith is often a good choice when: - You are building an MVP or a&lt;br&gt;
new product. - The team is small. - Requirements are changing&lt;br&gt;
frequently. - You want simpler testing, deployment, and debugging. - You&lt;br&gt;
do not yet need independent scaling for different features.&lt;/p&gt;

&lt;p&gt;A good starting point is often a &lt;strong&gt;modular monolith&lt;/strong&gt;: one deployable&lt;br&gt;
application, with clear boundaries between business modules.&lt;/p&gt;

&lt;h4&gt;
  
  
  When Should You Use Microservices?
&lt;/h4&gt;

&lt;p&gt;Microservices may be a better fit when: - Different parts of the&lt;br&gt;
application have very different scaling needs. - Multiple teams need to&lt;br&gt;
release services independently. - The product has clear business&lt;br&gt;
boundaries. - The organization can manage distributed systems,&lt;br&gt;
monitoring, networking, and failure recovery. - The benefits of&lt;br&gt;
independent ownership and deployment outweigh the added complexity.&lt;/p&gt;

&lt;p&gt;Do not choose microservices only because the company is growing or&lt;br&gt;
because they sound more modern. Choose them to solve concrete problems.&lt;/p&gt;

&lt;h4&gt;
  
  
  How Can a Monolith Evolve into Microservices?
&lt;/h4&gt;

&lt;p&gt;Imagine your café becomes extremely popular. Initially, one kitchen&lt;br&gt;
handles everything. Later, online orders increase dramatically, but&lt;br&gt;
inventory management remains small.&lt;/p&gt;

&lt;p&gt;You could extract order processing into its own service so it can scale&lt;br&gt;
independently. Over time, other capabilities might be separated when&lt;br&gt;
there is a clear benefit.&lt;/p&gt;

&lt;p&gt;A common migration approach is the &lt;strong&gt;Strangler Fig pattern&lt;/strong&gt;: new&lt;br&gt;
functionality is built outside the old system, and capabilities are&lt;br&gt;
gradually moved over until the old implementation can be retired. This&lt;br&gt;
should be done incrementally, with clear service boundaries and a safe&lt;br&gt;
migration plan.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: An E-Commerce Application
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Monolithic Design
&lt;/h5&gt;

&lt;p&gt;A single application contains login, product catalog, cart, orders,&lt;br&gt;
payments, and inventory modules. The modules may share a database and&lt;br&gt;
are deployed together.&lt;/p&gt;

&lt;h5&gt;
  
  
  Microservices Design
&lt;/h5&gt;

&lt;p&gt;Separate services manage users, products, orders, payments, and&lt;br&gt;
inventory. The order service may call the payment service and&lt;br&gt;
communicate with inventory through an API or message queue.&lt;/p&gt;

&lt;p&gt;This creates independent deployment and scaling options, but also means&lt;br&gt;
teams must handle network failures, duplicate messages, and consistency&lt;br&gt;
between services.&lt;/p&gt;

&lt;h4&gt;
  
  
  Quick Interview Question
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; If you were building a new e-commerce application today,&lt;br&gt;
would you choose a monolith or microservices?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sample answer:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;"I would start with a modular monolith unless there were clear&lt;br&gt;
requirements for independent deployment, scaling, or team ownership. It&lt;br&gt;
keeps the initial architecture simpler and helps the team validate the&lt;br&gt;
product. As the application grows, I would extract services based on&lt;br&gt;
measurable bottlenecks and clear business boundaries rather than&lt;br&gt;
splitting everything from day one."&lt;/p&gt;

&lt;h5&gt;
  
  
  Follow-Up: Can a Monolith Handle Millions of Users?
&lt;/h5&gt;

&lt;p&gt;Yes, depending on the workload, architecture, infrastructure, and&lt;br&gt;
optimization. A monolith can be replicated across multiple servers and&lt;br&gt;
use caching, load balancing, and database scaling. User count alone does&lt;br&gt;
not determine whether microservices are necessary.&lt;/p&gt;

&lt;h5&gt;
  
  
  Follow-Up: Are Microservices More Reliable?
&lt;/h5&gt;

&lt;p&gt;Not automatically. They can isolate some failures, but they also&lt;br&gt;
introduce network dependencies and more failure modes. Reliability&lt;br&gt;
depends on architecture, observability, timeouts, retries, capacity&lt;br&gt;
planning, and operational practices.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Takeaway
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Monolith:&lt;/strong&gt; One application, usually deployed as a unit.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Microservices:&lt;/strong&gt; Multiple independently deployable services
working together.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Best practice:&lt;/strong&gt; Choose the simplest architecture that meets
current needs, keep boundaries clear, and evolve the design as real
requirements emerge.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>architecture</category>
      <category>microservices</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Rate Limiting Explained Using a Cafe Example</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Fri, 23 Oct 2026 14:04:06 +0000</pubDate>
      <link>https://dev.to/khushindpatel/rate-limiting-explained-using-a-cafe-example-4mmo</link>
      <guid>https://dev.to/khushindpatel/rate-limiting-explained-using-a-cafe-example-4mmo</guid>
      <description>&lt;h4&gt;
  
  
  What Is Rate Limiting?
&lt;/h4&gt;

&lt;p&gt;Imagine a busy café where hundreds of customers arrive at the same time.&lt;br&gt;
The café has limited staff and equipment, so it cannot handle unlimited&lt;br&gt;
orders at once. The manager sets a rule to control how many orders can&lt;br&gt;
be placed within a certain time.&lt;/p&gt;

&lt;p&gt;Software systems use the same idea. &lt;strong&gt;Rate limiting controls how many&lt;br&gt;
requests a user, application, or IP address can make within a specific&lt;br&gt;
time period.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For example, an API might allow each user to make 100 requests per&lt;br&gt;
minute. If a user exceeds the limit, the system can reject extra&lt;br&gt;
requests, usually with HTTP status code &lt;code&gt;429 Too Many Requests&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  How Does Rate Limiting Work?
&lt;/h4&gt;

&lt;p&gt;Think of the café manager as the rate limiter.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; A customer sends an order. In software, this is an API request.&lt;/li&gt;
&lt;li&gt; The manager checks how many orders that customer has already placed
during the time window.&lt;/li&gt;
&lt;li&gt; If the customer is within the limit, the order is accepted.&lt;/li&gt;
&lt;li&gt; If the customer has exceeded the limit, the request is rejected or
delayed according to the policy.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In a real application, the rate limiter might run in an API gateway,&lt;br&gt;
reverse proxy, application middleware, or dedicated service. It usually&lt;br&gt;
tracks usage by a key such as a user ID, API key, IP address, or&lt;br&gt;
endpoint.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why Do We Need Rate Limiting?
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. To Protect Servers from Overload
&lt;/h5&gt;

&lt;p&gt;Too many requests can exhaust CPU, memory, database connections, or&lt;br&gt;
other resources. Rate limiting helps control incoming traffic so the&lt;br&gt;
system has a better chance of staying responsive.&lt;/p&gt;

&lt;h5&gt;
  
  
  2. To Prevent Abuse
&lt;/h5&gt;

&lt;p&gt;A login API without limits could be targeted by someone repeatedly&lt;br&gt;
trying passwords or requesting OTPs. Rate limiting makes excessive&lt;br&gt;
attempts harder. It should be combined with authentication, monitoring,&lt;br&gt;
and abuse detection.&lt;/p&gt;

&lt;h5&gt;
  
  
  3. To Ensure Fair Usage
&lt;/h5&gt;

&lt;p&gt;Imagine one café customer placing hundreds of orders while everyone else&lt;br&gt;
waits. Per-user limits help prevent one client from consuming all&lt;br&gt;
available capacity.&lt;/p&gt;

&lt;h5&gt;
  
  
  4. To Control Costs
&lt;/h5&gt;

&lt;p&gt;Some operations are expensive, such as AI generation, sending SMS&lt;br&gt;
messages, or calling paid third-party APIs. Rate limits can help control&lt;br&gt;
usage and reduce unexpected costs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Where Is Rate Limiting Used?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Login and OTP APIs:&lt;/strong&gt; Limit repeated login attempts or OTP
requests.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Public APIs:&lt;/strong&gt; Keep usage within published quotas.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Search endpoints:&lt;/strong&gt; Prevent excessive or automated searches.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Payment APIs:&lt;/strong&gt; Protect services from excessive requests while
preserving correct payment handling.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;AI APIs:&lt;/strong&gt; Limit requests or tokens to manage capacity and cost.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Social media platforms:&lt;/strong&gt; Limit actions such as posting,
commenting, or sending messages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The limit should fit the operation. A password-reset endpoint may need a&lt;br&gt;
stricter limit than a public read-only endpoint.&lt;/p&gt;

&lt;h4&gt;
  
  
  Common Rate Limiting Algorithms
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. Fixed Window Counter
&lt;/h5&gt;

&lt;p&gt;Imagine the café resets each customer's order counter at the start of&lt;br&gt;
every minute. A customer can place up to 100 orders during that minute.&lt;/p&gt;

&lt;p&gt;The system counts requests in fixed time windows, such as 10:00--10:01&lt;br&gt;
and 10:01--10:02.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Simple to implement and efficient.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantage:&lt;/strong&gt; Traffic can spike around a window boundary. A user&lt;br&gt;
could make 100 requests just before the minute ends and another 100&lt;br&gt;
immediately after it begins.&lt;/p&gt;

&lt;h5&gt;
  
  
  2. Sliding Window Log
&lt;/h5&gt;

&lt;p&gt;The system records request timestamps. For each new request, it counts&lt;br&gt;
how many requests occurred in the previous time period, such as the last&lt;br&gt;
60 seconds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Accurate rolling-window enforcement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt; Storing many timestamps can use significant memory&lt;br&gt;
and processing, especially for high-volume clients.&lt;/p&gt;

&lt;h5&gt;
  
  
  3. Sliding Window Counter
&lt;/h5&gt;

&lt;p&gt;This approach combines counts from the current and previous fixed&lt;br&gt;
windows, weighting the previous window according to how much of it&lt;br&gt;
overlaps the rolling time period.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; A practical balance between accuracy and memory use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt; It estimates the rolling count rather than tracking&lt;br&gt;
every request timestamp exactly.&lt;/p&gt;

&lt;h5&gt;
  
  
  4. Token Bucket
&lt;/h5&gt;

&lt;p&gt;Imagine each customer has a bucket containing tokens. Every request&lt;br&gt;
costs one token, and tokens refill at a steady rate. If a token is&lt;br&gt;
available, the request is allowed. If the bucket is empty, the request&lt;br&gt;
is rejected or delayed.&lt;/p&gt;

&lt;p&gt;A bucket with a capacity of 10 tokens might allow a burst of 10&lt;br&gt;
requests, while refilling at 2 tokens per second.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Allows controlled bursts while limiting the average&lt;br&gt;
request rate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt; Requires choosing the right bucket capacity and&lt;br&gt;
refill rate.&lt;/p&gt;

&lt;h5&gt;
  
  
  5. Leaky Bucket
&lt;/h5&gt;

&lt;p&gt;Imagine orders entering a container and leaving at a steady pace. If&lt;br&gt;
orders arrive faster than they can be processed, they wait in the&lt;br&gt;
container. If it fills up, new orders are rejected. Depending on&lt;br&gt;
implementation, a leaky bucket may queue requests or reject excess&lt;br&gt;
requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages:&lt;/strong&gt; Smooths incoming traffic and helps control output rate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages:&lt;/strong&gt; A queue can add latency, and excess requests still&lt;br&gt;
need a defined policy.&lt;/p&gt;

&lt;h4&gt;
  
  
  Which Algorithm Should You Choose?
&lt;/h4&gt;

&lt;p&gt;Requirement                                         Possible choice&lt;/p&gt;




&lt;p&gt;Simple quota with low implementation complexity     Fixed Window&lt;br&gt;
  Accurate rolling time limit                         Sliding Window Log&lt;br&gt;
  Efficient rolling-window approximation              Sliding Window Counter&lt;br&gt;
  Allow short bursts while controlling average rate   Token Bucket&lt;br&gt;
  Smooth traffic into a steady rate                   Leaky Bucket&lt;/p&gt;

&lt;p&gt;There is no single best algorithm for every system. Choose based on&lt;br&gt;
whether bursts should be allowed, how accurate the limit must be,&lt;br&gt;
available storage, and the traffic pattern.&lt;/p&gt;

&lt;h4&gt;
  
  
  How to Implement Rate Limiting in a Real System
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Step 1: Define the Limit
&lt;/h5&gt;

&lt;p&gt;Decide what is being limited and the allowed rate. For example, 100&lt;br&gt;
requests per minute per authenticated user for a search endpoint.&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 2: Choose the Rate-Limit Key
&lt;/h5&gt;

&lt;p&gt;Common keys include user ID, API key, IP address, or a combination of&lt;br&gt;
user and endpoint. IP-only limits can affect multiple legitimate users&lt;br&gt;
behind the same network, while user-only limits may not protect an&lt;br&gt;
unauthenticated endpoint.&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 3: Choose Where the Limiter Runs
&lt;/h5&gt;

&lt;p&gt;An API gateway or reverse proxy can apply limits before requests reach&lt;br&gt;
application servers. Application middleware can enforce rules close to&lt;br&gt;
the endpoint. A shared service or data store can coordinate limits&lt;br&gt;
across multiple application instances.&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 4: Store and Update Usage Safely
&lt;/h5&gt;

&lt;p&gt;If the application runs on multiple servers, a local in-memory counter&lt;br&gt;
on each server may allow a user to exceed the intended global limit. A&lt;br&gt;
shared store such as Redis can help coordinate counters, but updates&lt;br&gt;
must be atomic and the design should account for latency and store&lt;br&gt;
failures.&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 5: Decide What Happens When the Limit Is Reached
&lt;/h5&gt;

&lt;p&gt;Common policies include rejecting the request, delaying it, or placing&lt;br&gt;
eligible work in a queue. For HTTP APIs, return &lt;code&gt;429 Too Many Requests&lt;/code&gt;.&lt;br&gt;
If useful, include a &lt;code&gt;Retry-After&lt;/code&gt; header to indicate when the client&lt;br&gt;
can try again.&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 6: Monitor and Tune
&lt;/h5&gt;

&lt;p&gt;Track rejected requests, traffic patterns, latency, and usage by&lt;br&gt;
endpoint or client. Adjust limits based on real capacity and legitimate&lt;br&gt;
user behavior.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: An API with a Limit of 5 Requests per Minute
&lt;/h4&gt;

&lt;p&gt;Suppose a user can make five search requests per minute.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Requests 1--5: allowed.&lt;/li&gt;
&lt;li&gt;  Request 6 during the same applicable window: rejected with
&lt;code&gt;429 Too Many Requests&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  After enough time has passed for the algorithm's window or tokens to
reset or refill, requests can be allowed again.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The exact reset behavior depends on the chosen algorithm. A token bucket&lt;br&gt;
refills gradually rather than necessarily resetting all at once.&lt;/p&gt;

&lt;h4&gt;
  
  
  Important Design Considerations
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Rate Limiting vs.&amp;nbsp;Load Shedding
&lt;/h5&gt;

&lt;p&gt;Rate limiting enforces usage rules, often per user or client. Load&lt;br&gt;
shedding rejects selected work when a system is overloaded to help&lt;br&gt;
protect overall health. A production system may use both.&lt;/p&gt;

&lt;h5&gt;
  
  
  Rate Limiting vs.&amp;nbsp;Throttling
&lt;/h5&gt;

&lt;p&gt;These terms are sometimes used interchangeably. Rate limiting defines or&lt;br&gt;
enforces a request rate; throttling can also mean slowing down or&lt;br&gt;
delaying requests rather than immediately rejecting them.&lt;/p&gt;

&lt;h5&gt;
  
  
  Distributed Systems
&lt;/h5&gt;

&lt;p&gt;When requests are served by several application instances, the system&lt;br&gt;
needs a consistent way to apply the limit. A shared data store or&lt;br&gt;
gateway can help, but it introduces its own availability and latency&lt;br&gt;
trade-offs.&lt;/p&gt;

&lt;h5&gt;
  
  
  Client Behavior
&lt;/h5&gt;

&lt;p&gt;Clients should handle &lt;code&gt;429&lt;/code&gt; responses sensibly. They can wait before&lt;br&gt;
retrying, respect &lt;code&gt;Retry-After&lt;/code&gt; when provided, and use exponential&lt;br&gt;
backoff with jitter where appropriate. Retrying immediately can make&lt;br&gt;
overload worse.&lt;/p&gt;

&lt;h5&gt;
  
  
  Rate Limits Are Not a Complete Security Solution
&lt;/h5&gt;

&lt;p&gt;Rate limiting helps reduce abuse, but it does not replace&lt;br&gt;
authentication, authorization, fraud detection, input validation, or&lt;br&gt;
monitoring.&lt;/p&gt;

&lt;h4&gt;
  
  
  Quick Interview Question
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; An API allows 100 requests per minute. A user sends 100&lt;br&gt;
requests in the first 10 seconds and then sends one more request during&lt;br&gt;
that minute. Should the 101st request be allowed?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt; Under a fixed-window limit of 100 requests for that minute,&lt;br&gt;
the 101st request should be rejected. However, the answer can differ&lt;br&gt;
with a token bucket or another policy, so state the algorithm and&lt;br&gt;
time-window behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Follow-up:&lt;/strong&gt; How would you enforce the limit when the application runs&lt;br&gt;
on 10 servers?&lt;/p&gt;

&lt;p&gt;A strong answer mentions a shared rate-limit store or gateway, atomic&lt;br&gt;
updates, a clear key such as user ID or API key, and a plan for what&lt;br&gt;
happens if the shared store is unavailable.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Takeaway
&lt;/h4&gt;

&lt;p&gt;Rate limiting is like a café manager controlling how many orders each&lt;br&gt;
customer can place in a given time. It protects system capacity,&lt;br&gt;
supports fair usage, reduces abuse, and controls costs. The right design&lt;br&gt;
depends on the required limit, whether bursts are allowed, and how&lt;br&gt;
requests are distributed across servers.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Message Queues Explained Using a Cafe Example</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Mon, 19 Oct 2026 13:07:20 +0000</pubDate>
      <link>https://dev.to/khushindpatel/message-queues-explained-using-a-cafe-example-31</link>
      <guid>https://dev.to/khushindpatel/message-queues-explained-using-a-cafe-example-31</guid>
      <description>&lt;h4&gt;
  
  
  What Is a Message Queue?
&lt;/h4&gt;

&lt;p&gt;Imagine a busy café during lunch time. Many customers place orders at&lt;br&gt;
once, but the café has only four chefs. If the cashier had to wait for a&lt;br&gt;
chef to finish every order before accepting the next one, the line would&lt;br&gt;
move very slowly.&lt;/p&gt;

&lt;p&gt;Instead, the cashier writes each order on a ticket and puts it on a&lt;br&gt;
rack. The chefs pick up tickets when they are ready to cook. The cashier&lt;br&gt;
can keep accepting orders while the chefs work through the queue.&lt;/p&gt;

&lt;p&gt;That ticket rack is like a &lt;strong&gt;message queue&lt;/strong&gt; in software: it temporarily&lt;br&gt;
stores tasks or messages so the sender and receiver do not need to work&lt;br&gt;
at exactly the same time.&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbpofjoy1ut860nvp5rys.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbpofjoy1ut860nvp5rys.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Map the Café to Software
&lt;/h4&gt;

&lt;p&gt;Café                             Software&lt;/p&gt;



&lt;p&gt;Customer's order                 Message or task&lt;br&gt;
  Cashier who creates the ticket   Producer&lt;br&gt;
  Ticket rack                      Message queue&lt;br&gt;
  Chef who picks up a ticket       Consumer or worker&lt;br&gt;
  Preparing the order              Processing the message&lt;br&gt;
  Finished order                   Successfully processed message&lt;/p&gt;
&lt;h4&gt;
  
  
  How Does a Message Queue Work?
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt; A producer creates a message, such as "send an order confirmation
email."&lt;/li&gt;
&lt;li&gt; The producer sends the message to the queue.&lt;/li&gt;
&lt;li&gt; The queue stores it until a consumer is ready.&lt;/li&gt;
&lt;li&gt; A consumer receives the message and performs the task.&lt;/li&gt;
&lt;li&gt; After successful processing, the consumer acknowledges the message
so the queue knows it has been handled. The exact acknowledgement
and deletion behavior depends on the queue technology and
configuration.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The important point is that the producer usually does not have to wait&lt;br&gt;
for the full task to finish.&lt;/p&gt;
&lt;h4&gt;
  
  
  When Should You Use a Message Queue?
&lt;/h4&gt;
&lt;h5&gt;
  
  
  1. When a Task Can Happen in the Background
&lt;/h5&gt;

&lt;p&gt;After a customer places an order, the website should confirm the order&lt;br&gt;
quickly. Sending an email, generating an invoice, and notifying the&lt;br&gt;
warehouse can happen in the background.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Without a queue:&lt;/strong&gt; The customer request may wait for every task to&lt;br&gt;
finish.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With a queue:&lt;/strong&gt; The order service saves the order and schedules&lt;br&gt;
follow-up tasks. Background workers process those tasks separately.&lt;/p&gt;

&lt;p&gt;Use this when the user does not need to wait for the entire task to&lt;br&gt;
complete.&lt;/p&gt;
&lt;h5&gt;
  
  
  2. When Traffic Arrives in Sudden Bursts
&lt;/h5&gt;

&lt;p&gt;Imagine 200 orders arrive in one minute, but your workers can process&lt;br&gt;
only 80 orders per minute.&lt;/p&gt;

&lt;p&gt;The queue can temporarily hold the extra work. Workers keep processing&lt;br&gt;
at their available rate, and the backlog shrinks when incoming traffic&lt;br&gt;
slows.&lt;/p&gt;

&lt;p&gt;A queue &lt;strong&gt;buffers traffic; it does not magically increase processing&lt;br&gt;
capacity&lt;/strong&gt;. If messages arrive faster than they can be processed for a&lt;br&gt;
long time, the backlog will continue growing. You may need more workers,&lt;br&gt;
faster processing, rate limits, or a capacity change.&lt;/p&gt;
&lt;h5&gt;
  
  
  3. When Two Services Should Not Depend on Each Other Being Available at the Same Time
&lt;/h5&gt;

&lt;p&gt;Suppose your order service is working, but your email service is&lt;br&gt;
temporarily down. A queue can retain email tasks so they can be retried&lt;br&gt;
when the email service recovers, depending on your queue setup.&lt;/p&gt;

&lt;p&gt;This reduces the need for the order service to wait for every downstream&lt;br&gt;
service to be available.&lt;/p&gt;
&lt;h5&gt;
  
  
  4. When You Need Retries for Temporary Failures
&lt;/h5&gt;

&lt;p&gt;A worker might fail because of a temporary network problem or an&lt;br&gt;
unavailable external API. A queue system can support retrying the&lt;br&gt;
message.&lt;/p&gt;

&lt;p&gt;Retries should usually have a limit and a delay strategy. After repeated&lt;br&gt;
failures, the message can be moved to a &lt;strong&gt;dead-letter queue&lt;/strong&gt; for&lt;br&gt;
investigation instead of retrying forever.&lt;/p&gt;
&lt;h5&gt;
  
  
  5. When You Need to Process Many Independent Jobs
&lt;/h5&gt;

&lt;p&gt;Examples include resizing uploaded images, generating reports,&lt;br&gt;
processing payments through a carefully designed workflow, importing&lt;br&gt;
files, sending notifications, or running data pipelines.&lt;/p&gt;

&lt;p&gt;Queues are useful when work can be split into independent jobs and&lt;br&gt;
processed by one or more workers.&lt;/p&gt;
&lt;h4&gt;
  
  
  When Might You Not Need a Message Queue?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;The result is needed immediately.&lt;/strong&gt; If a user asks for their
current account balance, the application usually needs to fetch the
current result synchronously.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;The operation is simple and fast.&lt;/strong&gt; Adding a queue can create
extra infrastructure and complexity without much benefit.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;You need an immediate, definitive response.&lt;/strong&gt; A queue often means
the request is accepted for later processing, not that the work has
already succeeded.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;You cannot safely handle duplicate processing.&lt;/strong&gt; Many queue
systems can deliver a message more than once. Design consumers to be
idempotent, meaning processing the same message again does not
create an unwanted duplicate effect.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A system can combine both approaches: respond synchronously for the&lt;br&gt;
critical result, then queue non-critical follow-up tasks.&lt;/p&gt;
&lt;h4&gt;
  
  
  How to Use a Message Queue in a Real Application
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Step 1: Identify the Work That Can Be Done Later
&lt;/h5&gt;

&lt;p&gt;Start with a task that does not need to finish before the user receives&lt;br&gt;
the main response. For example: send a confirmation email after an order&lt;br&gt;
is saved.&lt;/p&gt;
&lt;h5&gt;
  
  
  Step 2: Choose a Queue Technology
&lt;/h5&gt;

&lt;p&gt;Common options include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;RabbitMQ:&lt;/strong&gt; Often used for task queues and routing messages
between services.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Apache Kafka:&lt;/strong&gt; Often used for high-volume event streams, durable
event logs, and consumers that may need to read or replay events.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Cloud-managed queues:&lt;/strong&gt; Services such as Amazon SQS or Google
Cloud Pub/Sub can reduce the work of managing queue infrastructure.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choose based on your delivery, ordering, throughput, replay, hosting,&lt;br&gt;
and operational requirements rather than popularity alone.&lt;/p&gt;
&lt;h5&gt;
  
  
  Step 3: Create a Clear Message Format
&lt;/h5&gt;

&lt;p&gt;Keep messages structured and versionable. For example:&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;"eventType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"OrderPlaced"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"orderId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ORD-1042"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"createdAt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-10-19T12:00:00Z"&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;Avoid putting unnecessary personal or sensitive data in messages. Often,&lt;br&gt;
an identifier such as &lt;code&gt;orderId&lt;/code&gt; is enough for a worker to retrieve the&lt;br&gt;
required details securely.&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 4: Publish the Message
&lt;/h5&gt;

&lt;p&gt;After the order is saved, the order service publishes an &lt;code&gt;OrderPlaced&lt;/code&gt;&lt;br&gt;
message. In production systems, think carefully about what happens if&lt;br&gt;
the database save succeeds but publishing the message fails. A common&lt;br&gt;
solution is the &lt;strong&gt;transactional outbox pattern&lt;/strong&gt;, which records the&lt;br&gt;
event in the same database transaction and publishes it reliably&lt;br&gt;
afterward.&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 5: Build a Consumer or Worker
&lt;/h5&gt;

&lt;p&gt;A separate worker subscribes to or polls the queue, reads the message,&lt;br&gt;
performs the task, and acknowledges success according to the&lt;br&gt;
technology's rules.&lt;/p&gt;

&lt;p&gt;For example, an email worker reads the order ID, fetches the order&lt;br&gt;
details, and sends the confirmation email.&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 6: Make Processing Safe to Retry
&lt;/h5&gt;

&lt;p&gt;A worker can finish its task but fail before its acknowledgement reaches&lt;br&gt;
the queue. The message may then be delivered again.&lt;/p&gt;

&lt;p&gt;Use idempotency where possible. For example, store a unique task or&lt;br&gt;
event ID and check whether the email or operation has already been&lt;br&gt;
completed before repeating it. For payments and other critical&lt;br&gt;
operations, use the payment provider's idempotency mechanisms and&lt;br&gt;
carefully designed state transitions.&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 7: Monitor the Queue
&lt;/h5&gt;

&lt;p&gt;Track: - Number of messages waiting - Age of the oldest message -&lt;br&gt;
Processing rate and failure rate - Retry count and dead-letter queue&lt;br&gt;
size - Consumer health and processing latency&lt;/p&gt;

&lt;p&gt;A growing queue can mean traffic has increased, workers are failing, or&lt;br&gt;
processing has become too slow.&lt;/p&gt;

&lt;h4&gt;
  
  
  Important Concepts to Know
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Producer
&lt;/h5&gt;

&lt;p&gt;The component that creates and sends messages. In our café, it is the&lt;br&gt;
cashier placing order tickets on the rack.&lt;/p&gt;

&lt;h5&gt;
  
  
  Consumer
&lt;/h5&gt;

&lt;p&gt;The component that receives and processes messages. In our café, it is a&lt;br&gt;
chef picking up a ticket.&lt;/p&gt;

&lt;h5&gt;
  
  
  Acknowledgement
&lt;/h5&gt;

&lt;p&gt;A signal that a message has been processed successfully. The queue's&lt;br&gt;
acknowledgement rules determine when a message can be considered&lt;br&gt;
complete.&lt;/p&gt;

&lt;h5&gt;
  
  
  Retry
&lt;/h5&gt;

&lt;p&gt;An attempt to process a message again after a temporary failure. Use&lt;br&gt;
bounded retries and appropriate delays.&lt;/p&gt;

&lt;h5&gt;
  
  
  Dead-Letter Queue
&lt;/h5&gt;

&lt;p&gt;A separate destination for messages that repeatedly fail, allowing&lt;br&gt;
investigation without blocking the normal flow.&lt;/p&gt;

&lt;h5&gt;
  
  
  Idempotency
&lt;/h5&gt;

&lt;p&gt;The ability to process the same message more than once without causing&lt;br&gt;
the same real-world effect multiple times. This matters because many&lt;br&gt;
systems provide &lt;strong&gt;at-least-once delivery&lt;/strong&gt;, not a guarantee that each&lt;br&gt;
message is delivered exactly once.&lt;/p&gt;

&lt;h5&gt;
  
  
  Ordering
&lt;/h5&gt;

&lt;p&gt;Some applications require messages to be processed in order, such as&lt;br&gt;
updates to the same account. Ordering guarantees depend on the queue&lt;br&gt;
technology and configuration and may reduce parallelism.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: An Online Shopping Order
&lt;/h4&gt;

&lt;p&gt;A customer clicks &lt;strong&gt;Place Order&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; The order service validates and saves the order.&lt;/li&gt;
&lt;li&gt; It publishes an &lt;code&gt;OrderPlaced&lt;/code&gt; event.&lt;/li&gt;
&lt;li&gt; Separate consumers handle tasks such as sending an email, creating
an invoice, notifying the warehouse, and updating analytics.&lt;/li&gt;
&lt;li&gt; If the email service is temporarily unavailable, the email task can
be retried without requiring the customer to submit the order again.&lt;/li&gt;
&lt;li&gt; The system monitors pending messages and failures so problems are
visible.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For critical workflows, do not assume that sending a message alone&lt;br&gt;
completes a payment or guarantees delivery. Track each step's status and&lt;br&gt;
design recovery behavior.&lt;/p&gt;

&lt;h4&gt;
  
  
  Quick Interview Question
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; Your application receives 200 jobs per minute, but workers&lt;br&gt;
can process only 80 jobs per minute. What happens when you add a message&lt;br&gt;
queue?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt; The queue stores the jobs that workers cannot process&lt;br&gt;
immediately, so the application can absorb a short burst. The workers&lt;br&gt;
still process only about 80 jobs per minute. If the incoming rate stays&lt;br&gt;
at 200 per minute, the backlog grows by roughly 120 jobs per minute&lt;br&gt;
until capacity increases or incoming traffic falls.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Follow-up:&lt;/strong&gt; What would you do if the queue keeps growing?&lt;/p&gt;

&lt;p&gt;Possible answers: add more consumers if the work can be parallelized,&lt;br&gt;
optimize slow processing, apply rate limits or backpressure, and&lt;br&gt;
investigate errors or downstream bottlenecks.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Takeaway
&lt;/h4&gt;

&lt;p&gt;A message queue is like the café's ticket rack. The producer adds work,&lt;br&gt;
the queue holds it, and consumers process it when they are ready. Use&lt;br&gt;
queues for background work, traffic bursts, service decoupling, and&lt;br&gt;
retryable jobs---but plan for failures, duplicate delivery, monitoring,&lt;br&gt;
and growing backlogs.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>beginners</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>CAP Theorem Explained Through a Cafe Example</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Fri, 16 Oct 2026 12:42:43 +0000</pubDate>
      <link>https://dev.to/khushindpatel/cap-theorem-explained-through-a-cafe-example-4ag8</link>
      <guid>https://dev.to/khushindpatel/cap-theorem-explained-through-a-cafe-example-4ag8</guid>
      <description>&lt;p&gt;Imagine you own a cafe with two branches. Both branches sell chocolate cakes and share their stock information.&lt;/p&gt;

&lt;p&gt;One day, the internet connection between the two branches stops working.&lt;/p&gt;

&lt;p&gt;Branch A sells the last chocolate cake, but Branch B does not know about it. Branch B still thinks one cake is available.&lt;/p&gt;

&lt;p&gt;This situation helps us understand CAP theorem.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. C — Consistency
&lt;/h3&gt;

&lt;p&gt;Both branches should have correct, up-to-date information.&lt;/p&gt;

&lt;p&gt;Branch A sold the last cake, so Branch B should not promise that same cake to another customer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In simple words:&lt;/strong&gt; Don't show incorrect or outdated data when strong consistency is required.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. A — Availability
&lt;/h3&gt;

&lt;p&gt;The café should keep serving customers.&lt;/p&gt;

&lt;p&gt;Even though Branch B cannot contact Branch A, it continues accepting orders using the information it has. However, it might accept an order for a cake that is already sold out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In simple words:&lt;/strong&gt; Keep responding to customers, even when the latest information is unavailable.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. P — Partition Tolerance
&lt;/h3&gt;

&lt;p&gt;The café should handle a broken connection between its branches.&lt;/p&gt;

&lt;p&gt;Even if Branch A and Branch B cannot communicate, the system must deal with the network failure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In simple words:&lt;/strong&gt; Handle communication failures between servers.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. What Does CAP Theorem Mean?
&lt;/h3&gt;

&lt;p&gt;When the network connection breaks, the café faces a choice.&lt;/p&gt;

&lt;h4&gt;
  
  
  Option 1: CP — Consistency + Partition Tolerance
&lt;/h4&gt;

&lt;p&gt;Branch B says, "I can't verify the stock, so I'll wait before confirming this order."&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The café protects consistency.&lt;/li&gt;
&lt;li&gt;Some customers must wait or receive an error.&lt;/li&gt;
&lt;li&gt;Availability is sacrificed for affected requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Option 2: AP — Availability + Partition Tolerance
&lt;/h4&gt;

&lt;p&gt;Branch B says, "I'll keep accepting orders even though I can't check Branch A's latest stock."&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customers continue getting responses.&lt;/li&gt;
&lt;li&gt;Some information might be outdated or conflicting.&lt;/li&gt;
&lt;li&gt;The branches can reconcile their data when communication returns.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. What About CA?
&lt;/h3&gt;

&lt;p&gt;Consistency and availability can coexist when there is no network partition and the system's design allows it.&lt;/p&gt;

&lt;p&gt;But when a partition occurs, a distributed system cannot guarantee both consistency and availability for every affected request.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Quick Comparison
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Property&lt;/th&gt;
&lt;th&gt;Café example&lt;/th&gt;
&lt;th&gt;Simple meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Consistency&lt;/td&gt;
&lt;td&gt;Both branches know the correct cake stock&lt;/td&gt;
&lt;td&gt;Keep data correct&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Availability&lt;/td&gt;
&lt;td&gt;Branch B continues accepting requests&lt;/td&gt;
&lt;td&gt;Keep responding&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Partition tolerance&lt;/td&gt;
&lt;td&gt;Branches handle a broken connection&lt;/td&gt;
&lt;td&gt;Handle network failures&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  7. Interview Question
&lt;/h3&gt;

&lt;p&gt;The internet connection between two café branches is down. Branch A may have sold the last chocolate cake. What should Branch B do if the café must prevent selling the same cake twice?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A. Accept the order immediately using old stock information.&lt;/li&gt;
&lt;li&gt;B. Wait or reject the order until stock can be verified safely.&lt;/li&gt;
&lt;li&gt;C. Ignore the inventory records.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Answer
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Option B&lt;/strong&gt; is the safest choice if strong consistency is required. Branch B may have to delay or reject the affected request during the network partition.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;C — Consistency:&lt;/strong&gt; Keep the data correct.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A — Availability:&lt;/strong&gt; Keep the service responding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;P — Partition tolerance:&lt;/strong&gt; Handle a broken connection.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;CAP theorem:&lt;/strong&gt; During a network partition, a distributed system cannot guarantee both consistency and availability for every request. It must make a trade-off for affected operations.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Indexing and Replication Through a Restaurant Example</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Thu, 15 Oct 2026 07:22:29 +0000</pubDate>
      <link>https://dev.to/khushindpatel/indexing-and-replication-through-a-restaurant-example-2g5m</link>
      <guid>https://dev.to/khushindpatel/indexing-and-replication-through-a-restaurant-example-2g5m</guid>
      <description>&lt;p&gt;Let's continue our café story, but now imagine the café has become a popular restaurant with thousands of customers, hundreds of menu items, and a large database of orders.&lt;/p&gt;

&lt;p&gt;The restaurant faces two problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Finding a customer's order quickly takes too much time.&lt;/li&gt;
&lt;li&gt;If the main database goes down, the restaurant may stop serving customers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's where &lt;strong&gt;indexing&lt;/strong&gt; and &lt;strong&gt;replication&lt;/strong&gt; help.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. What Is Indexing?
&lt;/h3&gt;

&lt;p&gt;Imagine the restaurant keeps thousands of order records in a large register. When a customer asks for order number 5821, the staff must scan page after page to find it.&lt;/p&gt;

&lt;p&gt;This takes time.&lt;/p&gt;

&lt;p&gt;Now imagine the register has an index at the back that says:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Order 5821 → Page 240&lt;/li&gt;
&lt;li&gt;Order 5822 → Page 241&lt;/li&gt;
&lt;li&gt;Order 5823 → Page 242&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The staff can jump directly to the right page instead of scanning the entire register.&lt;/p&gt;

&lt;p&gt;That is the idea behind &lt;strong&gt;database indexing&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  In system design
&lt;/h4&gt;

&lt;p&gt;A database index is a data structure that helps the database find rows faster without scanning every row in a table.&lt;/p&gt;

&lt;p&gt;For example, a database table might contain millions of orders. An index on &lt;code&gt;order_id&lt;/code&gt; can help the database locate a particular order efficiently.&lt;/p&gt;

&lt;h4&gt;
  
  
  SQL example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;idx_orders_order_id&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;orders&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then a query such as this may use the index:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;order_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5821&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The database's query planner decides whether using the index is the best option.&lt;/p&gt;

&lt;h4&gt;
  
  
  When should you use indexing?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;When a column is frequently used to search for records.&lt;/li&gt;
&lt;li&gt;When columns are often used to join tables.&lt;/li&gt;
&lt;li&gt;When queries frequently filter or sort by certain columns and an appropriate index can help.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  What is the downside of indexing?
&lt;/h4&gt;

&lt;p&gt;Imagine the restaurant adds a detailed index for every possible thing in its register. Finding records may become faster, but updating the register becomes more work because the indexes also need updating.&lt;/p&gt;

&lt;p&gt;Database indexes have similar trade-offs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They consume additional storage.&lt;/li&gt;
&lt;li&gt;Inserts, updates, and deletes can become slower because indexes must be maintained.&lt;/li&gt;
&lt;li&gt;Too many or poorly chosen indexes can hurt performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Remember:&lt;/strong&gt; An index helps you find data faster; it does not automatically make every query faster.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. What Is Replication?
&lt;/h3&gt;

&lt;p&gt;Now imagine the restaurant's entire order register is kept in one room. If that room becomes inaccessible, staff may not be able to retrieve order information.&lt;/p&gt;

&lt;p&gt;To reduce this risk, the restaurant keeps copies of the register in two other rooms.&lt;/p&gt;

&lt;p&gt;If the main register becomes unavailable, a copy may still be available.&lt;/p&gt;

&lt;p&gt;This is the idea behind &lt;strong&gt;database replication&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  In system design
&lt;/h4&gt;

&lt;p&gt;Replication means keeping copies of data on multiple database servers or nodes.&lt;/p&gt;

&lt;p&gt;A common setup has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Primary database:&lt;/strong&gt; Usually accepts writes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replica databases:&lt;/strong&gt; Receive copies of the primary's data and may serve read requests.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  How replication works
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;A customer places an order.&lt;/li&gt;
&lt;li&gt;The application writes the order to the primary database.&lt;/li&gt;
&lt;li&gt;The change is sent to one or more replicas.&lt;/li&gt;
&lt;li&gt;Read requests may be served by the primary or by suitable replicas, depending on the system's design.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Why use replication?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Availability:&lt;/strong&gt; A replica may help keep the application running if the primary fails.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read scalability:&lt;/strong&gt; Read traffic can be distributed across replicas.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Disaster recovery:&lt;/strong&gt; Copies of data can help recover from some failures, depending on how replication and backups are configured.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  What is the downside of replication?
&lt;/h4&gt;

&lt;p&gt;Copies do not always update at exactly the same time.&lt;/p&gt;

&lt;p&gt;Imagine the primary register records an order at 12:01, but a replica has not received the new order yet. A staff member checking that replica might temporarily see old information.&lt;/p&gt;

&lt;p&gt;This is called &lt;strong&gt;replication lag&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Replication also adds operational complexity. Failover, consistency, and replica health must be handled carefully. Replication alone is not a replacement for backups.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Types of Replication
&lt;/h3&gt;

&lt;h4&gt;
  
  
  A. Primary-Replica Replication
&lt;/h4&gt;

&lt;p&gt;The primary database handles writes, and replicas receive copies of the data. Reads may be distributed to replicas when appropriate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Restaurant example:&lt;/strong&gt; The head cashier records new orders in the main register, while other service counters use copies to look up existing orders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best used when:&lt;/strong&gt; The application has many reads and needs to scale read traffic or improve availability.&lt;/p&gt;

&lt;h4&gt;
  
  
  B. Synchronous Replication
&lt;/h4&gt;

&lt;p&gt;The system waits for confirmation from the required replica or replicas before considering a write complete, according to the configured acknowledgement rules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Restaurant example:&lt;/strong&gt; The cashier waits until the required backup register confirms that the new order has been copied before confirming completion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trade-off:&lt;/strong&gt; Stronger guarantees for acknowledged copies can increase write latency and may reduce write availability during network or replica problems.&lt;/p&gt;

&lt;h4&gt;
  
  
  C. Asynchronous Replication
&lt;/h4&gt;

&lt;p&gt;The primary confirms a write without waiting for replicas to finish copying it. Replicas catch up afterward.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Restaurant example:&lt;/strong&gt; The cashier confirms the order immediately, and staff copy it into the other registers moments later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trade-off:&lt;/strong&gt; It can make writes faster, but a replica may temporarily return stale data. If the primary fails before changes are replicated, some recent writes may be lost during failover.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Indexing vs. Replication
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Indexing&lt;/th&gt;
&lt;th&gt;Replication&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Main purpose&lt;/td&gt;
&lt;td&gt;Find data faster&lt;/td&gt;
&lt;td&gt;Keep copies of data on multiple nodes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Restaurant analogy&lt;/td&gt;
&lt;td&gt;An index pointing to the right page&lt;/td&gt;
&lt;td&gt;Copies of the order register&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Helps with&lt;/td&gt;
&lt;td&gt;Query performance&lt;/td&gt;
&lt;td&gt;Read scaling, availability, and recovery options&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Main cost&lt;/td&gt;
&lt;td&gt;Extra storage and slower writes due to index maintenance&lt;/td&gt;
&lt;td&gt;Extra storage, network traffic, and operational complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Does it copy all data to another server?&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes, in a typical full-data replication setup&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  5. Can We Use Both Together?
&lt;/h3&gt;

&lt;p&gt;Yes! Indexing and replication solve different problems, so they can be used together.&lt;/p&gt;

&lt;p&gt;Imagine the restaurant has one primary database and two read replicas. Each database has a useful index on &lt;code&gt;order_id&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replication provides copies of the data and allows some reads to be distributed.&lt;/li&gt;
&lt;li&gt;Indexing helps each database find a particular order efficiently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together, they can improve read performance and help the system handle more traffic. Indexes still need to be maintained on replicas, and replication lag must be considered.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Interview Question
&lt;/h3&gt;

&lt;p&gt;Your restaurant has 10 million orders. Searching for an order by &lt;code&gt;order_id&lt;/code&gt; is slow, and the database is receiving too many read requests.&lt;/p&gt;

&lt;p&gt;What would be a sensible approach?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A. Add an index on &lt;code&gt;order_id&lt;/code&gt; and consider read replicas for read traffic.&lt;/li&gt;
&lt;li&gt;B. Create more indexes on every column without checking query patterns.&lt;/li&gt;
&lt;li&gt;C. Replicate the database but leave the slow query unchanged.&lt;/li&gt;
&lt;li&gt;D. Remove the database indexes and add more servers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Answer
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Option A&lt;/strong&gt; is the sensible starting point.&lt;/p&gt;

&lt;p&gt;An appropriate index can help speed up searches by &lt;code&gt;order_id&lt;/code&gt;. Read replicas can help distribute read traffic when the application can tolerate their consistency characteristics. Check query plans and measure performance before and after making changes.&lt;/p&gt;

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

&lt;p&gt;Think of the restaurant's order register:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Indexing&lt;/strong&gt; is like a register's index that helps you find the right page quickly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replication&lt;/strong&gt; is like keeping copies of the register so multiple service counters can read data and the system has alternatives if one database fails.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Indexing improves how data is found. Replication creates additional copies of data. They address different problems and are often used together in real-world systems.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>webdev</category>
      <category>programming</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Understanding Caching Through a Cafe Example</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Mon, 12 Oct 2026 14:04:10 +0000</pubDate>
      <link>https://dev.to/khushindpatel/understanding-caching-through-a-cafe-example-26o3</link>
      <guid>https://dev.to/khushindpatel/understanding-caching-through-a-cafe-example-26o3</guid>
      <description>&lt;p&gt;Imagine you own a busy café. Every day, customers order popular items like masala chai, cold coffee, and sandwiches.&lt;/p&gt;

&lt;p&gt;If the chef has to collect every ingredient from the storeroom and prepare everything from scratch for every order, service will be slow. But if the café keeps popular ingredients ready near the counter, the chef can work faster.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;That is the basic idea behind caching in system design.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. What Is Caching?
&lt;/h3&gt;

&lt;p&gt;Caching means storing frequently accessed data in a temporary, fast storage location so future requests can be served faster.&lt;/p&gt;

&lt;h4&gt;
  
  
  Café analogy
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Storeroom:&lt;/strong&gt; Database&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ready-to-use ingredients near the counter:&lt;/strong&gt; Cache&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chef:&lt;/strong&gt; Application server&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customer order:&lt;/strong&gt; User request&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. How Does Caching Work?
&lt;/h3&gt;

&lt;p&gt;Suppose a customer asks for cold coffee. The café first checks whether the needed information is already available nearby.&lt;/p&gt;

&lt;h4&gt;
  
  
  Cache hit
&lt;/h4&gt;

&lt;p&gt;The required data is found in the cache, so the application can return it quickly without querying the database.&lt;/p&gt;

&lt;h4&gt;
  
  
  Cache miss
&lt;/h4&gt;

&lt;p&gt;The data is not in the cache. The application fetches it from the database and commonly stores it in the cache for future requests.&lt;/p&gt;

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

&lt;h4&gt;
  
  
  A. In-Memory Cache
&lt;/h4&gt;

&lt;p&gt;Imagine keeping popular ingredients beside the chef so they can be accessed almost immediately.&lt;/p&gt;

&lt;p&gt;In system design, data is stored in RAM, which is typically much faster to access than data stored on disk.&lt;/p&gt;

&lt;p&gt;Examples include Redis and Memcached.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use it when:&lt;/strong&gt; You need fast access to frequently requested data, such as product details, user sessions, or popular posts.&lt;/p&gt;

&lt;h4&gt;
  
  
  B. Browser Cache
&lt;/h4&gt;

&lt;p&gt;Imagine a regular customer has a copy of the café menu saved on their phone, so they do not need to request the same menu every time.&lt;/p&gt;

&lt;p&gt;In system design, the browser stores resources such as images, CSS, and JavaScript files according to caching rules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use it when:&lt;/strong&gt; You want repeat visitors to load websites faster and reduce unnecessary network requests.&lt;/p&gt;

&lt;h4&gt;
  
  
  C. CDN Cache
&lt;/h4&gt;

&lt;p&gt;Imagine your café has branches in several cities. Instead of sending every customer to the main café for the menu, each branch keeps a copy of popular menu items.&lt;/p&gt;

&lt;p&gt;In system design, a Content Delivery Network (CDN) stores cached content at locations closer to users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use it when:&lt;/strong&gt; You need to serve static content such as images, videos, CSS, and JavaScript to users in different geographical locations.&lt;/p&gt;

&lt;h4&gt;
  
  
  D. Database Cache
&lt;/h4&gt;

&lt;p&gt;Imagine the café keeps a prepared list of popular orders so the chef does not need to check the main records for every request.&lt;/p&gt;

&lt;p&gt;In system design, frequently accessed query results or database pages may be cached to avoid repeated expensive reads. Databases can have internal caches, and applications can also cache query results.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use it when:&lt;/strong&gt; The same data is read repeatedly and fetching it from the database is expensive.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. What Is Cache Expiration (TTL)?
&lt;/h3&gt;

&lt;p&gt;Suppose the café prepares fresh chutney in the morning. It should not keep serving the same chutney indefinitely.&lt;/p&gt;

&lt;p&gt;Caching works similarly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TTL (Time To Live)&lt;/strong&gt; defines how long a cached item can remain valid before it expires.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Café menu data: cache for one hour.&lt;/li&gt;
&lt;li&gt;Product prices: use a shorter TTL if prices change frequently.&lt;/li&gt;
&lt;li&gt;Static logo: cache for a long period if its URL changes whenever the logo is updated.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The correct TTL depends on how frequently data changes and how much stale data the application can tolerate.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. The Biggest Challenge: Stale Data
&lt;/h3&gt;

&lt;p&gt;Imagine the café changes the price of cold coffee from ₹100 to ₹120, but the cached menu still shows ₹100.&lt;/p&gt;

&lt;p&gt;This is called &lt;strong&gt;stale cache data&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Common ways to handle it
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;TTL:&lt;/strong&gt; Let cached data expire after a defined duration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache invalidation:&lt;/strong&gt; Remove or update cached data when the original data changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write-through:&lt;/strong&gt; Update the cache and underlying data store as part of the write path.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write-behind:&lt;/strong&gt; Update the cache first and persist the change to the database later, with appropriate reliability safeguards.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. What Is Cache Eviction?
&lt;/h3&gt;

&lt;p&gt;Suppose your café counter has room for only 20 ingredient containers. When it becomes full, you must decide which container to remove to make room for a new one.&lt;/p&gt;

&lt;p&gt;A cache also has limited memory, so it may need to evict existing entries.&lt;/p&gt;

&lt;h4&gt;
  
  
  Common eviction strategies
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Strategy&lt;/th&gt;
&lt;th&gt;Café example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;LRU (Least Recently Used)&lt;/td&gt;
&lt;td&gt;Remove the ingredient that has not been used for the longest time.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LFU (Least Frequently Used)&lt;/td&gt;
&lt;td&gt;Remove the ingredient used the fewest times.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;FIFO (First In, First Out)&lt;/td&gt;
&lt;td&gt;Remove the ingredient that was added first.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  7. When Should You Use Caching?
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Cache benefit&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Popular products&lt;/td&gt;
&lt;td&gt;Faster product page loads&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Frequently viewed profiles&lt;/td&gt;
&lt;td&gt;Fewer database reads&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Static images and files&lt;/td&gt;
&lt;td&gt;Faster delivery through browser or CDN caches&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Repeated expensive calculations&lt;/td&gt;
&lt;td&gt;Avoid recalculating the same result&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data that changes constantly&lt;/td&gt;
&lt;td&gt;Caching may need short TTLs or careful invalidation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Caching is not always the right choice. It adds complexity, consumes memory, and can return outdated data if freshness is not managed correctly.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Interview Question
&lt;/h3&gt;

&lt;p&gt;Your café receives 1,000 requests for its menu every minute. The menu rarely changes, but every request currently queries the database.&lt;/p&gt;

&lt;p&gt;What would you do?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A. Increase database queries&lt;/li&gt;
&lt;li&gt;B. Cache the menu and set an appropriate expiration or invalidation strategy&lt;/li&gt;
&lt;li&gt;C. Delete the database&lt;/li&gt;
&lt;li&gt;D. Restart the server after every request&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Answer
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Option B: Cache the menu and set an appropriate expiration or invalidation strategy.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Caching lets repeated requests be served quickly and reduces database reads. Update or invalidate the cached copy when the menu changes.&lt;/p&gt;

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

&lt;p&gt;Think of caching as &lt;strong&gt;keeping popular café items ready instead of fetching everything from the storeroom for every order&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In system design, caching helps reduce latency, database load, and repeated computation. The important part is deciding what to cache, where to cache it, how long to keep it, and how to keep it fresh.&lt;/p&gt;

</description>
      <category>redis</category>
      <category>systemdesign</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Understanding Load Balancing Through a Cafe Example</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Sat, 10 Oct 2026 15:11:46 +0000</pubDate>
      <link>https://dev.to/khushindpatel/understanding-load-balancing-through-a-cafe-example-1kah</link>
      <guid>https://dev.to/khushindpatel/understanding-load-balancing-through-a-cafe-example-1kah</guid>
      <description>&lt;p&gt;Imagine a busy café with one master chef and four other chefs. Customers keep placing orders. If the master chef prepares every dish alone, customers will wait too long.&lt;/p&gt;

&lt;p&gt;Instead, the master chef distributes orders among the four chefs. In system design, this is what a &lt;strong&gt;load balancer&lt;/strong&gt; does: it receives incoming requests and decides which server should handle each one.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Café Team
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Master chef:&lt;/strong&gt; Load balancer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Four chefs:&lt;/strong&gt; Servers&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customer orders:&lt;/strong&gt; Incoming requests&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Preparing dishes:&lt;/strong&gt; Processing requests&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1. Round Robin
&lt;/h3&gt;

&lt;p&gt;The master chef assigns orders to chefs one by one in a repeating order.&lt;/p&gt;

&lt;h4&gt;
  
  
  Café example
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Order 1 goes to Chef 1.&lt;/li&gt;
&lt;li&gt;Order 2 goes to Chef 2.&lt;/li&gt;
&lt;li&gt;Order 3 goes to Chef 3.&lt;/li&gt;
&lt;li&gt;Order 4 goes to Chef 4.&lt;/li&gt;
&lt;li&gt;Order 5 goes back to Chef 1.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  In system design
&lt;/h4&gt;

&lt;p&gt;Requests are distributed sequentially across servers.&lt;/p&gt;

&lt;h4&gt;
  
  
  Best used when
&lt;/h4&gt;

&lt;p&gt;Servers have similar capacity and requests take roughly the same amount of time.&lt;/p&gt;

&lt;h4&gt;
  
  
  Limitation
&lt;/h4&gt;

&lt;p&gt;Round Robin does not check whether a chef is already busy. A chef working on a complicated dish may receive another order even when another chef is free.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Weighted Round Robin
&lt;/h3&gt;

&lt;p&gt;Now imagine Chef 1 is more experienced and can prepare twice as many dishes as the other chefs. The master chef gives Chef 1 more orders.&lt;/p&gt;

&lt;h4&gt;
  
  
  Café example
&lt;/h4&gt;

&lt;p&gt;A possible distribution is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chef 1 receives 2 orders.&lt;/li&gt;
&lt;li&gt;Chef 2 receives 1 order.&lt;/li&gt;
&lt;li&gt;Chef 3 receives 1 order.&lt;/li&gt;
&lt;li&gt;Chef 4 receives 1 order.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The exact distribution depends on the configured weights.&lt;/p&gt;

&lt;h4&gt;
  
  
  In system design
&lt;/h4&gt;

&lt;p&gt;Servers receive requests according to assigned weights. A server with a higher weight generally receives a larger share of requests.&lt;/p&gt;

&lt;h4&gt;
  
  
  Best used when
&lt;/h4&gt;

&lt;p&gt;Servers have different processing capacities.&lt;/p&gt;

&lt;h4&gt;
  
  
  Limitation
&lt;/h4&gt;

&lt;p&gt;Weights do not necessarily reflect how busy a server is at that moment.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Least Connections
&lt;/h3&gt;

&lt;p&gt;Imagine Chef 1 is preparing three dishes, Chef 2 is preparing one, and Chefs 3 and 4 are free. The master chef sends the next order to a chef with the fewest active orders.&lt;/p&gt;

&lt;h4&gt;
  
  
  Café example
&lt;/h4&gt;

&lt;p&gt;The next order could go to Chef 3 or Chef 4 because both have no active orders.&lt;/p&gt;

&lt;h4&gt;
  
  
  In system design
&lt;/h4&gt;

&lt;p&gt;The load balancer selects a server with the fewest active connections.&lt;/p&gt;

&lt;h4&gt;
  
  
  Best used when
&lt;/h4&gt;

&lt;p&gt;Connections or requests can remain active for different lengths of time.&lt;/p&gt;

&lt;h4&gt;
  
  
  Limitation
&lt;/h4&gt;

&lt;p&gt;The number of active connections does not always represent the real workload. One request may require much more processing than another.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Weighted Least Connections
&lt;/h3&gt;

&lt;p&gt;Now combine the previous two ideas. Chef 1 is twice as capable as the other chefs, but the master chef also checks how many active orders each chef has.&lt;/p&gt;

&lt;p&gt;The master chef considers both capacity and current connections when choosing a chef.&lt;/p&gt;

&lt;h4&gt;
  
  
  In system design
&lt;/h4&gt;

&lt;p&gt;The algorithm uses server weights along with active connection counts to help distribute requests.&lt;/p&gt;

&lt;h4&gt;
  
  
  Best used when
&lt;/h4&gt;

&lt;p&gt;Servers have different capacities and workloads vary.&lt;/p&gt;

&lt;h4&gt;
  
  
  Limitation
&lt;/h4&gt;

&lt;p&gt;It still relies on connection counts and weights, which may not perfectly represent actual processing effort.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Least Response Time
&lt;/h3&gt;

&lt;p&gt;Imagine Chef 1 has only one order but is taking a long time to finish it. Chef 2 has two orders but usually finishes dishes quickly. The master chef considers how quickly each chef is responding and sends the next order to a suitable, faster option.&lt;/p&gt;

&lt;h4&gt;
  
  
  In system design
&lt;/h4&gt;

&lt;p&gt;Requests are routed based on response time, often combined with active connections. The exact calculation depends on the load balancer.&lt;/p&gt;

&lt;h4&gt;
  
  
  Best used when
&lt;/h4&gt;

&lt;p&gt;Fast responses and low latency are important.&lt;/p&gt;

&lt;h4&gt;
  
  
  Limitation
&lt;/h4&gt;

&lt;p&gt;Response times can fluctuate, so a single slow or fast response may not represent long-term performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. IP Hash
&lt;/h3&gt;

&lt;p&gt;Imagine the master chef uses each customer's membership number to consistently assign them to a particular chef. Customer A may usually be assigned to Chef 1, while Customer B may usually be assigned to Chef 3.&lt;/p&gt;

&lt;h4&gt;
  
  
  In system design
&lt;/h4&gt;

&lt;p&gt;The load balancer hashes the client's IP address to determine which server should receive the request.&lt;/p&gt;

&lt;h4&gt;
  
  
  Best used when
&lt;/h4&gt;

&lt;p&gt;Consistent client-to-server routing is useful, such as in some session-persistence setups.&lt;/p&gt;

&lt;h4&gt;
  
  
  Limitation
&lt;/h4&gt;

&lt;p&gt;Traffic can become uneven, and adding or removing servers can change which server a client reaches. IP-based routing may also be less reliable when many users share an IP address.&lt;/p&gt;

&lt;h3&gt;
  
  
  Quick Comparison
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Algorithm&lt;/th&gt;
&lt;th&gt;Café rule&lt;/th&gt;
&lt;th&gt;Best use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Round Robin&lt;/td&gt;
&lt;td&gt;Take turns&lt;/td&gt;
&lt;td&gt;Similar servers and requests&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Weighted Round Robin&lt;/td&gt;
&lt;td&gt;Stronger chef gets more orders&lt;/td&gt;
&lt;td&gt;Different server capacities&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Least Connections&lt;/td&gt;
&lt;td&gt;Choose a chef with fewer active connections&lt;/td&gt;
&lt;td&gt;Variable-duration connections&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Weighted Least Connections&lt;/td&gt;
&lt;td&gt;Consider capacity and active connections&lt;/td&gt;
&lt;td&gt;Different capacities and workloads&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Least Response Time&lt;/td&gt;
&lt;td&gt;Prefer faster-responding chefs&lt;/td&gt;
&lt;td&gt;Latency-sensitive applications&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;IP Hash&lt;/td&gt;
&lt;td&gt;Assign clients consistently&lt;/td&gt;
&lt;td&gt;Session persistence in suitable setups&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Interview Question
&lt;/h3&gt;

&lt;p&gt;Your café has four chefs. Chef 1 is powerful but currently busy. Chef 2 is less powerful but completely free. Which load-balancing algorithm could be a good fit?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A. Round Robin&lt;/li&gt;
&lt;li&gt;B. Weighted Round Robin&lt;/li&gt;
&lt;li&gt;C. Least Connections&lt;/li&gt;
&lt;li&gt;D. IP Hash&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Answer
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Weighted Least Connections&lt;/strong&gt; is usually the best fit when both server capacity and current connections matter. Least Connections alone may choose Chef 2 because they have fewer active connections, but it does not account for the difference in capacity.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;master chef&lt;/strong&gt; is the load balancer.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;four chefs&lt;/strong&gt; are servers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customer orders&lt;/strong&gt; are incoming requests.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;load-balancing algorithm&lt;/strong&gt; decides which server receives each request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is no single best algorithm for every application. Choose based on server capacity, request duration, response time, and whether consistent client routing is needed.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>systemdesign</category>
      <category>webdev</category>
    </item>
    <item>
      <title>System Design for Beginners: Vertical Scaling vs Horizontal Scaling</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Thu, 08 Oct 2026 14:22:59 +0000</pubDate>
      <link>https://dev.to/khushindpatel/system-design-for-beginners-vertical-scaling-vs-horizontal-scaling-1inb</link>
      <guid>https://dev.to/khushindpatel/system-design-for-beginners-vertical-scaling-vs-horizontal-scaling-1inb</guid>
      <description>&lt;p&gt;If you are preparing for software engineering interviews, you have probably heard the term &lt;strong&gt;System Design&lt;/strong&gt; many times.&lt;/p&gt;

&lt;p&gt;But what does it actually mean?&lt;/p&gt;

&lt;p&gt;System design is not just about drawing boxes and arrows. It is about deciding how different parts of a software system should work together as the number of users, requests and data grows.&lt;/p&gt;

&lt;p&gt;For example, building a simple Instagram clone for 100 users is easy. But what happens when millions of users are uploading photos, liking posts and refreshing their feeds at the same time?&lt;/p&gt;

&lt;p&gt;That is where system design becomes important.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;System design is the process of designing the architecture of a system so it can handle users, traffic, data, failures and future growth.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;One of the first concepts you should understand is &lt;strong&gt;scaling&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  What Is Scaling?
&lt;/h3&gt;

&lt;p&gt;Suppose your application is running on one server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Users
  |
  v
Server
  |
  v
Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything works fine when you have a small number of users.&lt;/p&gt;

&lt;p&gt;But as users increase, your server may start running out of CPU, memory or other resources.&lt;/p&gt;

&lt;p&gt;So you need to scale the system.&lt;/p&gt;

&lt;p&gt;There are two common ways to do this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vertical Scaling&lt;/li&gt;
&lt;li&gt;Horizontal Scaling&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  What Is Vertical Scaling?
&lt;/h3&gt;

&lt;p&gt;Vertical scaling means &lt;strong&gt;making your existing server more powerful&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example, your application currently runs on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CPU: 4 cores
RAM: 8 GB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You upgrade it to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CPU: 16 cores
RAM: 64 GB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You did not add another server. You simply made the existing server stronger.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Vertical scaling = Scale up by increasing the resources of one machine.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A simple real life example is upgrading your laptop by adding more RAM or getting a faster processor.&lt;/p&gt;

&lt;h4&gt;
  
  
  When should you use vertical scaling?
&lt;/h4&gt;

&lt;p&gt;It can be a good choice when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your application is small&lt;/li&gt;
&lt;li&gt;Traffic is predictable&lt;/li&gt;
&lt;li&gt;You need a quick and simple solution&lt;/li&gt;
&lt;li&gt;Your workload is difficult to distribute&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, if an internal company dashboard is used by only 50 people, adding 10 servers would probably be unnecessary.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Problem With Vertical Scaling
&lt;/h3&gt;

&lt;p&gt;The biggest problem is that there is a limit to how powerful one machine can become.&lt;/p&gt;

&lt;p&gt;There is also a &lt;strong&gt;single point of failure&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;Users
  |
  v
One Server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If that server goes down, your entire application can go down.&lt;/p&gt;

&lt;p&gt;This is one reason we often consider horizontal scaling.&lt;/p&gt;




&lt;h3&gt;
  
  
  What Is Horizontal Scaling?
&lt;/h3&gt;

&lt;p&gt;Horizontal scaling means &lt;strong&gt;adding more servers instead of making one server bigger&lt;/strong&gt;.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 Server 1
                /
Users → Load Balancer → Server 2
                \
                 Server 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the traffic is distributed across multiple servers.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Horizontal scaling = Scale out by adding more machines.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Think about a restaurant.&lt;/p&gt;

&lt;p&gt;If one cashier is not enough during lunch time, you don't necessarily make that cashier work five times faster. You open more counters.&lt;/p&gt;

&lt;p&gt;That is basically horizontal scaling.&lt;/p&gt;




&lt;h3&gt;
  
  
  What Does a Load Balancer Do?
&lt;/h3&gt;

&lt;p&gt;When you have multiple servers, something needs to decide which server should handle each request.&lt;/p&gt;

&lt;p&gt;That's the job of a &lt;strong&gt;load balancer&lt;/strong&gt;.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User 1 → Server 1
User 2 → Server 2
User 3 → Server 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some common load balancing strategies include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Round Robin&lt;/li&gt;
&lt;li&gt;Least Connections&lt;/li&gt;
&lt;li&gt;IP Hash&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal is to distribute traffic so that one server does not become overloaded.&lt;/p&gt;




&lt;h3&gt;
  
  
  Vertical Scaling vs Horizontal Scaling
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Vertical Scaling&lt;/th&gt;
&lt;th&gt;Horizontal Scaling&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Makes one server more powerful&lt;/td&gt;
&lt;td&gt;Adds more servers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Also called scaling up&lt;/td&gt;
&lt;td&gt;Also called scaling out&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Simpler to implement&lt;/td&gt;
&lt;td&gt;More complex&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Has hardware limitations&lt;/td&gt;
&lt;td&gt;Can scale much further&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Can have a single point of failure&lt;/td&gt;
&lt;td&gt;Better availability&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Good for smaller workloads&lt;/td&gt;
&lt;td&gt;Good for large and growing workloads&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The easiest way to remember it:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Vertical = Make the machine bigger&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Horizontal = Add more machines&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Which One Should You Use?
&lt;/h3&gt;

&lt;p&gt;The answer is not always "horizontal scaling".&lt;/p&gt;

&lt;p&gt;It depends on the problem.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example 1: Small Application
&lt;/h4&gt;

&lt;p&gt;Imagine you have an internal dashboard with 100 users.&lt;/p&gt;

&lt;p&gt;Your server is using only 30% CPU.&lt;/p&gt;

&lt;p&gt;Do you need five servers?&lt;/p&gt;

&lt;p&gt;Probably not.&lt;/p&gt;

&lt;p&gt;Vertical scaling may be simpler and cheaper.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example 2: Large E-commerce Platform
&lt;/h4&gt;

&lt;p&gt;Now imagine an e-commerce website normally receives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;100,000 requests/minute
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;During a big sale, traffic suddenly increases to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2,000,000 requests/minute
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One server may not be enough.&lt;/p&gt;

&lt;p&gt;Horizontal scaling makes more sense:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 Server 1
                /
Users → Load Balancer → Server 2
                \
                 Server 3
                    |
                  Server N
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can add more servers as traffic increases.&lt;/p&gt;




&lt;h3&gt;
  
  
  One Important Problem With Horizontal Scaling
&lt;/h3&gt;

&lt;p&gt;Horizontal scaling sounds great, but it introduces new challenges.&lt;/p&gt;

&lt;p&gt;Suppose a user's session is stored only on Server 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User → Server 1

Session stored on Server 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next request goes to Server 2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User → Server 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Server 2 does not have the session information.&lt;/p&gt;

&lt;p&gt;This is why horizontally scaled applications often use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stateless servers&lt;/li&gt;
&lt;li&gt;Shared session storage&lt;/li&gt;
&lt;li&gt;Distributed caches such as Redis&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;              Server 1
             /
Users → Load Balancer
             \
              Server 2
                   |
                   v
                 Redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now multiple servers can access shared information.&lt;/p&gt;




&lt;h3&gt;
  
  
  A Common Interview Question
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Interviewer:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Your application is running on one server and CPU usage is constantly around 95%. What would you do?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A beginner might immediately say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Add another server."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But a better answer is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"First, I would identify the bottleneck. If the application is CPU bound and a larger machine can handle the workload, vertical scaling could be a quick solution. If traffic is growing and we need better availability and long term scalability, I would consider horizontal scaling."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This shows that you are thinking about &lt;strong&gt;requirements and tradeoffs&lt;/strong&gt;, rather than blindly choosing a solution.&lt;/p&gt;




&lt;h3&gt;
  
  
  Another Tricky Interview Question
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Interviewer:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;You have 10 servers, but one server is receiving most of the traffic. You are already using a load balancer. Why could this happen?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Possible reasons include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The load balancing strategy is not distributing requests evenly&lt;/li&gt;
&lt;li&gt;Sticky sessions are being used&lt;/li&gt;
&lt;li&gt;Some requests are much heavier than others&lt;/li&gt;
&lt;li&gt;Traffic itself is uneven&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The important lesson is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Having multiple servers does not automatically mean your traffic is properly distributed.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  The System Design Mindset
&lt;/h3&gt;

&lt;p&gt;When learning system design, don't memorize:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Horizontal scaling is always better."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead, ask:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is the bottleneck?&lt;/li&gt;
&lt;li&gt;How much traffic do we have?&lt;/li&gt;
&lt;li&gt;How fast is traffic growing?&lt;/li&gt;
&lt;li&gt;Do we need high availability?&lt;/li&gt;
&lt;li&gt;Can the workload be distributed?&lt;/li&gt;
&lt;li&gt;What will the solution cost?&lt;/li&gt;
&lt;li&gt;What happens if a server fails?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;System design is about understanding &lt;strong&gt;tradeoffs&lt;/strong&gt; and choosing the right solution for the problem.&lt;/p&gt;




&lt;h3&gt;
  
  
  Quick Recap
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;System Design:&lt;/strong&gt; Designing the architecture of a system so it can handle users, traffic, data, failures and growth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vertical Scaling:&lt;/strong&gt; Make one machine more powerful.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Small Server → Bigger Server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Horizontal Scaling:&lt;/strong&gt; Add more machines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 Server → 5 Servers → 50 Servers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use &lt;strong&gt;vertical scaling&lt;/strong&gt; when simplicity and a smaller workload are more important.&lt;/p&gt;

&lt;p&gt;Use &lt;strong&gt;horizontal scaling&lt;/strong&gt; when traffic is large, growing or requires better availability.&lt;/p&gt;

&lt;p&gt;And remember:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Vertical scaling makes one machine stronger. Horizontal scaling makes the system wider.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The goal of system design is not to use the most complicated architecture.&lt;/p&gt;

&lt;p&gt;It is to choose the &lt;strong&gt;right architecture for the problem you are solving&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>system</category>
      <category>systemdesign</category>
      <category>development</category>
    </item>
    <item>
      <title>learning Generative AI/LLM through practical projects</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Tue, 01 Sep 2026 13:23:23 +0000</pubDate>
      <link>https://dev.to/khushindpatel/learning-roadmap-through-practical-projects-3pe4</link>
      <guid>https://dev.to/khushindpatel/learning-roadmap-through-practical-projects-3pe4</guid>
      <description>&lt;p&gt;If you want to become good at &lt;strong&gt;Generative AI/LLM engineering&lt;/strong&gt;, watching tutorials is not enough.&lt;/p&gt;

&lt;p&gt;The fastest way to understand these technologies is to build projects where you are forced to solve real problems: prompting, context management, retrieval, model adaptation, and evaluation.&lt;/p&gt;

&lt;p&gt;Here is a practical project roadmap:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LLM → RAG → Fine-Tuning → Evals&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Learn LLMs by Building a Lead Triaging Bot
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🎯 Project: Lead Triaging Bot
&lt;/h3&gt;

&lt;p&gt;Build an AI system that receives a new customer lead and decides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is this a high-quality lead?&lt;/li&gt;
&lt;li&gt;What is the customer's intent?&lt;/li&gt;
&lt;li&gt;Which product/service are they interested in?&lt;/li&gt;
&lt;li&gt;How urgent is the lead?&lt;/li&gt;
&lt;li&gt;What should the sales team do next?&lt;/li&gt;
&lt;/ul&gt;

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

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

&lt;blockquote&gt;
&lt;p&gt;"Hi, I'm looking for an enterprise plan for 200 employees. We need SSO and would like to schedule a demo next week."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Output:&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;Lead Quality: High
Intent: Enterprise Purchase
Company Size: 200 employees
Urgency: High
Recommended Action: Schedule Demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What you'll learn
&lt;/h3&gt;

&lt;p&gt;This project gives you a strong foundation in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LLM APIs&lt;/li&gt;
&lt;li&gt;Prompt engineering&lt;/li&gt;
&lt;li&gt;System prompts&lt;/li&gt;
&lt;li&gt;Structured outputs&lt;/li&gt;
&lt;li&gt;Few-shot prompting&lt;/li&gt;
&lt;li&gt;JSON responses&lt;/li&gt;
&lt;li&gt;Function/tool calling&lt;/li&gt;
&lt;li&gt;Temperature and model parameters&lt;/li&gt;
&lt;li&gt;Error handling&lt;/li&gt;
&lt;li&gt;LLM application architecture&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why this project?
&lt;/h3&gt;

&lt;p&gt;Before jumping into RAG or fine-tuning, you should understand how an LLM behaves &lt;strong&gt;without external knowledge or model customization&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This gives you the baseline against which you can later compare RAG and fine-tuning.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Learn RAG by Building a Company Knowledge Assistant
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🎯 Project: Company Knowledge Assistant
&lt;/h3&gt;

&lt;p&gt;Now take the same LLM and give it access to your own knowledge base.&lt;/p&gt;

&lt;p&gt;Upload documents such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Company Policies
Product Documentation
HR Policies
FAQs
Technical Documentation
Pricing Documents
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Users should be able to ask questions about these documents.&lt;/p&gt;

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

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

&lt;blockquote&gt;
&lt;p&gt;"What is our work-from-home policy?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;RAG pipeline:&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;User Question
      ↓
Query Embedding
      ↓
Vector Database
      ↓
Retrieve Relevant Documents
      ↓
Context + Question
      ↓
LLM
      ↓
Grounded Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;RAG works by retrieving relevant information from an external data source and providing that information to the LLM as context. (&lt;a href="https://github.com/langchain-ai/rag-from-scratch?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  What you'll learn
&lt;/h3&gt;

&lt;p&gt;Build the project in stages:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Level 1 — Basic RAG&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Document loading&lt;/li&gt;
&lt;li&gt;Chunking&lt;/li&gt;
&lt;li&gt;Embeddings&lt;/li&gt;
&lt;li&gt;Vector database&lt;/li&gt;
&lt;li&gt;Similarity search&lt;/li&gt;
&lt;li&gt;Context injection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Level 2 — Better RAG&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Metadata filtering&lt;/li&gt;
&lt;li&gt;Hybrid search&lt;/li&gt;
&lt;li&gt;Query rewriting&lt;/li&gt;
&lt;li&gt;Reranking&lt;/li&gt;
&lt;li&gt;Top-K retrieval&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Level 3 — Production RAG&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Conversation history&lt;/li&gt;
&lt;li&gt;Citations&lt;/li&gt;
&lt;li&gt;Access control&lt;/li&gt;
&lt;li&gt;Streaming&lt;/li&gt;
&lt;li&gt;Caching&lt;/li&gt;
&lt;li&gt;Observability&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Public GitHub project
&lt;/h3&gt;

&lt;p&gt;A great reference is &lt;a href="https://github.com/langchain-ai/rag-from-scratch?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;LangChain — RAG From Scratch&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It builds RAG progressively from indexing, retrieval and generation, making it particularly useful for understanding &lt;strong&gt;how RAG actually works rather than simply copying a framework implementation&lt;/strong&gt;. (&lt;a href="https://github.com/langchain-ai/rag-from-scratch?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;You can also explore &lt;a href="https://github.com/danielbank/rag-llamaindex?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;LlamaIndex RAG example&lt;/a&gt; for a more application-oriented implementation. (&lt;a href="https://github.com/danielbank/rag-llamaindex?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;)&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Learn Fine-Tuning by Building a Medical Advisor
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🎯 Project: Medical Advisor
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; This should be treated as an educational AI project, not a real medical diagnostic system.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The goal is to take an open-source LLM and adapt it to produce responses in a particular domain and format.&lt;/p&gt;

&lt;p&gt;For example, create a dataset containing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Question
     ↓
Medical Context
     ↓
Expected Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then fine-tune an open model on your dataset.&lt;/p&gt;

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

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

&lt;blockquote&gt;
&lt;p&gt;"What are common symptoms associated with iron deficiency?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The model should learn to produce a response following your desired structure and style.&lt;/p&gt;

&lt;h3&gt;
  
  
  What you'll learn
&lt;/h3&gt;

&lt;p&gt;This project teaches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dataset preparation&lt;/li&gt;
&lt;li&gt;Instruction datasets&lt;/li&gt;
&lt;li&gt;Data cleaning&lt;/li&gt;
&lt;li&gt;Tokenization&lt;/li&gt;
&lt;li&gt;Training/validation splits&lt;/li&gt;
&lt;li&gt;Supervised Fine-Tuning (SFT)&lt;/li&gt;
&lt;li&gt;LoRA&lt;/li&gt;
&lt;li&gt;QLoRA&lt;/li&gt;
&lt;li&gt;Model checkpoints&lt;/li&gt;
&lt;li&gt;Training metrics&lt;/li&gt;
&lt;li&gt;Model comparison&lt;/li&gt;
&lt;li&gt;Inference with adapters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of trying to fine-tune a huge model from scratch, start with &lt;strong&gt;LoRA/QLoRA&lt;/strong&gt;. These techniques make experimentation much more practical.&lt;/p&gt;

&lt;h3&gt;
  
  
  Public GitHub projects
&lt;/h3&gt;

&lt;p&gt;For a simple introduction:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Apoorva-Udupa/Fine-Tuning_LLMs_with_LoRA_and_QLoRA?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Fine-Tuning LLMs with LoRA and QLoRA&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This repository demonstrates LoRA and QLoRA fine-tuning using PyTorch and Hugging Face Transformers. (&lt;a href="https://github.com/Apoorva-Udupa/Fine-Tuning_LLMs_with_LoRA_and_QLoRA?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;For a more complete implementation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/gazelle93/llm-fine-tuning-sft-lora-qlora?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;LLM Fine-Tuning — SFT, LoRA &amp;amp; QLoRA&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It includes dataset loading, tokenization, SFT, LoRA and QLoRA examples. (&lt;a href="https://github.com/gazelle93/llm-fine-tuning-sft-lora-qlora?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  The important lesson
&lt;/h3&gt;

&lt;p&gt;Don't think:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Fine-tuning = giving the model more knowledge&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead, think:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Fine-tuning = adapting model behavior, style, format or task performance.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For frequently changing factual knowledge, RAG is often a better solution.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Learn Evals by Building an LLM Evaluation System
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🎯 Project: Evaluate Your AI Applications
&lt;/h3&gt;

&lt;p&gt;This is the project most beginners skip.&lt;/p&gt;

&lt;p&gt;And it is one of the most important.&lt;/p&gt;

&lt;p&gt;Suppose your RAG system answers:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What is the company's leave policy?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;How do you know whether the answer is actually good?&lt;/p&gt;

&lt;p&gt;You need an evaluation system.&lt;/p&gt;




&lt;h2&gt;
  
  
  Build a Lead/RAG Evaluation Bot
&lt;/h2&gt;

&lt;p&gt;Create a test dataset:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Question
Expected Answer
Retrieved Context
Generated Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then evaluate the system automatically.&lt;/p&gt;

&lt;h3&gt;
  
  
  Evaluate:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Retrieval&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Did we retrieve the correct document?&lt;/li&gt;
&lt;li&gt;Was the relevant information present?&lt;/li&gt;
&lt;li&gt;Was irrelevant information retrieved?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Generation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is the answer correct?&lt;/li&gt;
&lt;li&gt;Is it relevant?&lt;/li&gt;
&lt;li&gt;Is it grounded in the retrieved context?&lt;/li&gt;
&lt;li&gt;Did the model hallucinate?&lt;/li&gt;
&lt;/ul&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Question:
What is our annual leave policy?

Expected:
Employees receive 24 days of annual leave.

Model Answer:
Employees receive 24 days of annual leave.

Evaluation:
Correctness: 1.0
Faithfulness: 1.0
Relevance: 1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now intentionally introduce a bad answer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Model Answer:
Employees receive 30 days of annual leave.

Evaluation:
Correctness: 0.0
Faithfulness: 0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You have now started building an &lt;strong&gt;LLM evaluation pipeline&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Public GitHub projects
&lt;/h3&gt;

&lt;p&gt;A good reference is &lt;a href="https://github.com/Aftabbs/RAG-Evaluation-Framework?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;RAG Evaluation Framework&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It separates evaluation into retrieval quality and generation quality and uses LLM-based evaluation with LangChain. (&lt;a href="https://github.com/Aftabbs/RAG-Evaluation-Framework?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Another useful project is &lt;a href="https://github.com/vibrantlabsai/ragas?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Ragas&lt;/a&gt;, which provides metrics and test-data generation for evaluating LLM applications and RAG systems. (&lt;a href="https://github.com/vibrantlabsai/ragas?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;You can also study &lt;a href="https://github.com/sujitpal/llm-rag-eval?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;LLM RAG Eval&lt;/a&gt;, which focuses specifically on evaluating RAG pipelines. (&lt;a href="https://github.com/sujitpal/llm-rag-eval?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;)&lt;/p&gt;




&lt;h2&gt;
  
  
  The Complete Learning Roadmap
&lt;/h2&gt;

&lt;p&gt;Instead of building four unrelated projects, build them as a progression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    GENERATIVE AI
                         │
                         ▼
              ┌─────────────────────┐
              │ 1. Lead Triaging Bot│
              │       LLM           │
              └──────────┬──────────┘
                         │
                         ▼
              ┌─────────────────────┐
              │ 2. Knowledge        │
              │    Assistant        │
              │       RAG           │
              └──────────┬──────────┘
                         │
                         ▼
              ┌─────────────────────┐
              │ 3. Medical Advisor  │
              │    Fine-Tuning      │
              └──────────┬──────────┘
                         │
                         ▼
              ┌─────────────────────┐
              │ 4. Evaluation       │
              │    Framework        │
              │       Evals         │
              └─────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What You Should Know After Building All 4
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Project&lt;/th&gt;
&lt;th&gt;Technology&lt;/th&gt;
&lt;th&gt;You Learn&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Lead Triaging Bot&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;LLM&lt;/td&gt;
&lt;td&gt;Prompting, structured output, tools&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Knowledge Assistant&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;RAG&lt;/td&gt;
&lt;td&gt;Embeddings, retrieval, vector DB, RAG&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Medical Advisor&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Fine-Tuning&lt;/td&gt;
&lt;td&gt;SFT, LoRA, QLoRA, datasets&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Evaluation Framework&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Evals&lt;/td&gt;
&lt;td&gt;Metrics, test datasets, hallucination detection&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;But the real value comes when you &lt;strong&gt;connect them&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Your final architecture can look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                         User
                           │
                           ▼
                    Lead / Query
                           │
                           ▼
                   ┌──────────────┐
                   │     LLM      │
                   └──────┬───────┘
                          │
                ┌─────────┴─────────┐
                ▼                   ▼
              RAG              Fine-Tuned
           Knowledge             Model
              │                   │
              └─────────┬─────────┘
                        ▼
                   Final Answer
                        │
                        ▼
                    EVALUATION
                        │
              ┌─────────┼─────────┐
              ▼         ▼         ▼
          Correct?  Relevant?  Grounded?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The key takeaway
&lt;/h2&gt;

&lt;p&gt;Don't learn these technologies as isolated topics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Build progressively.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start with an LLM application → add your own knowledge with RAG → adapt the model with fine-tuning → finally build an evaluation layer to measure whether your system actually improved.&lt;/p&gt;

&lt;p&gt;That progression takes you from &lt;strong&gt;"I know how to call an LLM API"&lt;/strong&gt; to &lt;strong&gt;"I can design, improve and evaluate production-style LLM systems."&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>learning</category>
      <category>llm</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How Does Aadhaar Verify Billions of People's Fingerprints in Seconds?</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Thu, 09 Jul 2026 17:44:45 +0000</pubDate>
      <link>https://dev.to/khushindpatel/how-does-aadhaar-verify-billions-of-peoples-fingerprints-in-seconds-2lao</link>
      <guid>https://dev.to/khushindpatel/how-does-aadhaar-verify-billions-of-peoples-fingerprints-in-seconds-2lao</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;India's Aadhaar system stores biometric information for over a billion residents. Every day, millions of fingerprint authentication requests are made for banking, government services, SIM verification, and more.&lt;/p&gt;

&lt;p&gt;A common question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How can Aadhaar verify a fingerprint among more than a billion records in just a few seconds?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The answer is that Aadhaar doesn't compare your fingerprint against every fingerprint in the database. Instead, it uses smart indexing, biometric templates, and a highly optimized distributed architecture.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Myth
&lt;/h2&gt;

&lt;p&gt;Many people imagine Aadhaar works like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Fingerprint
      |
      v
Compare with Person 1
Compare with Person 2
Compare with Person 3
...
Compare with 1.4 Billion People
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If this were true, authentication would take hours.&lt;/p&gt;

&lt;p&gt;Fortunately, that's &lt;strong&gt;not&lt;/strong&gt; how the system works.&lt;/p&gt;




&lt;h2&gt;
  
  
  Fingerprints Are Stored as Templates
&lt;/h2&gt;

&lt;p&gt;When you enroll for Aadhaar, the system doesn't store your fingerprint as a normal image.&lt;/p&gt;

&lt;p&gt;Instead, it extracts unique features such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ridge endings&lt;/li&gt;
&lt;li&gt;Ridge bifurcations&lt;/li&gt;
&lt;li&gt;Minutiae points&lt;/li&gt;
&lt;li&gt;Relative positions and angles&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These features are converted into a compact &lt;strong&gt;biometric template&lt;/strong&gt;, making comparisons much faster than comparing full images.&lt;/p&gt;




&lt;h2&gt;
  
  
  Authentication Is Usually 1:1 Matching
&lt;/h2&gt;

&lt;p&gt;Most Aadhaar authentications already include your &lt;strong&gt;Aadhaar number&lt;/strong&gt; or &lt;strong&gt;Virtual ID&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The process looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Aadhaar Number + Fingerprint
          |
          v
Find User Record
          |
          v
Compare Submitted Fingerprint
          |
          v
Authentication Success or Failure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since the system already knows which record to check, it performs &lt;strong&gt;one fingerprint comparison&lt;/strong&gt;, not billions.&lt;/p&gt;




&lt;h2&gt;
  
  
  What About Identification Without an Aadhaar Number?
&lt;/h2&gt;

&lt;p&gt;In some scenarios, the system may need to identify a person without knowing who they are.&lt;/p&gt;

&lt;p&gt;This is called &lt;strong&gt;1:N matching&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of checking every record one by one, the system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses biometric indexes&lt;/li&gt;
&lt;li&gt;Narrows the search to likely matches&lt;/li&gt;
&lt;li&gt;Searches across multiple servers in parallel&lt;/li&gt;
&lt;li&gt;Compares only a small candidate set&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This dramatically reduces the search time.&lt;/p&gt;




&lt;h2&gt;
  
  
  Distributed System Architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;              Authentication Request
                        |
                        v
                Load Balancer
                        |
        +---------------+---------------+
        |               |               |
        v               v               v
   Biometric       Biometric      Biometric
   Server 1        Server 2       Server 3
        |               |               |
        +---------------+---------------+
                        |
                        v
               Authentication Result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The workload is distributed across many servers, allowing millions of authentication requests to be processed concurrently.&lt;/p&gt;




&lt;h2&gt;
  
  
  Optimizations That Make It Fast
&lt;/h2&gt;

&lt;p&gt;Modern biometric systems use several techniques:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Biometric templates instead of images&lt;/li&gt;
&lt;li&gt;Fast indexing algorithms&lt;/li&gt;
&lt;li&gt;Parallel processing&lt;/li&gt;
&lt;li&gt;In-memory caching&lt;/li&gt;
&lt;li&gt;Distributed databases&lt;/li&gt;
&lt;li&gt;Optimized biometric matching engines&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together, these reduce authentication time from minutes to just a few seconds.&lt;/p&gt;




&lt;h2&gt;
  
  
  Interview Perspective
&lt;/h2&gt;

&lt;p&gt;A common misconception is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The system compares your fingerprint against every person in India."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A strong system design answer is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Most Aadhaar authentications are &lt;strong&gt;1:1 verification&lt;/strong&gt;, not &lt;strong&gt;1:N identification&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Fingerprints are stored as biometric templates.&lt;/li&gt;
&lt;li&gt;Distributed servers process requests in parallel.&lt;/li&gt;
&lt;li&gt;Indexing reduces the search space.&lt;/li&gt;
&lt;li&gt;Only a tiny number of comparisons are actually performed.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Aadhaar does &lt;strong&gt;not&lt;/strong&gt; compare your fingerprint with billions of records for every authentication.&lt;/li&gt;
&lt;li&gt;Fingerprints are converted into compact biometric templates.&lt;/li&gt;
&lt;li&gt;Most authentications are &lt;strong&gt;1:1 verification&lt;/strong&gt; using your Aadhaar number or Virtual ID.&lt;/li&gt;
&lt;li&gt;Large-scale infrastructure, indexing, and distributed processing allow millions of requests to be handled efficiently.&lt;/li&gt;
&lt;li&gt;The speed comes from smart system design—not brute-force searching.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>Why Does LinkedIn Show "500+ Connections" Instead of the Exact Number?</title>
      <dc:creator>Khushi Patel</dc:creator>
      <pubDate>Mon, 29 Jun 2026 13:56:01 +0000</pubDate>
      <link>https://dev.to/khushindpatel/why-does-linkedin-show-500-connections-instead-of-the-exact-number-40a5</link>
      <guid>https://dev.to/khushindpatel/why-does-linkedin-show-500-connections-instead-of-the-exact-number-40a5</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Have you ever noticed that LinkedIn displays &lt;strong&gt;"500+ Connections"&lt;/strong&gt; once someone crosses 500 connections, instead of showing the exact count like 723 or 1,842?&lt;/p&gt;

&lt;p&gt;At first glance, this might seem like a simple UI choice, but it's actually a great example of a &lt;strong&gt;product and system design decision&lt;/strong&gt; where engineering, business goals, and user psychology come together.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Product Perspective
&lt;/h2&gt;

&lt;p&gt;LinkedIn's goal is not to help users compare who has more connections. Instead, it wants to indicate that someone has a strong professional network.&lt;/p&gt;

&lt;p&gt;From a networking perspective:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;450 Connections → Growing Network
500 Connections → Well Connected Professional
2500 Connections → Also Well Connected Professional
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For most users, knowing whether someone has 1,200 or 1,500 connections doesn't provide significant additional value.&lt;/p&gt;

&lt;p&gt;So LinkedIn chooses a threshold:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 - 499  → Show exact number
500+     → Show "500+"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This communicates the important information while reducing unnecessary comparison.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Engineering Perspective
&lt;/h2&gt;

&lt;p&gt;Imagine LinkedIn has hundreds of millions of users.&lt;/p&gt;

&lt;p&gt;Every profile view needs to display:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Name&lt;/li&gt;
&lt;li&gt;Headline&lt;/li&gt;
&lt;li&gt;Profile picture&lt;/li&gt;
&lt;li&gt;Connection count&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Showing an exact connection count requires keeping that number constantly updated whenever:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A connection request is accepted&lt;/li&gt;
&lt;li&gt;A connection is removed&lt;/li&gt;
&lt;li&gt;An account is deleted&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For highly connected users, this count changes frequently.&lt;/p&gt;

&lt;p&gt;By displaying:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;500+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;523
524
525
526
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;LinkedIn reduces the importance of real-time precision.&lt;/p&gt;

&lt;p&gt;This gives engineers more flexibility around caching and data synchronization.&lt;/p&gt;




&lt;h2&gt;
  
  
  A Distributed Systems Trade-off
&lt;/h2&gt;

&lt;p&gt;In system design, there's a concept called:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Precision vs Practical Value&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ask yourself:&lt;/p&gt;

&lt;p&gt;Would a user experience change if LinkedIn showed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;12,842
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;500+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Probably not.&lt;/p&gt;

&lt;p&gt;Since the exact value provides little additional business value, LinkedIn can optimize for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Faster profile loads&lt;/li&gt;
&lt;li&gt;Better caching&lt;/li&gt;
&lt;li&gt;Lower database reads&lt;/li&gt;
&lt;li&gt;Simpler distributed updates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is a classic example of choosing an &lt;strong&gt;approximate answer when an exact answer isn't necessary&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real-World System Design Principle
&lt;/h2&gt;

&lt;p&gt;A common mistake in software engineering is trying to make everything perfectly accurate.&lt;/p&gt;

&lt;p&gt;Good system designers ask:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Does the user actually need this precision?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;ul&gt;
&lt;li&gt;Instagram likes may update with slight delays&lt;/li&gt;
&lt;li&gt;YouTube subscriber counts are often rounded&lt;/li&gt;
&lt;li&gt;Social media follower counts are abbreviated&lt;/li&gt;
&lt;li&gt;LinkedIn shows 500+ connections&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These systems intentionally sacrifice precision because the business value of exactness is low.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Deliverable System Design Lesson
&lt;/h2&gt;

&lt;p&gt;One of the most important lessons in system design is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Build for the requirement, not for perfection.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If the product requirement is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Show whether a user has a large professional network
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;500+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;solves the problem.&lt;/p&gt;

&lt;p&gt;If the requirement were:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Display the exact connection count for analytics purposes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then a different design would be necessary.&lt;/p&gt;

&lt;p&gt;Great engineering decisions are often about identifying where precision matters and where it doesn't.&lt;/p&gt;




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

&lt;p&gt;LinkedIn shows &lt;strong&gt;500+ connections&lt;/strong&gt; because the exact number provides little additional value to users after a certain threshold. This decision reduces social comparison, simplifies the user experience, and gives engineers more flexibility in scaling, caching, and synchronizing connection counts.&lt;/p&gt;

&lt;p&gt;It's a great example of a system design principle: &lt;strong&gt;optimize for what users actually need, not for perfect accuracy everywhere.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
