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)
Dynamic Content (Partially cacheable)
NOT Cacheable
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
| Provider | Strengths | Used By | |
|---|---|---|---|
| **Cloudflare** | Free tier, DDoS protection, easy setup | 20% of all websites | |
| **AWS CloudFront** | Deep AWS integration, global reach | Netflix, Slack | |
| **Akamai** | Largest network, enterprise-grade | Apple, Microsoft | |
| **Fastly** | Real-time purging, edge computing | GitHub, Stripe | |
| **Vercel Edge Network** | Built-in with Vercel deployments | Next.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:
image.jpg?v=2 → CDN treats it as a new fileWhen to Use a CDN
Always use a CDN if:
You might skip a CDN if:
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.