URL Shortener
Design a URL shortener like bit.ly supporting 100M new URLs/month and low-latency redirects.
Answers use simple, clear English.
Audio N/AQuick interview answer
API: create(longUrl)->shortCode, redirect(shortCode)->302 longUrl. Generate unique codes via base62 counter, hash+collision retry, or pre-generated keys. Store mapping in KV/SQL with cache (Redis).
Detailed answer
API: create(longUrl)->shortCode, redirect(shortCode)->302 longUrl. Generate unique codes via base62 counter, hash+collision retry, or pre-generated keys. Store mapping in KV/SQL with cache (Redis). Separate write and read paths; cache hot redirects; analytics via async events. Consider custom aliases, TTL, and abuse detection. Interview expects capacity estimates, ID generation trade-offs, caching, DB choice, and redirect SLA. For 11+ YOE, discuss multi-region, consistency of analytics, and key exhaustion.
Full explanation
Interview expects capacity estimates, ID generation trade-offs, caching, DB choice, and redirect SLA. For 11+ YOE, discuss multi-region, consistency of analytics, and key exhaustion.
Common mistakes
Only talking about hashing; ignoring hot-key cache; no capacity math.
Best practices
State assumptions, draw API + data model + scale path, call out trade-offs.
Follow-up questions
- How do you avoid predicting sequential IDs?
- How would you design multi-region active-active?