Requirements
- Show a user the recent posts from everyone they follow, newest first.
- Posting and reading should both feel instant.
- Handle celebrities with millions of followers.
High level design
The core choice is fan out on write versus fan out on read.
- Fan out on write: when a user posts, push the post id into a precomputed feed list for each follower. Reads are then a cheap list fetch.
- Fan out on read: store posts once and gather them from followed accounts at read time. Writes are cheap but reads are heavy.
Most systems use a hybrid that fans out on write for normal users and pulls on read for the few accounts with huge follower counts.
Bottlenecks
- Celebrity fan out: pushing one post to millions of feeds is wasteful, so pull those posts at read time and merge them in.
- Feed storage: keep only recent post ids in a fast cache and page older content from the store.
- Ranking: a chronological feed is simple, but a ranked feed needs a scoring step that mixes recency, affinity, and engagement.
Key idea
A news feed trades work between write time and read time, and a hybrid fan out keeps both fast while handling the long tail of huge accounts.