system-design pattern
URL Shortener Design
Classic system design case study. Learn to handle billions of URLs with high availability and low latency.
Time
O(1) for both shorten and redirect
Space
O(n) where n = number of URLs
🧠Mental Model
“A library card catalog - short code maps to full book location. Need to generate unique codes and retrieve them fast.”
Verbal cue: Generate unique short ID, store mapping, redirect quickly.
🎯Recognition Triggers
When you see these patterns in a problem, consider this approach:
shorten URLtiny URLbit.lyredirect service
💡Interview Tips
- 17-character base62 gives 3.5 trillion unique codes
- 2Discuss both random vs sequential ID generation trade-offs
- 3Mention 301 (permanent) vs 302 (temporary) redirect implications
⚠️Common Mistakes
- ✕Not handling collision in ID generation
- ✕Forgetting about custom short codes
- ✕Not discussing cache invalidation for analytics