PerformanceContent Delivery Networks

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.

What is a CDN?

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

What CDNs Cache

Static Assets (ideal for CDN)

  • Images, videos, audio
  • JavaScript bundles and CSS files
  • HTML pages (for static sites)
  • Software downloads, PDFs

Dynamic Content (possible but complex)

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.

How CDN Caching Works

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 hours
  • Cache-Control: no-cache — Always revalidate with origin
  • Cache-Control: public — Can be cached by CDN
  • Cache-Control: private — Only cache in browser, not CDN
  • ETag and Last-Modified — For conditional requests

CDN Benefits

  1. Lower latency: Serve from the nearest edge, not across the world
  2. Reduced origin load: Your servers only handle cache misses
  3. Traffic spike absorption: CDNs can handle massive traffic bursts (viral content, product launches)
  4. DDoS mitigation: Many CDNs have built-in DDoS protection
  5. Better availability: If your origin goes down, the CDN may still serve cached content

Cache Invalidation on CDNs

Updating cached content is the hardest part of CDN management.

Content-Addressed URLs (Best Practice)

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.

API Invalidation

Most CDN providers expose an API to purge specific URLs or cache tags. Use this when you need to immediately update content.

Short TTLs

For semi-dynamic content, use shorter TTLs (5–60 minutes) to limit staleness without full invalidation complexity.

CDN Architecture Patterns

Pull CDN

The CDN fetches content from your origin on the first cache miss and caches it automatically. Simple to set up.

Push CDN

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.

Popular CDN Providers

| 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 |

Interview Tips

  • CDNs come up in almost every system design that serves global users or media. Mention them early
  • Know that CDNs primarily help with static content and latency — they don't solve database scaling
  • Discuss cache invalidation strategy for content updates (immutable URLs with hashes is the gold standard)
  • For video streaming (YouTube/Netflix), mention that CDNs are the core delivery mechanism, often storing popular videos on thousands of edge nodes