What is Content Delivery Network (CDN)? How CDN Work?
Content Delivery Network (CDN): Understanding Working and Its Benefits
.png&w=3840&q=75)
Content Delivery Network (CDN): Understanding Working and Its Benefits
.png&w=3840&q=75)
.png)
You are in Mumbai. You click play on a Netflix video. The movie’s files are stored on a server in Virginia, USA. Without a CDN, your request crosses the Pacific Ocean, hits a server 13,000 kilometres away, and the video data makes that round trip every second. You get buffering.
With a CDN, Netflix has already copied that video to an edge server in Mumbai. Your request travels 20 kilometres instead of 13,000. The video starts instantly.
That is the entire idea. Move the data closer to the person who needs it.
Today, CDNs carry more than half of all global internet traffic. Facebook, YouTube, Amazon, Netflix, and every major website you use runs on a CDN. When a website loads in milliseconds from anywhere in the world, a CDN is almost certainly why.
A Content Delivery Network (CDN) is a geographically distributed network of servers that caches and delivers web content to users from a server that is physically closest to them, reducing the time data needs to travel.
Break that apart:
Geographically distributed: Servers are placed in cities and data centres around the world, not in one central location
Caches content: Copies of static files (images, videos, CSS, JavaScript) are stored on these distributed servers so they do not have to be fetched from the origin every time
Closest server: When you request a webpage, the CDN automatically routes you to the nearest server, called an edge server, instead of the original host server
Key Analogy:
Think of a CDN like a chain of ATMs. Without ATMs, every time you need cash you would have to travel to your bank’s main branch, possibly in another city. With ATMs on every corner, you get your cash from the machine nearest to you. You do not care where the main bank is. You just get fast access wherever you are. A CDN does exactly this for website content: it puts copies near everyone so no one has to go the long way.
WITHOUT CDN:
User (Tokyo) ──────────────────────────→ Origin Server (New York)
13,000 km, ~200ms latency
Every user, every request goes to New York
WITH CDN:
User (Tokyo) ──→ Edge Server (Tokyo) ──→ (only if not cached) Origin Server
20 km, ~5ms latency
Cached content served locally in millisecondsWhen a user requests content from a website using a CDN, here is exactly what happens:
Step 1: USER REQUEST
User in London types www.example.com
Request goes to DNS server
Step 2: DNS ROUTING
DNS identifies the user's location
Instead of returning the origin server's IP address,
DNS returns the IP of the nearest CDN edge server
Step 3: CACHE CHECK (HIT)
Request arrives at CDN edge server in London
Edge server checks: "Do I have a cached copy of this file?"
If YES (Cache Hit):
Edge server delivers the file directly → done in ~5ms
Origin server is never contacted
Step 4: CACHE MISS (First-time or expired)
If the file is NOT cached (or has expired):
Edge server fetches the file from the origin server
Delivers it to the user
Stores a local copy for future requests
Step 5: SUBSEQUENT REQUESTS
Next user in London requests the same file
Edge server delivers from cache → fast
Origin server not involvedThe percentage of requests served from cache (without contacting the origin) is the cache hit ratio. A well-configured CDN achieves 80-95% cache hit ratio, meaning the origin server only handles 5-20% of all requests.
1,000,000 daily requests, 90% cache hit ratio:
900,000 requests → served by edge servers (fast, free from origin bandwidth)
100,000 requests → fetched from origin server
Origin server load reduced by 90%Type | How It Works | Example | Best For |
|---|---|---|---|
Public CDN | Shared infrastructure available to anyone | Cloudflare, Akamai, CloudFront | Most websites and apps |
Private CDN | Dedicated CDN for one organisation | Netflix Open Connect, Google Cloud CDN | Large enterprises with specific needs |
Pull CDN | Content is pulled from origin when first requested, then cached | Cloudflare, CloudFront | Dynamic or frequently updated content |
Push CDN | Content is manually uploaded to CDN servers in advance | KeyCDN, CDN77 | Large static files (software downloads, videos) |
Peer-to-Peer (P2P) CDN | Users share content with each other | BitTorrent, WebTorrent | Large file distribution |
Hybrid CDN | Combines public and private CDN elements | Azure CDN | Organizations with mixed requirements |
PULL CDN (most common):
Origin ← CDN fetches content on first request
CDN caches and serves all future requests
Pro: Automatic. Con: First request is slow (cache miss)
PUSH CDN:
Origin → You upload content to CDN manually
CDN serves from day one, no first-request delay
Pro: No cache miss. Con: Manual management of updatesCaching is the process of storing a copy of content so it can be served quickly on future requests. It is the core mechanism that makes CDNs fast.
HTTP Response Headers control caching behaviour:
Cache-Control: max-age=86400 ← Cache this file for 86,400 seconds (1 day)
Cache-Control: no-cache ← Do not cache this (force origin fetch every time)
Cache-Control: public ← Any CDN or browser can cache this
ETag: "abc123" ← Version identifier for cache validation
When a CDN edge server receives a request:
1. Check if the file exists in cache
2. Check if it has expired (based on max-age)
3. If expired, re-validate with origin using ETag
4. If ETag matches → extend cache, no new data transferred (304 Not Modified)
5. If ETag differs → fetch fresh copy from originContent Type | Cacheable? | Notes |
|---|---|---|
Images (PNG, JPG, WebP) | Yes | Set long TTL (30-365 days) |
CSS / JavaScript files | Yes | Version in filename for cache busting |
HTML pages (static) | Yes | Shorter TTL (hours) |
Videos | Yes | Large cached files, huge bandwidth savings |
API responses (dynamic) | Sometimes | Only if response is same for all users |
User-specific pages | No | Must come from origin every time |
Login/checkout pages | No | Contains personal data |
CDNs handle two fundamentally different types of content differently.
Content that is the same for every user: images, CSS, fonts, JavaScript, video files, PDFs.
User A requests logo.png → CDN caches it
User B requests logo.png → CDN serves from cache (no origin contact)
User C in a different city requests logo.png → nearest edge server serves it
Result: Origin server handles 0 requests for logo.png after the first oneContent that varies per user: news feeds, account pages, shopping cart, real-time data.
User A's dashboard → shows Alice's orders (personalised, cannot cache)
User B's dashboard → shows Bob's orders (different, cannot cache)
For dynamic content, CDNs use:
1. Dynamic acceleration: Optimised route from edge to origin
(pre-established TCP connections, intelligent routing)
2. Edge computing: Run logic at the edge to reduce origin calls
(personalisation, A/B testing, authentication at the edge)When designing a web system, a CDN fits at the edge layer between users and your application servers.
System Design with CDN:
Users Worldwide
|
v
[CDN Edge Layer] ← Serves 80-95% of all requests
Cloudflare/Akamai/CloudFront
| (cache miss only)
v
[Load Balancer]
|
┌───┴───┐
v v
[App] [App] ← Application servers handle only dynamic requests
| |
v v
[Database] ← Database only queried for truly dynamic data
Result: Database and app servers are protected from 80-95% of trafficCDN with Static and Dynamic Split
# Example: Serving a web application with CDN separation STATIC_ASSETS = { "images": "https://cdn.example.com/images/", # CDN serves these "css": "https://cdn.example.com/css/", # CDN serves these "js": "https://cdn.example.com/js/", # CDN serves these } DYNAMIC_ROUTES = { "/api/user": "origin server", # Cannot be cached (user-specific) "/api/orders": "origin server", # Cannot be cached (user-specific) "/dashboard": "origin server", # Cannot be cached } # In HTML: # <img src="https://cdn.example.com/images/logo.png"> ← CDN # <link href="https://cdn.example.com/css/styles.css"> ← CDN # <script>fetch('/api/user/profile')</script> ← Origin
Distance and latency relationship:
Origin Server only (New York):
User in New York: ~10ms
User in London: ~80ms
User in Mumbai: ~180ms
User in Tokyo: ~200ms
With CDN (edge servers everywhere):
User in New York: ~5ms (local edge)
User in London: ~5ms (London edge)
User in Mumbai: ~5ms (Mumbai edge)
User in Tokyo: ~5ms (Tokyo edge)
CDN reduces latency by 10x-40x for distant usersMetric | Without CDN | With CDN | Improvement |
|---|---|---|---|
Page load time (distant users) | 3-8 seconds | 0.5-1.5 seconds | 4-6x faster |
Origin server bandwidth | 100% of traffic | 5-20% of traffic | 80-95% reduction |
Time To First Byte (TTFB) | 200-500ms | 10-50ms | 5-10x faster |
Availability during traffic spike | May crash | Handles surge | DDoS protection |
Global consistency | Varies by location | Consistent everywhere | Uniform UX |
Feature | Without CDN | With CDN |
|---|---|---|
Content delivery | Single origin server handles all requests | Distributed edge servers serve most requests |
Latency | Depends on distance to origin | Low regardless of location |
Scalability | Limited by origin server capacity | Scales globally with edge network |
Bandwidth costs | High (origin handles everything) | Lower (CDN absorbs majority) |
DDoS protection | Vulnerable | CDN absorbs attack traffic |
Single point of failure | Yes | No (distributed redundancy) |
Setup required | None | DNS and CDN configuration |
Cost | Server hosting cost only | CDN subscription + hosting |
<!-- Without CDN: file served from your own server -->
<link href="/css/bootstrap.min.css" rel="stylesheet">
<!-- With CDN: file served from jsDelivr's edge servers worldwide -->
<link href="<https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css>"
rel="stylesheet">
<!-- The CDN version:
- Loads from the server nearest to the user
- May already be cached in the user's browser from another site
- Reduces your server's bandwidth costs to zero for this file -->Netflix: Runs Netflix Open Connect, a private CDN. Netflix pre-positions popular movies and shows on edge servers in ISP data centres before users request them. During peak hours, over 95% of Netflix traffic is served from local edge servers without ever touching Netflix’s origin infrastructure.
YouTube: Uses Google’s CDN infrastructure with edge servers in hundreds of cities. Video files are pre-cached based on popularity. A trending video in India is cached on servers across Indian cities before demand spikes.
E-Commerce (Flash Sales): When a major sale goes live, thousands of users hit the site simultaneously. Without a CDN, the origin server crashes under the load. The CDN absorbs the burst, serving product images, CSS, and JavaScript from edge servers while only dynamic requests (adding to cart, payment) reach the origin.
# Measuring CDN impact: cache hit tracking import time import requests def measure_response_time(url, label): start = time.time() response = requests.get(url) elapsed = (time.time() - start) * 1000 cache_status = response.headers.get('CF-Cache-Status', 'UNKNOWN') print(f"{label}:{elapsed:.0f}ms | Cache:{cache_status}") return elapsed # Same image: first request (cache miss) vs second request (cache hit) image_url = "https://cdn.example.com/images/hero.jpg" t1 = measure_response_time(image_url, "First request (cache miss)") t2 = measure_response_time(image_url, "Second request (cache hit)") print(f"Cache speedup:{t1/t2:.1f}x faster") # First request (cache miss): 180ms | Cache: MISS # Second request (cache hit): 12ms | Cache: HIT # Cache speedup: 15x faster
Dramatically faster load times for all users: By serving content from the nearest edge server, CDNs reduce latency from hundreds of milliseconds to single digits for users far from the origin. A user in Tokyo gets the same fast experience as a user next door to the origin server. Faster pages directly reduce bounce rates and improve conversion
Massive reduction in origin server load: When 80-95% of requests are served from CDN cache, the origin server only handles a tiny fraction of traffic. This means smaller, cheaper servers can handle the same global user base, and the origin is protected from traffic spikes that would otherwise cause crashes
Built-in DDoS protection and security: CDNs sit at the edge of the network, absorbing attack traffic before it reaches the origin. Large CDNs can absorb hundreds of terabits per second of DDoS traffic. They also centralise TLS/SSL certificate management and can run Web Application Firewalls (WAF) at the edge
High availability and redundancy: Content is distributed across dozens or hundreds of edge servers. If one data centre goes offline, traffic automatically routes to the next nearest server. No single hardware failure can take down content globally
Additional cost: CDN services add another monthly expense on top of hosting costs. For high-traffic sites the bandwidth savings outweigh the CDN fees, but for low-traffic sites the cost-benefit analysis may not favour a CDN
Cache invalidation complexity: When you update content on the origin server, cached copies on edge servers may serve stale (outdated) versions until the cache expires. Forcing an immediate cache purge requires manual action or a CDN API call. Getting cache expiry (TTL) right requires careful tuning
Debugging becomes harder: When a user reports a bug, the content they saw may have come from an edge server cache, not the origin. Reproducing bugs that only appear on certain edge servers requires more complex debugging workflows
Not effective for highly dynamic or personalised content: Pages that are unique per user (dashboards, checkout, account pages) cannot be cached and must always come from the origin. A CDN provides no speed benefit for these requests and adds a small amount of latency for the extra network hop
A CDN is the infrastructure that makes the global web feel local.
Here is the full recap:
A CDN is a distributed network of edge servers that caches copies of your content close to users worldwide, reducing the physical distance data must travel.
When a user requests content, DNS routing sends them to the nearest edge server. If the content is cached (cache hit), it is served in milliseconds. If not (cache miss), the edge server fetches from origin, caches it, and serves future requests locally.
Core components: Origin Server (master copy), Edge Servers / PoPs (serve users), DNS (routing), Load Balancer (distribute traffic), Control Plane (manage caching rules).
Static content (images, CSS, video) is easily cached and delivers massive bandwidth savings. Dynamic content (personalised pages, APIs) cannot be fully cached but benefits from CDN’s optimised routing to origin.
A CDN reduces origin server load by 80-95%, reduces global latency by 10-40x, protects against DDoS attacks, and ensures consistent availability even during traffic spikes.
Popular providers: Cloudflare (free tier, excellent security), Amazon CloudFront (deep AWS integration), Akamai (enterprise-grade), Fastly (real-time edge compute).
FAQ