← Back to Learn
Beginner6 April 20265 min read

CDN — Why Netflix Doesn't Buffer (And Your App Shouldn't Either)

How does Netflix stream 4K video to 200 million users without lag? CDNs. Let's understand Content Delivery Networks with a chai stall franchise analogy.

cdnperformancecachingbasics
Share:

What is a CDN?

Imagine you run a famous chai stall in Mumbai. People from Delhi, Bangalore, and Kolkata hear about your chai and want to try it. But they can't fly to Mumbai every time they want a cup.

So what do you do? You open franchise stalls in Delhi, Bangalore, and Kolkata — each serving the same chai recipe. Now customers get their chai from the nearest stall instead of traveling to Mumbai.

A CDN (Content Delivery Network) does exactly this for your website's content. Instead of serving everything from one server in one location, your content is cached on servers worldwide. Users get content from the server closest to them.

Without CDN:
🇮🇳 User in Delhi → Request travels to 🇺🇸 Server in Virginia
Round trip: ~200ms 🐌

With CDN:
🇮🇳 User in Delhi → Request goes to 🇮🇳 CDN Server in Mumbai
Round trip: ~20ms ⚡

Why Does It Matter?

Speed

Every millisecond counts. Amazon found that every 100ms of latency costs them 1% in sales. A CDN can reduce load times by 50-70%.

Reliability

If your origin server goes down, the CDN can still serve cached content. Your website stays up even during server failures.

Scalability

During a viral moment (your app gets featured on Shark Tank), millions of users hit your site simultaneously. A CDN distributes this load across hundreds of servers worldwide instead of crushing your single origin server.

Cost

Serving content from a CDN is cheaper than serving it from your origin server. CDN providers have optimized networks and bulk bandwidth deals.

Real-World Example: How Hotstar Handles IPL

During an IPL match, Hotstar serves live video to 25+ million concurrent users. Here's how CDN makes it possible:

🏏 Live Match Feed
   ↓
📡 Origin Server (encodes video)
   ↓
🌐 CDN Edge Servers (100+ locations in India)
   ├── Mumbai Edge → serves users in Maharashtra
   ├── Delhi Edge → serves users in North India
   ├── Bangalore Edge → serves users in South India
   ├── Kolkata Edge → serves users in East India
   └── ... (100+ more locations)
   ↓
📱 Each user streams from their nearest edge server

Without CDN, 25 million users would all hit one server. With CDN, the load is distributed across 100+ servers. Each server handles ~250K users — much more manageable.

What Can a CDN Cache?

Static Content (Perfect for CDN)

• Images (product photos, profile pictures)
• CSS and JavaScript files
• Fonts
• Videos
• PDFs and documents

Dynamic Content (Partially cacheable)

• API responses that don't change often (product catalog)
• HTML pages that are the same for all users (blog posts)
• Search results for popular queries

NOT Cacheable

• User-specific data (your bank balance)
• Real-time data (live stock prices)
• POST/PUT/DELETE requests

How Does a CDN Work?

Step 1: First Request (Cache Miss)

👤 User in Delhi requests sahilsudan.com/image.jpg
   ↓
🏢 CDN Edge Server in Delhi: "I don't have this yet"
   ↓
📡 Fetches from Origin Server in Mumbai
   ↓
💾 Stores a copy (caches it)
   ↓
👤 Returns image to user

Step 2: Subsequent Requests (Cache Hit)

👤 Another user in Delhi requests sahilsudan.com/image.jpg
   ↓
🏢 CDN Edge Server in Delhi: "I have this cached! ✅"
   ↓
👤 Returns image instantly (no origin server involved)

Step 3: Cache Expiry

After a set time (TTL — Time To Live), the cached content expires. The next request fetches a fresh copy from the origin.

CDN Architecture

                    ┌─────────────┐
                    │   Origin    │
                    │   Server    │
                    └──────┬──────┘
                           │
              ┌────────────┼────────────┐
              │            │            │
        ┌─────┴─────┐ ┌───┴───┐ ┌─────┴─────┐
        │  Edge     │ │ Edge  │ │  Edge     │
        │  Mumbai   │ │ Delhi │ │ Singapore │
        └─────┬─────┘ └───┬───┘ └─────┬─────┘
              │            │            │
         Users in      Users in    Users in
         West India    North India  SE Asia

Popular CDN Providers

ProviderStrengthsUsed By
**Cloudflare**Free tier, DDoS protection, easy setup20% of all websites
**AWS CloudFront**Deep AWS integration, global reachNetflix, Slack
**Akamai**Largest network, enterprise-gradeApple, Microsoft
**Fastly**Real-time purging, edge computingGitHub, Stripe
**Vercel Edge Network**Built-in with Vercel deploymentsNext.js apps

CDN + Cache Invalidation

The hardest part of using a CDN is cache invalidation — telling the CDN to forget old content when you update something.

Scenario: You update your profile picture. The CDN has the old picture cached for 24 hours. Users see the old picture until the cache expires.

Solutions:

1. Cache busting: Add version to URL: image.jpg?v=2 → CDN treats it as a new file
2. Purge API: Tell the CDN to delete the cached version immediately
3. Short TTL: Set cache to expire every 5 minutes (trade-off: more origin requests)

When to Use a CDN

Always use a CDN if:

• Your users are geographically distributed
• You serve static assets (images, CSS, JS)
• You want faster page loads
• You need DDoS protection

You might skip a CDN if:

• All your users are in one city
• Your app is purely dynamic (real-time chat)
• You're in early development with 10 users

Key Takeaway

CDN = "Bring the content closer to the user." Instead of making users travel across the world to your server, put copies of your content on servers near them.

It's one of the simplest yet most impactful optimizations in system design. In interviews, always mention CDN when discussing performance, scalability, or serving static content. It shows you think about the user experience, not just the backend.

👨‍💻
Sahil Sudan

Software Engineer at Spense. I write about system design, web development, and fintech — explained simply for students and developers.

📬 Stay Updated

Get a new System Design or fintech insight every week. No spam, unsubscribe anytime.

Share: