SD Content Delivery Network CDN
A Content Delivery Network (CDN) is a geographically distributed group of servers that work together to deliver content to users as fast as possible. Instead of every user fetching content from one central server (which may be thousands of miles away), a CDN stores copies of content on servers placed strategically around the world, and serves each user from the closest location.
Imagine an online store with a warehouse in New York. A customer in Tokyo ordering a product has to wait for the package to travel from New York. A CDN is like setting up a local warehouse in Tokyo — the customer gets the same product, but much faster.
The Problem CDN Solves
Every millisecond of delay in a web page load costs conversions. Research shows a 100ms delay reduces conversion rates by 7%. For a global website, the problem is distance — physical distance between the user and the origin server adds measurable latency.
Without CDN: User in Mumbai → Request travels to New York server → Response travels back Latency: ~200ms (just network travel time) With CDN: User in Mumbai → Request goes to Mumbai CDN node → Response in ~10ms
How a CDN Works
ORIGIN SERVER (USA)
|
+----------+----------+
| | |
CDN Node CDN Node CDN Node
(Europe) (India) (Asia)
| | |
Users in Users in Users in
Europe India East Asia
- The website owner uploads content to the origin server.
- The CDN provider replicates this content to all edge nodes worldwide.
- When a user requests content, DNS routes the request to the nearest CDN edge node.
- If the edge node has the content cached, it serves it directly (cache HIT).
- If the content is not cached (cache MISS), the edge node fetches it from the origin server, caches it, and serves it to the user.
- All future requests from that region are served from the edge node cache.
Types of Content Delivered by CDN
Static Content
Static content does not change between users. It is ideal for CDN caching because one copy serves everyone.
- Images (product photos, logos, icons)
- CSS stylesheets
- JavaScript files
- HTML files that do not require personalization
- Videos and audio files
- PDF documents and fonts
Dynamic Content
Dynamic content changes per user (like a personalized dashboard or a shopping cart). CDNs traditionally struggled with this, but modern CDNs handle dynamic content through edge computing — running code at the CDN node itself instead of the origin server.
Example: Cloudflare Workers allows custom JavaScript to run at CDN edge nodes, so personalized responses generate close to the user.
CDN Caching and TTL
CDN edge nodes cache content for a defined period called TTL (Time To Live). When TTL expires, the edge node fetches a fresh copy from the origin server.
Content: product-image.jpg TTL set to: 24 hours Timeline: Hour 0 → User in India requests image → CDN fetches from origin → Caches for 24h Hour 1 → Another user requests same image → Served from CDN cache Hour 12 → 10,000 users request image → All served from CDN cache Hour 24 → TTL expires → Next request fetches fresh copy from origin
| Content Type | Recommended TTL | Reason |
|---|---|---|
| Logo / Brand images | 1 year | Rarely changes |
| JavaScript/CSS (versioned) | 1 year | Version in filename handles updates |
| Blog article images | 1 week | Changes occasionally |
| Product catalog images | 1 day | Updated regularly |
| News article thumbnails | 1 hour | Frequently updated |
| Live scores/prices | No cache | Must always be fresh |
Cache Busting in CDN
When a file changes (like a JavaScript update), the CDN might still serve the old cached version. Cache busting forces the CDN to recognize a file as new and fetch a fresh copy.
The standard approach is versioning — including a version number or hash in the file name:
Old: styles.css ← CDN caches this for 1 year New: styles.v2.css ← CDN treats this as a brand new file, caches fresh copy Or using a hash: Old: app.js ← old version New: app.a3f9b2.js ← hash changes when file changes → CDN fetches fresh
CDN and SSL/TLS
CDNs handle HTTPS termination at the edge node. The user's secure connection (HTTPS) terminates at the nearest CDN node. The connection between the CDN node and the origin server can also be encrypted.
User ←—HTTPS—→ CDN Edge Node ←—HTTPS—→ Origin Server Benefits: - SSL handshake happens at nearby CDN node (faster) - Origin server does not handle SSL for every user - CDN provider manages SSL certificates
CDN for Video Streaming
Video streaming is one of the most demanding use cases for CDN. A single high-definition video file can be gigabytes in size. Without CDN, streaming platforms could not function at scale.
Without CDN: Netflix origin server → 10 million users streaming simultaneously = 10 million concurrent connections to one server = Impossible With CDN: Netflix origin → CDN nodes worldwide Each CDN node serves users in its region = Millions distributed across thousands of servers = Smooth streaming globally
Video CDNs also use adaptive bitrate streaming — serving different video quality levels based on the user's network speed, all cached at edge nodes.
CDN Security Features
Modern CDNs do more than just speed up content delivery. They provide important security protections:
- DDoS Protection: CDN absorbs and filters massive attack traffic before it reaches the origin server. An attack sending 1Tbps of traffic gets distributed across thousands of edge nodes, each absorbing a fraction.
- Web Application Firewall (WAF): CDN edge nodes block malicious requests (SQL injection, XSS attacks) before they reach the origin.
- Bot Management: CDN identifies and blocks malicious bots while allowing legitimate bots (like search engine crawlers).
- Hotlink Protection: CDN prevents other websites from embedding and stealing bandwidth by serving images directly from the CDN URL.
Popular CDN Providers
| CDN Provider | Known For | Common Users |
|---|---|---|
| Cloudflare | Security + CDN combined, free tier available | Small to large websites |
| AWS CloudFront | Deep AWS integration | AWS-hosted applications |
| Akamai | Largest global edge network | Enterprise, media, banking |
| Fastly | Real-time cache purging, programmable | News sites, e-commerce |
| Google Cloud CDN | Google's global network backbone | GCP-hosted applications |
CDN vs Load Balancer
| Aspect | CDN | Load Balancer |
|---|---|---|
| Purpose | Cache and serve static content close to users | Distribute request load across servers |
| Location | Globally distributed edge nodes | Within a single data center or region |
| Content Type | Static files, media, cacheable content | All request types including dynamic |
| Caching | Core feature | Not typically a caching layer |
Summary
A CDN dramatically improves website speed, reliability, and security by serving content from geographically distributed edge nodes close to users. Static assets like images, JavaScript, and videos are ideal for CDN caching. TTL and cache busting ensure content stays fresh while maximizing cache usage. Modern CDNs also provide DDoS protection and edge computing capabilities, making them an essential component of any globally scaled system.
