A CDN is a globally distributed network of servers that caches content close to users. It's the primary tool for reducing latency and handling traffic spikes for static assets and media.
A Content Delivery Network (CDN) is a geographically distributed network of edge servers (also called Points of Presence, or PoPs) that cache copies of your content. When a user requests a file, the CDN serves it from the nearest edge location instead of your origin server.
Without CDN: User in Tokyo → Origin server in Virginia → 200ms round-trip latency With CDN: User in Tokyo → Edge server in Tokyo → 10ms round-trip latency
Modern CDNs like Cloudflare Workers and AWS CloudFront Functions can also handle dynamic requests at the edge — executing logic before the request ever reaches your origin.
User Request → CDN Edge (Cache HIT?)
YES → Serve from edge cache
NO → Fetch from origin → Cache at edge → Serve to user
CDNs respect standard HTTP cache headers:
Cache-Control: max-age=86400 — Cache for 24 hoursCache-Control: no-cache — Always revalidate with originCache-Control: public — Can be cached by CDNCache-Control: private — Only cache in browser, not CDNETag and Last-Modified — For conditional requestsUpdating cached content is the hardest part of CDN management.
Include a hash of the file content in the filename:
bundle.abc123.js
style.def456.css
When the file changes, the filename changes — no cache invalidation needed. Old URLs simply expire.
Most CDN providers expose an API to purge specific URLs or cache tags. Use this when you need to immediately update content.
For semi-dynamic content, use shorter TTLs (5–60 minutes) to limit staleness without full invalidation complexity.
The CDN fetches content from your origin on the first cache miss and caches it automatically. Simple to set up.
You explicitly upload content to the CDN (e.g., via API or CLI). You control exactly what's cached. Common for large files like video.
| Provider | Known For | |---|---| | Cloudflare | Free tier, security features, edge compute | | AWS CloudFront | Deep AWS integration | | Fastly | Developer-friendly, real-time purging | | Akamai | Enterprise, largest network | | Vercel Edge Network | Next.js/Vercel-optimized |