URL Shortener - Step 1: Scope & Requirements
Step 1 of 6: S - Scope & Requirements
Let's clarify what we're building before diving into design
📊 Decision 1: Scale First
100M URLs/day = 1,200 writes/sec
Peak: 3,600 writes/sec
⚡ Decision 2: Read Heavy
10:1 read/write ratio
Cache-friendly design needed
🎯 Decision 3: Simple MVP
Focus on core features first
Analytics can come later
🎙️ Interview Dialogue
Interviewer:
"Design a URL shortening service like bit.ly"
You (asking clarifying questions):
✅ "Should users be able to create custom aliases, or just random short codes?"
→ Start with random, custom aliases are nice-to-have
✅ "Do we need user accounts or is it anonymous?"
→ Anonymous for MVP, accounts later
✅ "What's our scale? How many URLs per day?"
→ 100 million shortenings per day
✅ "Read vs write ratio?"
→ 10:1 (10 reads for every write)
✅ "How long should URLs live? Forever?"
→ Default 10 years, configurable
✅ "Should we use 301 (permanent) or 302 (temporary) redirects?"
→ 302 for analytics tracking, 301 for performance
🔄Deep Dive: 301 vs 302 Redirects▼
✅ 302 Temporary Redirect
Best for URL shorteners:
- • Browser doesn't cache the redirect
- • Every click goes through our servers
- • We can track analytics for each click
- • Can change destination URL later
- • Search engines don't transfer ranking
❌ 301 Permanent Redirect
Problems for our use case:
- • Browser caches redirect permanently
- • Subsequent clicks bypass our servers
- • No analytics after first click per user
- • Can't change destination without cache issues
- • Search engines transfer ranking to destination
🎯 Decision: Use 302 redirects by default to preserve analytics capabilities. For high-traffic URLs where performance is critical, we could offer 301 as an option to reduce server load.
📋 Final Requirements Summary
Functional Requirements
- ✓Generate short URL from long URL (6-7 chars)
- ✓Redirect short URL to original (301/302)
- ✓URL expiration (default 10 years)
- ○Custom aliases (nice-to-have)
- ○Analytics & click tracking (phase 2)
Non-Functional Requirements
- 📊100M URL shortenings/day (1,200 QPS)
- 📖1B redirects/day (11,600 QPS)
- ⚡<100ms redirect latency (P99)
- 🎯99.9% availability (3 nines)
- 💾10 year data retention
💡 Key Takeaways
Scale Matters
1,200 writes/sec and 11,600 reads/sec drives our architecture
Read-Heavy System
10:1 ratio means caching is critical
Start Simple
MVP first, then add analytics and custom URLs