Easy · 12 steps · ~60 min
Design a link shortener
Billions of redirects, a few writes, and short codes that never collide.
A link shortener turns a long address into a short code, then sends anyone who opens the code to the original page. Creating links is rare; opening them is constant.
Same problem as BitlyTinyURLt.co
How it works
- Shorten: the server stores code → long URL in a database.
- Open: the server looks the code up and replies with a redirect.
What you'll build
- The API and the data behind it
- A system that answers 500 requests a second
- A cache, replicas and a load balancer for 50,000
- A rate limiter that stops a scraper
- A design that survives a cache restart, a lost server and a lost primary
Steps
- 1Design the API
- 2Design the data model
- 3Handle 500 requests/sec
- 4Handle 15,000 requests/sec for $1,000 a month
- 5Handle 50,000 requests/sec
- 6Handle 50,000 requests/sec for $1,700 a month
- 7Survive a scraper on the same budget
- 8Survive a cache restart
- 9Lose an API server
- 10Lose the primary database
- 11New links 404 for their creators
- 12Deep dive: generating short codes