CDN (Content Delivery Network)
A global network of servers used to deliver content from a location closest to the user to reduce buffering
Overview
A Content Delivery Network (CDN) is a geographically distributed network of servers that cache and deliver content from locations closest to users. This dramatically reduces latency and server load.
CDNs are essential for serving static assets (images, videos, CSS, JavaScript) to global audiences efficiently.
Key Concepts
Edge Servers
Servers distributed globally at "edge" locations near users. Cache static content to serve it with minimal latency.
Origin Server
Your main server that holds the original content. CDN fetches from origin when cache is empty.
Cache Hit/Miss
Hit: Content found in CDN cache (fast). Miss: CDN must fetch from origin (slower first time, then cached).
TTL (Time To Live)
How long content stays cached before CDN checks for updates.
How It Works
Without CDN: User in Tokyo → Your server in US East Latency: ~150ms, load on your server
With CDN: User in Tokyo → CDN edge in Tokyo → (cache miss) → Your server in US East First request: ~150ms + processing Subsequent requests: ~10ms from Tokyo CDN
Cache Hit Flow:
- User requests image.jpg
- DNS routes to nearest CDN edge server
- Edge checks cache
- If cached, returns immediately
- If not, fetches from origin, caches, then returns
Use Cases
Streaming video (Netflix, YouTube)
Image-heavy websites (Instagram, Pinterest)
Software downloads (npm, GitHub)
Static website hosting
API acceleration
DDoS protection
Best Practices
Set appropriate cache TTLs based on content type
Use cache-busting for updated files (versioned URLs)
Compress assets before CDN delivery
Implement cache warming for critical content
Use multiple CDN providers for redundancy
Monitor cache hit ratios
Configure proper cache headers (Cache-Control)
Use CDN for static content only, not dynamic/personalized
Interview Tips
What Interviewers Look For
- •
Explain how CDNs reduce latency by serving from nearby locations
- •
Discuss cache hit vs cache miss performance difference
- •
Mention major CDN providers: Cloudflare, AWS CloudFront, Akamai, Fastly
- •
Talk about cache invalidation challenges: "There are only two hard things in computer science: cache invalidation and naming things"
- •
Explain TTL and cache-busting strategies
- •
Discuss CDN benefits beyond speed: DDoS protection, reduced origin load