<?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: NISCHIT D S</title>
    <description>The latest articles on DEV Community by NISCHIT D S (@nischit_007).</description>
    <link>https://dev.to/nischit_007</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%2F4102010%2F8634cca3-f7c2-4bba-b496-b4ae7035d9c2.JPG</url>
      <title>DEV Community: NISCHIT D S</title>
      <link>https://dev.to/nischit_007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nischit_007"/>
    <language>en</language>
    <item>
      <title>Reliability &amp; Availability</title>
      <dc:creator>NISCHIT D S</dc:creator>
      <pubDate>Wed, 09 Sep 2026 03:28:46 +0000</pubDate>
      <link>https://dev.to/nischit_007/reliability-availability-46jk</link>
      <guid>https://dev.to/nischit_007/reliability-availability-46jk</guid>
      <description>&lt;p&gt;&lt;strong&gt;| What's the Difference?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These terms are often confused, but they measure different things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reliability : System performs correctly without failure&lt;/li&gt;
&lt;li&gt;Availability : System is operational when needed&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Analogy: Think of a car:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reliable = The car doesn't break down during your trip&lt;/li&gt;
&lt;li&gt;Available = The car is ready to drive when you need it
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A system can be available but unreliable (works but gives wrong results), or reliable but unavailable (works correctly but only 50% of the time).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;| Measuring Availability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Availability is typically expressed as a percentage of uptime:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Availability = Uptime / (Uptime + Downtime) × 100%

**Real-world examples:**

Google Search: ~99.99% (four nines)
AWS S3: 99.99% availability SLA
Credit card processing: Often requires 99.999%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;| Calculating Composite Availability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For components in sequence (all must work):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A_total = A₁ × A₂ × A₃ × ... × Aₙ
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example: Three services at 99% each in sequence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0.99 × 0.99 × 0.99 = 97.03%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For components in parallel (any can work):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A_total = 1 - (1 - A₁) × (1 - A₂) × ... × (1 - Aₙ)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example: Two servers at 99% each in parallel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 - (0.01 × 0.01) = 99.99%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;| Measuring Reliability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Reliability is measured using these key metrics:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mean Time Between Failures (MTBF)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Average time the system operates before failing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MTBF = Total Operating Time / Number of Failures
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example: Server runs for 8760 hours/year with 2 failures&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MTBF = 8760 / 2 = 4380 hours
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Mean Time To Recovery (MTTR)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Average time to restore the system after failure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MTTR = Total Downtime / Number of Failures
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lower MTTR = &lt;strong&gt;Better availability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Relationship to Availability&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;Availability = MTBF / (MTBF + MTTR)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Key Insight: You can improve availability by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increasing MTBF (fail less often)&lt;/li&gt;
&lt;li&gt;Decreasing MTTR (recover faster)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Often, reducing MTTR is easier and cheaper than increasing MTBF!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;| Common Failure Modes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Software Failures&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory leaks - Application crashes over time&lt;/li&gt;
&lt;li&gt;Bugs - Incorrect behavior under certain conditions&lt;/li&gt;
&lt;li&gt;Deadlocks - System hangs waiting for resources&lt;/li&gt;
&lt;li&gt;Resource exhaustion - Disk full, too many connections&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Human Errors&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Studies show &lt;strong&gt;70-80%&lt;/strong&gt; of outages are caused by humans:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Configuration mistakes&lt;/li&gt;
&lt;li&gt;Deployment errors&lt;/li&gt;
&lt;li&gt;Accidental deletions&lt;/li&gt;
&lt;li&gt;Security misconfigurations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;External Failures&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Network partitions&lt;/li&gt;
&lt;li&gt;Third-party service outages&lt;/li&gt;
&lt;li&gt;Power failures&lt;/li&gt;
&lt;li&gt;Natural disasters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;| Patterns for High Availability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Redundancy :&lt;/strong&gt; Eliminate single points of failure by duplicating components.&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%2F7dyh31psjf897yjac5et.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%2F7dyh31psjf897yjac5et.png" alt=" " width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of redundancy:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Active-Active: All nodes handle traffic (load sharing)&lt;/li&gt;
&lt;li&gt;Active-Passive: Standby nodes take over on failure&lt;/li&gt;
&lt;li&gt;N+1: One extra server for every N servers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Health Checks &amp;amp; Monitoring :&lt;/strong&gt; Detect failures quickly to minimize MTTR.&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%2Feibc9u8zxxpjxfvdb25v.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%2Feibc9u8zxxpjxfvdb25v.png" alt=" " width="799" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Health check best practices:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check every 10-30 seconds&lt;/li&gt;
&lt;li&gt;Use separate endpoint from main API&lt;/li&gt;
&lt;li&gt;Include dependency checks&lt;/li&gt;
&lt;li&gt;Set appropriate timeouts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Failover Strategies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwt7gli6yiys39me2bpz8.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%2Fwt7gli6yiys39me2bpz8.png" alt=" " width="800" height="285"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Circuit Breaker Pattern :&lt;/strong&gt; Prevent cascading failures by stopping calls to failing services.&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%2F6t4jzh1nkxd705fep3hv.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%2F6t4jzh1nkxd705fep3hv.png" alt=" " width="799" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Closed: Normal operation, requests pass through&lt;/li&gt;
&lt;li&gt;Open: Requests fail immediately (no call to service)&lt;/li&gt;
&lt;li&gt;Half-Open: Allow limited requests to test recovery&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Retry with Exponential Backoff : Handle transient failures gracefully.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;retry_with_backoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;operation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_retries&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_retries&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;operation&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;TransientError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;wait_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uniform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;wait_time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Max retries exceeded&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Key points:

- Start with small delay (1s)
- Double each time (1s, 2s, 4s, 8s...)
- Add jitter to prevent thundering herd
- Set maximum retry count
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Real-World Architecture: High Availability Database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fypjsn33s1iru200xpq53.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%2Fypjsn33s1iru200xpq53.png" alt=" " width="800" height="655"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This architecture provides:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read scaling via replicas&lt;/li&gt;
&lt;li&gt;Automatic failover if primary fails&lt;/li&gt;
&lt;li&gt;Point-in-time recovery from S3 backups&lt;/li&gt;
&lt;li&gt;Geographic distribution possible&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key Takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Availability measures uptime, Reliability measures correctness&lt;/li&gt;
&lt;li&gt;Each "nine" of availability is 10x harder to achieve&lt;/li&gt;
&lt;li&gt;Parallel redundancy dramatically improves availability&lt;/li&gt;
&lt;li&gt;Reducing MTTR is often easier than increasing MTBF&lt;/li&gt;
&lt;li&gt;Human error causes most outages—automate and use guardrails&lt;/li&gt;
&lt;li&gt;Circuit breakers prevent cascading failures&lt;/li&gt;
&lt;li&gt;SLOs should be based on user needs, not engineering pride&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>systemdesign</category>
      <category>learning</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Scalability Principles</title>
      <dc:creator>NISCHIT D S</dc:creator>
      <pubDate>Mon, 31 Aug 2026 04:55:25 +0000</pubDate>
      <link>https://dev.to/nischit_007/scalability-principles-2758</link>
      <guid>https://dev.to/nischit_007/scalability-principles-2758</guid>
      <description>&lt;p&gt;&lt;strong&gt;| What is Scalability?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Scalability is the ability of a system to handle increased load by adding resources. A scalable system can grow to accommodate more users, more data, or more transactions without a significant degradation in performance.&lt;/p&gt;




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

&lt;ul&gt;
&lt;li&gt;A small café can serve 20 customers comfortably&lt;/li&gt;
&lt;li&gt;As it gets popular, you need to scale&lt;/li&gt;
&lt;li&gt;You can make the kitchen bigger (vertical scaling)&lt;/li&gt;
&lt;li&gt;Or open more locations (horizontal scaling)&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;| Why Does Scalability Matter?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Viral growth&lt;/strong&gt; : Your startup might go viral overnight&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unpredictable traffic&lt;/strong&gt; : Black Friday, viral content, news events&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost efficiency&lt;/strong&gt; : Pay for what you need, when you need it&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User experience&lt;/strong&gt; : Slow apps lose users (53% abandon if &amp;gt;3s load)&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;| Vertical vs Horizontal Scaling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are two fundamental approaches to scaling:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vertical Scaling (Scale Up)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add more power to your existing machine - more CPU, RAM, or storage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before: 4 CPU, 8GB RAM, 100GB Storage
After:  32 CPU, 128GB RAM, 2TB Storage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Pros Of Vertical Scaling**

- Simple to implement
- No code changes needed
- Lower complexity
- ACID compliance easier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Cons Of Vertical Scaling**

- Hardware limits exist
- Single point of failure
- Expensive at high end
- Downtime during upgrades
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;| Horizontal Scaling (Scale Out)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add more machines to distribute the load.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before: 1 server handling all traffic
After:  10 servers sharing the load
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Pros Of Horizontal Scaling**

- Theoretically unlimited
- Better fault tolerance
- Cost-effective at scale
- No single point of failure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Cons Of Horizontal Scaling**

- More complex architecture
- Data consistency challenges
- Requires load balancing
- Network latency between nodes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Real-World Example: Instagram**

- Started with a single server
- Scaled vertically until they hit limits
- Moved to horizontal scaling with sharded databases
- Now runs on thousands of servers across multiple data centers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;| Key Metrics for Scalability&lt;/strong&gt;&lt;br&gt;
To measure scalability, you need to understand these key metrics:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. **Throughput&lt;/strong&gt;** : Requests per second (RPS) your system can handle.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Example: "Our API handles 10,000 RPS"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. **Latency&lt;/strong&gt;** : Time taken to process a single request (measured in milliseconds).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Important: P50, P95, P99 percentiles matter more than averages!

P50: 50ms  (50% of requests faster than this)
P95: 100ms (95% of requests faster than this)
P99: 500ms (99% of requests faster than this)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The P99 catches the "unlucky" slow requests that affect user experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. **The Scalability Equation&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;Throughput = Concurrency / Latency
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your average latency is 100ms and you have 100 concurrent workers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Throughput = 100 / 0.1 = 1,000 RPS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. **Amdahl's Law&lt;/strong&gt;** : The speedup of a program using multiple processors is limited by the sequential fraction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Speedup = 1 / (S + (1-S)/N)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where S = sequential fraction, N = number of processors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Insight&lt;/strong&gt;: If 10% of your code is sequential, adding infinite processors only gives &lt;strong&gt;10x speedup&lt;/strong&gt; maximum!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;| Common Scalability Patterns&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. **Load Balancing&lt;/strong&gt;** : Distribute requests across multiple servers to prevent any single server from becoming a bottleneck.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        ┌─────────────────┐
        │  Load Balancer  │
        └────────┬────────┘
       ┌─────────┼─────────┐
       ▼         ▼         ▼
   ┌───────┐ ┌───────┐ ┌───────┐
   │Server1│ │Server2│ │Server3│
   └───────┘ └───────┘ └───────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. **Caching&lt;/strong&gt; **: Store frequently accessed data in memory for faster retrieval.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rule of thumb:&lt;/strong&gt; Cache 20% of data = handle 80% of requests (Pareto principle)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. **Database Sharding&lt;/strong&gt;** : Split your database across multiple machines based on a shard key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Shard Key: user_id

User 1-1M    → Shard A
User 1M-2M   → Shard B  
User 2M-3M   → Shard C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. **Microservices&lt;/strong&gt;** : Break your monolith into smaller, independently scalable services.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Monolith: One thing does everything
    ↓
Microservices: Each service scales independently

Auth Service  → 2 instances (light load)
Image Service → 20 instances (heavy load)
API Gateway   → 5 instances (medium load)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. **Asynchronous Processing&lt;/strong&gt; **: Use message queues to handle time-consuming tasks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Request → API → Queue → Worker → Done!
     ↓
  Quick Response (Task queued!)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfect for: Email sending, image processing, report generation&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. **Read Replicas&lt;/strong&gt;** : Create read-only copies of your database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌──────────────┐
│  Primary DB  │ ← Writes
└──────┬───────┘
       │ Replicates
   ┌───┴───┐
   ▼       ▼
┌─────┐ ┌─────┐
│Rep 1│ │Rep 2│ ← Reads
└─────┘ └─────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Works great for read-heavy workloads (80%+ reads).&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;| Stateless vs Stateful Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. **Stateless Services&lt;/strong&gt; **: Each request contains all information needed to process it. The server doesn't remember previous requests.&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="err"&gt;Request:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;token:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"abc123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;action:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"getData"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
         &lt;/span&gt;&lt;span class="err"&gt;↓&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;Any&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;→&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Process&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;→&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Response&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Benefits:**

- Easy to scale horizontally
- Any server can handle any request
- Simple load balancing
- No session affinity required
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. **Stateful Services&lt;/strong&gt;** : The server maintains client state between requests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Challenges:**

- Need sticky sessions or shared state
- More complex failover
- Session storage required
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best Practice: Externalize State&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;Instead of:
Server Memory → Session Data

Use:
┌─────────┐    ┌───────────┐    ┌─────────┐
│Client A │───▶│  Server 1 │───▶│  Redis  │
└─────────┘    └───────────┘    │ (State) │
┌─────────┐    ┌───────────┐    │         │
│Client B │───▶│  Server 2 │───▶│         │
└─────────┘    └───────────┘    └─────────┘

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

&lt;/div&gt;



&lt;p&gt;This gives you the benefits of both: stateful behavior with stateless architecture.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;| Real-World Example: Scaling Twitter&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's see how a real company approached scalability:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The Challenge

- 500 million tweets per day
- Millions of users refreshing feeds
- Celebrity tweets can spike traffic 100x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Solutions Twitter Used&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Fan-out on Write :&lt;/strong&gt; When you tweet, it's pre-computed into your followers' timelines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You tweet → Immediately written to all followers' timeline cache

Trade-off: More storage, but faster reads.

Exception: Celebrities use fan-out on read (accounts with millions of followers).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Redis for Timeline Cache :&lt;/strong&gt; Each user's home timeline is cached. Recent tweets always available instantly.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;3. Separate Read/Write Paths : *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tweets → Write Cluster (optimized for writes)
Reads  → Read Cluster (optimized for reads)

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

&lt;/div&gt;



&lt;p&gt;Eventually consistent (you might not see your tweet for a few seconds).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Geographic Distribution&lt;/strong&gt; : Data centers worldwide. Users routed to nearest location.&lt;/p&gt;




&lt;p&gt;| Key Takeaways&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scalability is about handling growth&lt;/strong&gt; without sacrificing performance&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Horizontal scaling **(adding machines) is generally preferred over **vertical scaling&lt;/strong&gt; (bigger machines)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stateless architectures&lt;/strong&gt; are easier to scale than stateful ones&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Caching, load balancing, and database sharding&lt;/strong&gt; are essential patterns&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure throughput, latency, and availability&lt;/strong&gt; to track scalability&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real systems use multiple strategies&lt;/strong&gt; tailored to specific use cases&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>systemdesign</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
