Design a URL Shortener
System Design Cases: lesson 1 of 20
One tiny key, a hundred million long links behind it.
Lesson 1 of 20 · 6 min
Design a URL Shortener
Step 1 of 11
A hundred million links, and 500 reads for every 5 writes. The read path is the design.
The Idea
Take a long URL, hand back a short key, and redirect every later hit on that key. Assume 100 million links and 500 redirects a second against 5 writes — read-heavy, and every read is one exact-key lookup.
Real-World Example
A cloakroom ticket. The number you are given says nothing about your coat; the desk's ledger is the only thing that connects the two, and it is read far more often than it is written.
The Tradeoff
A base62 counter gives the shortest collision-free keys and leaks how many links exist, because one shared sequence hands them out in order. Random keys hide that and need a uniqueness check on every write. Redirect with 302: a 301 is cached by the browser forever, and your click counts stop arriving.
Your turn
Put the steps in the right order.
- Answer with 302 to the long URL and publish a click event
- Generate a short key and confirm no row already holds it
- On a redirect, read the cache first and fall back to the store
- Write key to long URL, then return the short link
Mini quiz
1 / 3