Design a URL shortener
A public link shortener handling 100M new links per month with a 100:1 read-to-write ratio and redirects under 50 ms at p99.
1. Requirements
- Create a short link from a long URL; optional custom alias and expiry.
- Redirect short link to the long URL (HTTP 301/302).
- p99 redirect latency under 50 ms; 99.99% redirect availability.
- Links are never reassigned; abuse (phishing) links can be disabled.
2. Capacity math
Writes
~40 / s
100M links / (30 × 86,400 s) ≈ 39 writes/s
Reads
~4,000 / s
100:1 read ratio → ~3,900 redirects/s, peak ×3 ≈ 12k/s
Storage (5 yrs)
~3 TB
6B links × ~500 bytes ≈ 3 TB
Key space
7 chars
62^7 ≈ 3.5 trillion ≫ 6B links
3. Architecture
Rendering…
4. Decisions and rejected alternatives
Chosen Pre-allocated key ranges per API node (base62 counter)
Rejected Hashing the long URL (MD5 + truncate)
Hashing needs collision checks on every write; ranges give guaranteed-unique keys with no coordination on the hot path.
Chosen Key-value store (e.g. DynamoDB / Cassandra)
Rejected Single relational database
Access is purely by key and grows to billions of rows; horizontal partitioning is simpler than sharding SQL.
Chosen 302 redirect with cache headers
Rejected 301 permanent redirect
301s are cached by browsers forever, which breaks click analytics and link disabling.
5. Failure modes
- Cache cluster lost: Reads fall through to the store; store is sized for 3× normal read load for 15 minutes.
- Key allocator down: Each API node holds a buffered range of 10k keys, so writes continue for hours.
- Hot link (viral): CDN caches redirects at the edge for 60 s.
6. Scaling triggers
- Over 20k redirects/s: add edge caching of redirects.
- Over 10 TB: move cold links (no clicks in 1 year) to cheaper storage.
Want one for your own system? Access is by approval, free during beta.
Join the waitlist