URL Shortener Cheat Sheet
Key concepts, trade-offs, and quick-reference notes for your interview prep.
QPS Estimation
#1💡 Always clarify the read:write ratio first. URL shorteners are extremely read-heavy (100:1 is standard).
Storage Estimation (5 years)
#2💡 Each URL record is ~500 bytes (short code + original URL + metadata). 30 billion URLs over 5 years.
Base62 Key Space
#3💡 62 = [a-zA-Z0-9]. 7 characters gives 3.5 trillion unique short codes, enough for decades.
Cache Hit Ratio
#4💡 Popular URLs follow a Zipf distribution. 20% of URLs get 80% of traffic. Cache those aggressively.
Database Schema
#5💡 short_code as primary key means every redirect is a single PK lookup - O(1) in any database.
API Endpoints
#6💡 Keep the read path (GET /:code) as fast as possible. It handles 100x more traffic than writes.
Redirect Flow
#7💡 Cache hit skips the DB entirely. Cache miss path: read from DB, write to cache, then redirect.
Scaling Thresholds
#8💡 Start simple (single server + cache). Only add complexity (sharding, replication) when you hit limits.
301 vs 302 Redirect
#9💡 Use 301 for maximum performance (browser skips your server). Use 302 if you need click analytics.
Key Length Trade-off
#10💡 More characters = more capacity but longer URLs. 7 is the sweet spot for most systems.