Back to course
    article~25 min readCaching & Performance

    CDN Basics

    Push content closer to users and protect origins from traffic spikes.

    CDN Basics — Beginner Friendly System Design Guide

    Why Distance Makes Internet Slow

    Imagine Hotstar servers exist only in:

    USA
    

    Now user in Jaipur watches IPL.

    Video must travel:

    • thousands of kilometers

    Result:

    • buffering
    • high latency
    • slow loading

    This problem is solved using:

    CDN
    

    What Is CDN?

    CDN stands for:

    Content Delivery Network
    

    A CDN is:

    A globally distributed network of servers that stores and delivers content closer to users.


    Simple Real-Life Analogy

    Imagine Amazon warehouse only in Mumbai.

    Customer in Jaipur orders product.

    Delivery becomes slow.

    So Amazon creates:

    • warehouses in multiple cities

    CDN works similarly.


    Real Example — Netflix

    When you watch Netflix in India:

    • video usually comes from nearby Indian CDN server
    • not directly from US servers

    This improves:

    • speed
    • streaming quality
    • reliability

    CDN Flow

    User Requests Video
            │
            ▼
    Nearest CDN Server
       │               │
    Cached            Not Cached
       │                │
       ▼                ▼
    Return Fast      Fetch From Origin
    Content          Server
    

    What Is Origin Server?

    Origin server is:

    • main backend server
    • original source of content

    Example:

    • main Hotstar infrastructure

    Why CDNs Are Important

    Without CDN:

    Users Worldwide
            │
            ▼
    Single Origin Server ❌
    

    Problems:

    • slow loading
    • server overload
    • huge bandwidth cost

    With CDN

    Users
      │
      ▼
    Nearest CDN Edge Server
      │
      ▼
    Fast Content Delivery
    

    What Content Is Cached In CDN?

    Usually:

    • images
    • videos
    • CSS
    • JavaScript
    • fonts
    • static files

    Real Example — Swiggy

    Swiggy may serve:

    • restaurant images
    • app assets
    • banners

    through CDN.

    This reduces load on main servers.


    What Is Edge Server?

    CDN servers placed across:

    • countries
    • cities
    • regions

    are called:

    Edge Servers
    

    They are physically closer to users.


    Global CDN Architecture

    Users Worldwide
            │
            ▼
    Nearest Edge Server
            │
     ┌──────┼────────┐
     ▼               ▼
    India CDN      US CDN
            │
            ▼
    Origin Server
    

    Benefits Of CDN

    BenefitWhy Important
    Lower latencyFaster loading
    Reduced bandwidthLower infrastructure cost
    Better scalabilityHandles traffic spikes
    Improved reliabilityReduces origin pressure
    Faster global deliveryBetter user experience

    Real Example — IPL Traffic Spike

    During IPL:

    • crores of users stream simultaneously

    Without CDN:

    • origin servers may crash

    CDN absorbs massive traffic load.


    CDN Protects Origin Servers

    Without CDN:

    Millions Of Requests
            │
            ▼
    Origin Server Overloaded ❌
    

    With CDN

    Millions Of Requests
            │
            ▼
    CDN Edge Servers
            │
            ▼
    Only Few Requests Reach Origin
    

    Huge reduction in backend pressure.


    Cache Hit vs Cache Miss


    Cache Hit

    Content already exists in CDN.

    Very fast.


    Cache Miss

    CDN does not have content.

    Fetches from:

    • origin server

    then caches it.


    Flow

    User Request
          │
          ▼
    CDN Check
      │            │
    Hit           Miss
     │              │
     ▼              ▼
    Fast         Fetch From Origin
    Response     Store In Cache
    

    Real Example — YouTube

    Popular videos:

    • cached heavily in CDNs

    Rare videos:

    • may come from origin/datacenter

    CDN And DNS

    CDNs work closely with:

    • DNS

    DNS routes users to:

    • nearest CDN edge server

    DNS + CDN Flow

    User Opens Website
            │
            ▼
    DNS Detects Location
            │
            ▼
    Nearest CDN Selected
            │
            ▼
    Content Delivered
    

    CDN And Static Assets

    CDNs are ideal for:

    • static content

    because content changes less frequently.


    Example Static Assets

    AssetCDN Friendly?
    ImagesYes
    VideosYes
    CSSYes
    JS FilesYes
    FontsYes

    Dynamic Content And CDN

    Dynamic content is harder to cache.

    Examples:

    • payment responses
    • personalized dashboards
    • live balances

    Need careful caching strategies.


    Real Example — PhonePe

    Static assets:

    • served from CDN

    Sensitive payment APIs:

    • handled by backend servers directly

    CDN Cache Expiry

    CDN content eventually expires.

    Using:

    • TTL
    • Cache-Control headers

    Expiry Flow

    Content Cached
          │
          ▼
    TTL Expiry
          │
          ▼
    Fetch Fresh Copy From Origin
    

    Real Example — News Websites

    News homepage changes frequently.

    CDN cache may refresh:

    • every few minutes

    Popular CDN Providers

    ProviderCommon Usage
    CloudflareWebsites & APIs
    CloudFrontAWS
    AkamaiEnterprise CDN
    FastlyHigh-performance delivery

    CDN And DDoS Protection

    CDNs also help against:

    • traffic attacks
    • bot traffic
    • DDoS attacks

    because edge servers absorb traffic.


    DDoS Protection Flow

    Malicious Traffic
           │
           ▼
    CDN Edge Servers
           │
           ▼
    Origin Server Protected
    

    Real Example — Flipkart Big Billion Day

    Huge traffic spikes happen.

    CDN helps:

    • serve product images
    • reduce backend load
    • improve performance

    Common Beginner Misconceptions


    "CDN Replaces Backend"

    No.

    CDN mainly accelerates:

    • static delivery

    Backend still handles:

    • business logic
    • databases
    • APIs

    "CDN Only Helps Global Apps"

    Even Indian-only apps benefit because:

    • traffic distribution improves
    • latency reduces

    "CDN Stores Everything Forever"

    No.

    Content expires and refreshes periodically.


    Final Mental Model

    CDN =
    Distributed edge servers
    that deliver content closer to users
    

    Complete Architecture

    Users
      │
      ▼
    DNS
      │
      ▼
    Nearest CDN Edge Server
      │
     ┌──┴─────────┐
     ▼            ▼
    Cache Hit    Origin Server
      │
      ▼
    Fast Response
    

    One-Line Interview Definition

    A CDN (Content Delivery Network) is a globally distributed system of edge servers that caches and delivers content closer to users, reducing latency and protecting origin servers from traffic spikes.

    Module context

    From browser cache to Redis clusters and CDNs. Caching strategies that turn slow apps into fast ones, with real-world invalidation patterns.

    Mark this lesson complete when you finish reviewing it.