Project 02
URL shortener
Hashing, caching, read-heavy load
Brief
Shorten long URLs to compact codes; redirect fast; per-user link management; click counts; optional expiry and custom aliases.
Targets
100M stored URLs · 10k redirects/sec peak, 100:1 read/write · redirect p99 < 50 ms · 99.95% availability.
Must cover
- Collision handling in key generation (→ 75).
- Abuse limits — per-user and per-IP creation limits (→ 96).
- Redirect status codes — 301 vs. 302 and the analytics consequence (→ 28).
- Malicious-URL checks — blocklist screening and reporting path (P).
Design challenges
- Key generation (→ 75): counter + base62 vs. hash-and-truncate vs. pre-generated key pool — compare collision handling, predictability, and code length.
- Read path (→ 83): cache-aside with Redis; reason about hit ratio from the access distribution; defend the viral-link case against stampede and hot keys (→ 88).
- Click counting without slowing redirects — asynchronous increment (→ 105–106 — ahead, Part 7).
- Honest capacity estimate (→ 20): storage for 100M rows; cache memory for the hot set.
Out of scope
Sharding. Estimate first — one well-indexed database likely suffices at these numbers; prove it in step 6 and record the simpler option in step 21.