Back-of-Envelope: Twitter Timeline Capacity
mediumCapacity estimation turns vague requirements ('design Twitter') into concrete numbers that constrain the rest of the design. The muscle to build is doing this in 3-5 minutes without a calculator. Twitter timeline is canonical because it covers all the levers.
Key Concepts
Approach
Step 1 — Users:
MAU = 300M, DAU = 150M, tweets/day = 2 ⇒ writes = 600M/day.
Per second avg ≈ 600M / 86,400 ≈ 7,000/s. Peak ≈ 35-70K/s.
Step 2 — Reads:
Each DAU opens 10× × sees 100 tweets ⇒ reads = 150B/day.
Per second ≈ 1.7M/s avg, 17M/s peak. Read:write 250:1.
Step 3 — Storage:
Tweet ~300 B ⇒ 180 GB/day raw text. 10 yr ≈ 657 TB ≈ 2 PB with 3x replica.
Media (20% of tweets, 200KB avg) ⇒ 24 TB/day media. Object store + CDN.
Step 4 — Fanout:
Avg 200 followers × 600M tweets = 120B timeline writes/day.
Per second ≈ 1.4M/s avg, 10M/s peak. Distribute across many fanout workers.
Step 5 — Cache:
Active users × 800 entries × 16 B ≈ 150M × 13KB ≈ 2 TB cache.
Sanity checks
- 17M/s reads ≫ any single node → CDN/cache layer mandatory.
- 120B fanout writes/day → workers, Kafka partitions sized accordingly.
- 2 PB / 100 TB per shard ≈ 20 shards minimum; in practice run 40-80 for headroom.
- Sanity: Twitter's published numbers (~500M tweets/day, 200M DAU) — our estimate within 20%.
- Media dominates storage by 100x; CDN cost will dominate text DB cost.
Common interview pattern
1. State assumptions explicitly: MAU, DAU%, activity, peak factor.
2. Compute writes/s and reads/s with arithmetic.
3. Compute storage/day → /year → with replication.
4. Derive: cache size, shard count, Kafka partitions, fleet size.
5. Verify: is any number absurd? Adjust and explain.
6. State the dominant cost: 'Read caching + CDN for media is 80% of cost.'
Keep numbers round; don't pretend precision.
Capacity → infrastructure
Writes/s ÷ writes/s/node = shard count.
Reads/s ÷ reads/s/node = read replicas needed.
Storage / per-shard cap = additional shards for storage.
Fanout writes/s ÷ fanout-worker rate = worker count.
Cache size / per-node RAM = cache nodes.
Network egress (media) → CDN PoP count + per-PoP capacity.
Adjusting for hot users
Power-law follower distribution.
Average 200 followers, median ~25, top users >10M.
Fanout cost: dominated by top 0.01%.
Mitigate: hybrid push (normal) + pull (celebrity) — see ID 170.
Capacity model must account: 80% of users contribute 20% of fanout writes; top 0.01% contribute 50%.