Design a service like a link shortener. Users submit a long URL and receive a short code. Anyone opening the short link is redirected to the original URL. Reads vastly outnumber writes, and a code must never resolve to the wrong destination.
Functional requirements
Create a short code for a long URL
Redirect a short code to its original URL
Optionally expire links
Count clicks per link
Non-functional requirements
Redirect p99 latency under 120 ms
99.9% availability for redirects
Codes are unique and never reused for a different URL
Constraints and scale
100 million new links per month
100:1 read-to-write ratio
Links are kept for 5 years
You will practise
Estimate QPS and storage
Place a cache on a read-heavy path
Generate unique IDs across instances
Show 3 hints
Work out write QPS first: 100M / (30 × 86 400)
How would three API instances avoid issuing the same code?
Click counting does not need to be on the redirect path