Design a news feed (Twitter)
Deliver each of 300M users a timeline of recent posts from everyone they follow, instantly — including celebrities with 100M followers.
Open the interactive version → diagrams, practice & moreThe problem
Deliver each of 300M users a timeline of recent posts from everyone they follow, instantly — including celebrities with 100M followers.
The idea
Precompute timelines via fan-out, with a hybrid approach for celebrities.
How it works
On a new post, fan-out-on-write pushes it into followers' cached timelines (fast reads). For mega-accounts that's too expensive, so fan-out-on-read pulls their posts at view time (hybrid). Tweets/graph in NoSQL, timelines in cache, media in object store + CDN, search alongside.
The tradeoff
Fan-out-on-write = fast reads, expensive writes; fan-out-on-read = cheap writes, slow reads. The hybrid balances both.
In the wild
Twitter's timeline architecture is the canonical example of this tradeoff.
Interview deep dive
Flow
- User posts; write tweet to durable storage.
- Fan-out worker pushes tweet IDs into normal followers' timelines.
- Celebrity posts stay in author storage and merge on read.
- Timeline read hydrates IDs, ranks, and fetches media through CDN.
Watch for
- The celebrity problem is a write-amplification problem.
- Timeline cache stores IDs, not full post blobs.
- Backfill and ranking must tolerate partial freshness.
Interviewer trap
State the hybrid threshold and what metric would make you change it.