What is a CDN — Simple Explanation with Examples
A CDN (Content Delivery Network) is a distributed network of servers that delivers web content to users based on their geographic location, reducing latency and improving load times.
In this guide, you’ll learn how CDNs work, why they’re essential for modern websites, and how to use them to speed up your own applications. CDNs power everything from streaming video to e-commerce checkout pages.
Why CDNs Exist — The Problem They Solve
The internet is a global network, but physical distance still matters. A user in Tokyo requesting a page from a server in New York experiences noticeable delay (latency):
- Round-trip time: ~200ms for Tokyo ↔ New York
- Packet loss: Higher over long distances
- Bandwidth bottlenecks: A single server can only handle so many concurrent connections
A CDN solves this by placing servers (called edge servers) in multiple geographic locations. When a user requests content, the CDN delivers it from the nearest edge server instead of the origin.
The Traffic Spike Problem
When a website goes viral or experiences a traffic surge, a single origin server can be overwhelmed. CDNs absorb this load by distributing it across hundreds or thousands of edge servers, preventing crashes.
The Analogy — Warehouse vs Local Store
Imagine you own a company that sells widgets. All your inventory is in a single central warehouse. Customers anywhere in the world must order from that one warehouse, paying high shipping costs and waiting weeks for delivery.
Now imagine opening small retail stores in every major city. Customers walk in and get widgets instantly. That’s a CDN.
The central warehouse is your origin server. The local stores are edge servers. When a customer wants a widget, they go to the nearest store. If the store doesn’t have it, it fetches one from the warehouse and keeps it on the shelf for the next customer (caching).
How a CDN Routes Requests
User in London
│
▼
┌──────────────────┐
│ DNS Resolution │ CDN's DNS returns IP of nearest edge server
└────────┬─────────┘
│
▼
┌──────────────────┐
│ London Edge │ Edge server checks its cache
│ Server │
└──┬───────────────┘
│ ┌──────────────────┐
├── Cache HIT ──────────►│ Serve cached │
│ │ content instantly │
│ └──────────────────┘
│
└── Cache MISS ─────────►┌──────────────────┐
│ Fetch from │
│ origin server │
├──────────────────┤
│ Cache for next │
│ request │
│ (set TTL) │
└──────────────────┘Static vs Dynamic Content
CDNs handle both types, but differently:
| Type | Description | Cacheable? | Examples |
|---|---|---|---|
| Static | Rarely changes | Yes (long TTL) | Images, CSS, JS, fonts, PDFs |
| Dynamic | Changes per user/request | Limited or no | API responses, user profiles, stock prices |
Caching Strategy
# Nginx config — cache static assets for 1 year
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
add_header Cache-Control "public, immutable";
}CDN Benefits
| Benefit | Impact |
|---|---|
| Speed | 50–80% reduction in page load time for global users |
| Reliability | If one edge server fails, traffic routes to another |
| DDoS protection | CDNs absorb massive traffic spikes (Cloudflare: 26M req/s) |
| Bandwidth savings | Origin server handles fewer requests (cache hit rate >90%) |
| SSL termination | CDNs handle TLS at the edge, offloading origin servers |
Popular CDNs
| CDN | Key Feature | Global Servers |
|---|---|---|
| Cloudflare | Built-in DDoS + WAF + CDN | 330+ cities |
| Akamai | Enterprise-grade, dynamic acceleration | 4,100+ locations |
| Fastly | Instant cache purge, edge computing (VCL/Compute) | 100+ PoPs |
| Amazon CloudFront | Tight AWS integration, Origin Shield | 600+ PoPs |
| KeyCDN | Simple pricing, real-time analytics | 40+ PoPs |
Code Example — Serving via CDN
Without CDN (origin only)
<!-- Direct origin server — slow for global users -->
<script src="https://api.example.com/js/app.js"></script>With CDN
<!-- CDN-hosted — served from nearest edge -->
<script src="https://cdn.example.com/js/app.js"></script>
<!-- Or use a public CDN for popular libraries -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.3.1/umd/react.production.min.js"></script>Custom Domain with CDN (Cloudflare example)
# DNS setup — proxy through Cloudflare
example.com A 203.0.113.1 (proxied: orange cloud ☁️)
www.example.com CNAME example.com (proxied: orange cloud ☁️)Set Cache-Control headers on origin to control what the CDN caches:
// Express.js — CDN caching headers
app.get('/api/posts', (req, res) => {
res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
res.json(posts);
});s-maxage specifically tells CDNs how long to cache (vs max-age for browsers).
Common Use Cases
1. Media streaming
Netflix serves 15% of global internet traffic through its own CDN (Open Connect). YouTube, Twitch, and Spotify all rely on CDNs to stream video and audio.
2. E-commerce
Amazon, Shopify stores, and Alibaba use CDNs to deliver product images, JavaScript bundles, and checkout pages quickly — directly impacting conversion rates.
3. Software downloads
Microsoft distributes Windows updates. Steam delivers game installs. CDNs handle terabytes of downloads per second.
4. News and media websites
BBC, CNN, and The Guardian serve millions of daily readers from CDN edge servers to handle traffic spikes during breaking news.
5. Global SaaS applications
Slack, Notion, and Figma use CDNs to serve static assets (app bundles, images) quickly to users worldwide while API calls go to origin servers.
FAQ
Related Terms
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro