MongoDB
Designing a URL Shortener at Scale
A deep dive into designing a production-ready URL shortener like bit.ly, covering hashing, redirection, and analytics.
S
srikanthtelkalapally888@gmail.com
Designing a URL Shortener at Scale
A URL shortener converts long URLs into short aliases and redirects users when accessed.
Functional Requirements
- Create a short URL from a long URL
- Redirect short URL to original
- Support custom aliases
- Track click analytics
Non-Functional Requirements
- 100M URLs generated per day
- Low latency reads (<10ms)
- High availability (99.99%)
Key Design Decisions
URL Encoding
Use Base62 encoding (a-z, A-Z, 0-9) to generate 7-character short codes.
62^7 = ~3.5 trillion unique URLs
Database Choice
- Write: Use a NoSQL store like Cassandra for high write throughput
- Read: Cache hot URLs in Redis (80% of traffic hits 20% of URLs)
Architecture
Client → Load Balancer → App Servers
↓
Redis Cache
↓
Cassandra
Redirection Flow
- Client hits short URL
- Check Redis cache
- If miss, query Cassandra
- Store in cache, redirect
Analytics
Use Kafka to stream click events asynchronously to an analytics pipeline.
Conclusion
A well-designed URL shortener handles billions of redirects with sub-10ms latency using caching and distributed storage.