The feed problem
A social feed shows posts from everyone you follow. There are two ways to assemble it, and the choice shapes the whole system.
Fan out on write
When a user posts, the system pushes that post into the precomputed feed of every follower. Reading a feed is then a cheap lookup of an already built list.
- Fast reads, which is great because reads vastly outnumber writes.
- Expensive writes for users with millions of followers, a problem called the celebrity fan out.
Fan out on read
When a user posts, nothing special happens. At read time, the system pulls recent posts from everyone you follow and merges them on the fly.
- Cheap writes, since a post just gets stored once.
- Expensive reads, because every feed view does many queries and a merge.
The hybrid
Most large systems use a hybrid: fan out on write for ordinary users and fan out on read for celebrities, then blend the two at read time.
Key idea
Fan out on write trades costly writes for cheap reads, fan out on read does the reverse, and real systems blend both.