Design a URL Shortener
Quick Overview
Design a URL shortening service like bit.ly. Cover hash generation strategies, database design for billions of URLs, redirect latency optimization, analytics tracking, and handling collisions.
Meta
0
Design a URL shortening service like bit.ly. Cover hash generation strategies, database design for billions of URLs, redirect latency optimization, analytics tracking, and handling collisions.
Meta uses this in system design rounds as a warm, well-scoped problem, relevant to link sharing across Facebook, Instagram, and Messenger. The interviewer checks key generation without collisions, a read-heavy storage and caching design, low redirect latency, and an analytics path that stays off the critical path.
What the Interviewer Expects
- Clarify read-to-write ratio, URL lifetime, and custom alias needs
- Estimate storage and QPS for billions of URLs
- Compare key generation options such as hashing, counters, and base-62 encoding
- Design caching and storage for fast redirects
- Keep click analytics asynchronous so redirects stay fast
Key Topics to Cover
How to Approach This
- Start by clarifying functional and non-functional requirements with the interviewer.
- Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
- Draw a high-level architecture first, then deep dive into 1-2 critical components.
- Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
- Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
- How do you generate unique IDs across many servers without coordination?
- 301 or 302 redirects, and how does that choice affect analytics?
- How would you detect and block malicious or spam URLs?
- How do you handle a single link going viral?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Functional Requirements:
- URL Shortening: Generate a short URL from a long URL.
- Redirecting: Users should be redirected to the original URL when accessing the short URL.
- **Analytic...
Capacity Estimation
Assuming the service is designed for Meta, let's estimate the scale:
- Daily New URLs: Assume 10 million new URLs created per day.
- Total URLs: In one year, this would lead to approximately 3...