System Design
4 deep-dive scenarios · Step-by-step breakdowns · Architecture patterns
System Design Quiz
12 questions · 80% to pass
URL Shortener (Bit.ly)
Medium · 35-40 min
Functional Requirements
- ✓Given a long URL, generate a short URL (6-7 chars)
- ✓Given a short URL, redirect to the original URL
- ✓Support custom short URLs (optional)
- ✓Track analytics: clicks, geolocation, device
Non-Functional Requirements
- →100M URLs created/day, 10B redirects/day
- →Redirect latency < 10ms P99
- →High availability (99.99% uptime)
- →URLs should not be predictable (no sequential IDs)
Scale Estimates
- 100M writes/day = ~1,200 writes/sec
- 10B reads/day = ~115,000 reads/sec (100:1 read:write ratio)
- 500 bytes/URL × 100M/day × 365 days × 5 years = ~90TB storage
Define the contract before the architecture. Two endpoints: POST /shorten (body: {long_url, custom_alias?}) → {short_url}. GET /{short_code} → 301/302 redirect to long_url.
Key Decisions
- • 301 (permanent) vs 302 (temporary) redirect: 301 reduces load (browser caches), 302 allows accurate analytics tracking. Choose based on requirements.
- • Authentication: public API needs rate limiting; business API needs auth tokens
Key Components
Load Balancer
Distributes 115K req/sec across stateless app servers
ID Generation Service
Snowflake-style unique IDs without coordination
Redis Cache
80%+ cache hit rate makes redirect sub-millisecond
SQL Database (read replicas)
Persistent storage; read replicas handle read scale
Kafka + Analytics DB
Async click tracking without impacting redirect latency
CDN (optional)
Edge caching for 301 redirects reduces origin load globally
Trade-offs to Discuss
- • 301 vs 302: 301 is faster (browser caches), 302 gives better analytics
- • SQL vs NoSQL: SQL is simpler and sufficient; NoSQL if multi-region write scale needed
- • Hashing vs counter: hashing has collisions; counter requires central sequence generator
Expected Follow-up Questions
- • How would you handle URL expiration?
- • How do you prevent abuse (spam/malicious URLs)?
- • How would you design this for 10x the scale?
- • How do you handle custom domains (company.short.link)?