31. Design a URL Shortener
1
The interview prompt2
31.1 What do you ask first?3
31.2 How big is this, really?4
31.3 What are the doors?5
31.4 What do we store?6
31.5 What does the whole system look like?7
31.6 How do you generate the short code?8
31.7 301 or 302?9
31.8 How do you keep redirects fast at 12,000 a second?10
31.9 How do you count clicks without slowing redirects?11
31.10 What would you say in the last five minutes?12
Score yourself13
Variations to practise14
Sources15
Code lab31. Design a URL Shortener
Sources
3 min read+10 XP
Source notes
- 301 (Moved Permanently) responses are cacheable by default; 302 (Found) only with explicit freshness information; 307 and 308 keep the request method: HTTP Semantics, RFC 9110, sections 15.4.2, 15.4.3, 15.4.8 and 15.4.9.
- All traffic numbers are interview assumptions agreed in Step 1, not figures for any real service.
- Arithmetic (62⁶ = 56,800,235,584; 62⁷ = 3,521,614,606,208; about 333 million redirects a day; about 33 GB of hot cache; 6 billion ÷ 62⁷ ≈ 0.17% clash chance per new random code at full size) computed 2026-10-05.
- ID blocks, scrambling and hash-with-retry code: tested 2026-10-05 (
code/ch31_url_shortener.py, all checks pass).