← Lessons

quiz vs the machine

Gold1480

System Design

Fan Out On Write Versus Read

Two ways to build a feed and the cost tradeoff that picks between them.

6 min read · core · beat Gold to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the main benefit of fan out on write?

2. Why is fan out on write expensive for celebrities?

3. What does the common hybrid approach do?