The problem
Your home timeline is the merge of tweets from everyone you follow, newest first. Computing this on every load means scanning thousands of authors — far too slow at read time when reads vastly outnumber writes.
Fan-out on write
Twitter flips the cost to write time. When you tweet, the system fans out the tweet id into the precomputed timeline cache of each follower. Reading a timeline then becomes a single cheap lookup.
- Fan-out on write pushes each tweet into follower inboxes
- Fan-out on read merges author timelines only when you open the app
- Most users get fan-out on write for fast reads
The celebrity problem
A user with millions of followers would trigger millions of writes per tweet. So Twitter uses a hybrid: celebrity tweets are fetched at read time and merged into your precomputed list, avoiding write amplification.
The lesson is that read and write costs trade off, and you place work where traffic is cheapest.
Key idea
Precompute timelines on write for the common case, but fall back to read time merging for celebrities to dodge write amplification.