Caching & PerformanceIntermediate~60 min

Design a CDN

Design a content delivery network that caches and serves static and dynamic content from edge locations worldwide. Consider cache invalidation strategies, origin shielding, and geographic routing.

You'll practice

cachingnetworking

Functional Requirements

  • Cache and serve static content from edge locations
  • Invalidate or purge cached content
  • Route users to the nearest edge server

Non-Functional Requirements

  • Sub-50ms latency for cached content globally
  • 99.99% availability across edge locations
  • Scale to 1M+ requests per second

Frequently Asked Questions

What is a CDN and how does it work?

A Content Delivery Network is a distributed network of servers (edge locations) that cache and serve content closer to end users. When a user requests content, the CDN routes them to the nearest edge server, reducing latency and offloading traffic from the origin server.

What is cache invalidation and why is it hard?

Cache invalidation is the process of removing or updating stale content from edge caches. It is challenging because changes at the origin need to propagate to hundreds of edge servers worldwide, and you must balance freshness (serving updated content) against performance (avoiding unnecessary cache misses).

What is origin shielding?

Origin shielding adds an intermediate cache layer between edge servers and the origin. Instead of every edge server fetching directly from the origin on a cache miss, they fetch from the shield server first. This dramatically reduces load on the origin during cache stampedes or cold starts.

How does a CDN handle dynamic content?

For dynamic content, CDNs use techniques like edge computing (running logic at edge locations), short TTLs with stale-while-revalidate, and connection optimization (persistent connections to origin, TCP/TLS optimizations). Some CDNs also support ESI (Edge Side Includes) to cache parts of dynamic pages.

Ready to design this system?