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
31.10 What would you say in the last five minutes?
3 min read+10 XP
Step 6: Wrap-up (5 minutes)
A strong close names the weak spots before the interviewer does:
- Bottleneck: the read path. Covered by Redis, replicas and an in-process cache for viral links.
- Single points of failure: the ticket server (blocks buffer it; run it redundantly), the primary database (failover to a replica).
- Abuse: rate-limit link creation per client (Chapter 25), and check new URLs against a malware list before saving them.
- Next with more time: link expiry with a cleanup job, custom aliases (a uniqueness check on the alias), and a second region for disaster recovery (Chapter 29).
Memory code: "Name the weak spots before they do."