Real-World Designs · 10 min read · Intermediate
Case Study: Design a URL Shortener
Walk through a complete system design: API contracts, Base62 ID encoding, cache-first redirects, and async click analytics.
What you'll learn
- Design POST /shorten and GET /:code with 301 vs 302 trade-offs
- Generate collision-free Base62 short codes
- Cache hot links in Redis for sub-5ms redirect latency
Overview
Walk through a complete system design: API contracts, Base62 ID encoding, cache-first redirects, and async click analytics.
Great system design is about explicit trade-offs rather than memorizing buzzwords. Every architectural layer you add (caches, replicas, queues, shards) solves one bottleneck while introducing new operational failure modes.
Design Checklist
| Dimension | Questions to Ask |
|---|---|
| Traffic & Scale | What is the read-to-write ratio, peak QPS, and payload size? |
| Consistency | Can users tolerate eventual consistency for a few seconds, or do we need strict ACID? |
| Failure Modes | What happens if a cache node, replica, or downstream API times out? |
| Simplicity | Can a single well-indexed PostgreSQL instance handle the next 12 months of growth? |
Key Takeaways
- Design POST /shorten and GET /:code with 301 vs 302 trade-offs
- Generate collision-free Base62 short codes
- Cache hot links in Redis for sub-5ms redirect latency
Quick Check
Check Your Understanding
Score: 0 / 1
1. Why do URL shorteners that track click analytics typically return HTTP 302 (Temporary Redirect) instead of 301 (Permanent)?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.