| Scale | Users | Requests per Second (QPS) | Data Stored | Key Changes |
|---|---|---|---|---|
| Small | 100 users | ~10 QPS | ~10K URLs (~1MB) | Single server, single DB instance, simple hashing |
| Medium | 10,000 users | ~1,000 QPS | ~1M URLs (~100MB) | DB read replicas, caching hot URLs, load balancer |
| Large | 1,000,000 users | ~100,000 QPS | ~100M URLs (~10GB) | Sharded DB, distributed cache, CDN for redirects |
| Very Large | 100,000,000 users | ~10M QPS | ~10B URLs (~1TB+) | Multi-region sharding, global CDN, asynchronous writes, tiered storage |
First design walkthrough (URL shortener) in HLD - Scalability & System Analysis
At small to medium scale, the database is the first bottleneck. It handles all URL mappings and redirect lookups. As traffic grows, the DB CPU and I/O get overwhelmed by read and write queries.
At large scale, the application servers can become CPU-bound due to encoding/decoding URLs and handling many concurrent connections.
At very large scale, network bandwidth and data partitioning become critical challenges.
- Database: Add read replicas to distribute read load. Use connection pooling. Implement sharding by URL hash ranges to split data across servers.
- Caching: Use in-memory caches (like Redis) for popular URLs to reduce DB hits.
- Application Servers: Horizontally scale by adding more servers behind a load balancer.
- CDN: Use a Content Delivery Network to cache redirect responses globally, reducing latency and load.
- Storage: Archive old or rarely used URLs to cheaper storage tiers.
- Asynchronous Processing: Use queues for write-heavy operations to smooth spikes.
- At 1,000 QPS, DB needs to handle ~86 million requests per day.
- Each URL record ~100 bytes (short URL, original URL, metadata).
- 1 million URLs ~100 MB storage; 100 million URLs ~10 GB.
- Redirect responses are small (~100 bytes), so bandwidth at 100,000 QPS ~10 MB/s (800 Mbps).
- Network bandwidth and storage costs grow with scale; caching reduces DB and bandwidth load.
Start by clarifying requirements: expected traffic, URL length, expiration, analytics.
Discuss data model and how to generate unique short URLs.
Explain bottlenecks at different scales and propose solutions step-by-step.
Use real numbers to justify design choices.
Show awareness of trade-offs like consistency vs availability.
Your database handles 1,000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first and why?
Answer: Add read replicas and implement caching to reduce DB load, because the DB is the first bottleneck at this scale.
Practice
Solution
Step 1: Understand the function of a URL shortener
A URL shortener takes a long URL and creates a shorter alias that redirects to the original URL.Step 2: Identify the correct purpose among options
Only To convert long URLs into short, easy-to-share links describes this function correctly; others describe unrelated tasks.Final Answer:
To convert long URLs into short, easy-to-share links -> Option DQuick Check:
URL shortener purpose = convert long URLs to short [OK]
- Confusing URL shortening with security features
- Thinking it stores passwords
- Assuming it generates random data unrelated to URLs
Solution
Step 1: Identify the role of each component
Short code generator creates unique short strings; load balancer distributes traffic; cache stores data temporarily; authentication manages users.Step 2: Match component to short code creation
Only the short code generator is responsible for creating unique short URLs.Final Answer:
Short code generator -> Option CQuick Check:
Unique code creation = short code generator [OK]
- Confusing load balancer with code generation
- Thinking cache generates codes
- Assuming authentication creates short URLs
http://short.ly/abc123?Solution
Step 1: Understand the redirection process
When a short URL is accessed, the system finds the original URL mapped to the short code and redirects the user.Step 2: Evaluate each option
The system looks upabc123in storage and redirects to the original long URL correctly describes this lookup and redirect. Others describe incorrect or unrelated actions.Final Answer:
The system looks upabc123in storage and redirects to the original long URL -> Option AQuick Check:
Click short URL = lookup and redirect [OK]
- Thinking system creates new codes on click
- Assuming deletion happens on access
- Believing user must input original URL manually
Solution
Step 1: Understand duplicate short code impact
If duplicates exist, different long URLs share the same short code, causing wrong redirection.Step 2: Analyze options for relevance
Multiple long URLs map to the same short code causing incorrect redirects correctly identifies this problem. Others describe unrelated issues.Final Answer:
Multiple long URLs map to the same short code causing incorrect redirects -> Option BQuick Check:
Duplicate codes cause wrong redirects [OK]
- Confusing storage issues with duplicate codes
- Thinking duplicates affect user accounts
- Assuming cache hits cause this problem
Solution
Step 1: Identify scalability needs
Millions of users require fast access, high availability, and fault tolerance.Step 2: Evaluate design choices
Distributed storage spreads data load; caching speeds up lookups; load balancing distributes traffic. This combination supports scale.Step 3: Reject poor choices
Single server limits scale; sequential codes risk collisions; disabling cache slows response.Final Answer:
Use distributed storage with caching and load balancing -> Option AQuick Check:
Scaling needs distributed storage + cache + load balancer [OK]
- Choosing single server for large scale
- Ignoring caching benefits
- Using sequential codes risking collisions
Ready to prove it?
Pass the test and this pattern moves unknown
