Medium · 11 steps · ~55 min
Design a CDN
Serve the world from the edge and keep the origin calm.
A site serves images, scripts and video to users all over the world. The origin is in one region and slow for distant users, and it cannot handle viral traffic. Build a content delivery network that serves most requests from nearby caches and protects the origin.
Same problem as CloudflareAkamaiFastly
How it works
- Read: users fetch files, almost all repeats (read-heavy).
- Publish: owners upload new versions and purge old ones (rare writes).
- Miss: a cold file must be fetched from the origin once.
What you'll build
- The API and cache entry data
- A CDN in front of the origin
- A shield tier that merges edge misses
- Geo-routing capacity across the globe
- Designs that survive a cold cache, a lost edge and a lost origin server
Steps
- 1Design the API
- 2Design the data model
- 3Serve the first customers from the origin
- 4Take the load off the origin
- 5Fresh content and purge
- 6Add a second tier: the origin shield
- 7Go global: a million requests a second
- 8Survive a cold cache on the origin
- 9Lose a point of presence
- 10Lose an origin server
- 11Deep dive: the stampede