System Design Lab›System Design Questions›Design CDN (Content Delivery Network)
Design CDN (Content Delivery Network)
MediumInfrastructurecdncachingdistributedsecurity
Question Overview
Design a global content delivery network that serves customers' content from edge locations near their users. You will need to cover anycast versus DNS routing, cache hierarchies and origin shielding, cache key design, and purging content worldwide within seconds.…
Sign up to see the full question and AI interviewer
Requirements
- Route each user to a nearby, healthy PoP and serve cache hits with under 50 ms time to first byte
- Fetch misses from the origin, honoring Cache-Control, per-rule TTLs, and configurable cache keys
- Purge by URL, prefix, or tag, taking effect globally within 10 seconds
- HTTPS for 100K customer domains using customer-provided or managed certificates
- Survive the loss of a PoP, keep origin offload above 95%, and serve stale content when the origin is down
- Per-customer request logs and cache-hit analytics
Back-of-the-envelope numbers
- Egress: 10M RPS × 250 KB average response = 2.5 TB/s ≈ 20 Tbps at global peak
- Per PoP: 10M RPS ÷ 200 PoPs = 50K RPS and 100 Gbps on average, with large metro PoPs carrying 5-10× that
- Servers: at ~20 Gbps of TLS egress per server, 20 Tbps ÷ 20 Gbps = 1,000 servers minimum, ~2,000+ with headroom and N+1 per PoP
- Cache capacity: a large PoP with 50 servers × 20 TB SSD ≈ 1 PB holds ~10% of the 10 PB corpus, enough for most requests under Zipf popularity
- Origin offload: 90% edge hit ratio → 1M RPS to the regional tier; 90% hits there → 100K RPS (1%) reaches origins across 100K domains
- Purge fan-out: 10K purges/min × 200 PoPs = 2M PoP-level messages/min ≈ 33K/s, distributed through a pub/sub tree
- Logs: 10M RPS × ~300 B ≈ 3 GB/s at peak, aggregated or sampled at the edge before shipping to analytics
Key components
- Request routing: anycast announces the same IPs from every PoP over BGP, while GeoDNS picks a PoP per resolver location; withdrawing routes drains a PoP
- In-PoP load balancing: ECMP to L4 balancers, then consistent hashing on the cache key so each object is stored once per PoP
- Edge cache: RAM for the hottest objects and SSD for the rest, with an admission filter so one-hit wonders do not evict popular content
- Tiered caching and origin shield: edge misses go to a regional parent or designated shield PoP, so origins see about one fetch per object per tier
- Request collapsing: concurrent misses for the same key wait on a single origin fetch instead of stampeding the origin
- Freshness and purge: max-age, s-maxage, stale-while-revalidate, and stale-if-error, plus purges fanned out over pub/sub that bump per-tag generations
- Control plane: customer configs and certificates distributed to every PoP, with TLS 1.3 and session resumption at the edge
Common mistakes
- Treating each edge server as an independent cache, duplicating hot objects on every server and shrinking effective PoP capacity
- Having no request collapsing, so when a hot object expires thousands of simultaneous misses hit the origin
- Including every query parameter and cookie in the cache key, fragmenting the cache until the hit ratio collapses
- Ignoring Vary and private responses, serving the wrong encoding or one user's personalized page to another user
- Relying on short DNS TTLs for instant failover, even though many resolvers cache records longer than asked
- Implementing prefix purge by scanning cached keys on every server rather than using tag indexes or generation counters
Likely follow-ups
- How would you serve a live sports stream to 20M concurrent viewers?
- How would you absorb a 1 Tbps DDoS attack on one customer without hurting others?
- How would you choose which PoP acts as the origin shield for a given customer?
- How would you handle TLS for customers who refuse to share their private keys?
- How would you safely run customer code at the edge?
- How would you decide what to cache when a PoP's disks hold only 10% of the content?
No community solutions yet
Be the first to publish your solution
Practice ‘Design CDN (Content Delivery Network)’ with an AI Interviewer
Get scored feedback on your diagram, scalability approach, and trade-offs. Free while we grow — up to 3 full interviews a day.