Design a URL Shortener
Design a URL shortening service like bit.ly that takes long URLs and creates short, unique aliases. The system should handle high read throughput with low-latency redirects. Aim for 100M URLs created per month with a 100:1 read-to-write ratio.
How the interview goes
Five phases, and questions the interviewer is likely to ask in each.
1. Requirements
- What's the expected read:write ratio?
- Do we need real-time analytics or is eventual consistency acceptable?
- Should short URLs be predictable or random?
Show a hintHint
Think about the read:write ratio — URL shorteners are read-heavy.
2. High-level design
- What happens if your ID generator goes down?
- Why did you choose that database type?
- Where does caching fit in your architecture?
Show a hintHint
Consider where caching fits in the redirect path.
3. Deep dive
- How do you handle hash collisions?
- What's your cache eviction strategy?
- How do you handle link expiration at scale?
Show a hintHint
Look into Snowflake IDs or base62 encoding for distributed unique ID generation.
4. Scaling
- How would you shard the database?
- What happens when a single URL goes viral?
- How do you handle geographic distribution?
Show a hintHint
Database sharding by short_code hash is a common approach.
5. Trade-offs
- What would you change if consistency mattered more than availability?
- How would the design differ if you needed sub-10ms redirect latency globally?
Show a hintHint
301 (permanent) vs 302 (temporary) redirects have caching implications for analytics.
Practice this with an AI interviewer
Write your design doc with live diagrams while the interviewer asks one question at a time and pushes on your choices. Get a scored debrief with what to study next.
Start this interview