Concept Simulators / Speed and waiting

News feed fan-out

Push, pull and hybrid feeds, and the celebrity problem.

On the roadmap:Interview Ready · step 3: Feeds, chat and notifications

Intermediateabout 10 to 15 min6 experiments
Experiments
New here? A few short steps show what happens, one at a time.

Settings

How a feed is built

When someone posts, the post is written into the feed of every follower. Opening a feed is one quick lookup. Posting is expensive for people with many followers.

Feed writes a second

70k

Lookups to read feeds a second

2.3k

Opening a feed

3.4 ms

Celebrity post reaches all

1.7 min

Pushing writes 70k feed entries a second, and a post from an account with 5.0M followers is a burst of 5.0M writes that takes 1.7 min to deliver. Opening a feed is just 1 lookup, about 3.4 ms.

The same load, three ways

StrategyWrites a secondRead lookups a secondOpening a feedCelebrity post delay
70k2.3k3 ms1.7 min
231694k123 msnone
47k14k5 msnone

Storage for push and hybrid is about 5.0B feed entries, at 500 recent posts per user. Pull needs none.

In plain words

A feed shows recent posts from the accounts you follow. It can be built when someone posts, by copying the post into every follower's feed (push), or when you open it, by fetching posts from everyone you follow (pull). Push makes reading cheap and posting costly. Pull is the reverse. Most large systems mix the two.

Why it matters

The shape of the follower graph decides the design: a post from an ordinary account reaches a few hundred people, and one from a celebrity reaches millions. Here you can change the numbers, see what each strategy costs in writes, reads and delay, and see why the celebrity case forces a hybrid.

How real systems do it

The simulation is a simplified model. Here is what production systems add or do.

  • Twitter has described building timelines by fan-out on write for most accounts, writing each tweet into followers' cached timelines, and handling accounts with very many followers separately, by merging their tweets in when a timeline is read.
  • A precomputed feed is usually a list of post IDs per user in a fast store such as Redis. The posts themselves are fetched by ID, so a feed entry is small.
  • The delivery delay for a push is the follower count divided by how fast the system can write. At 50,000 writes a second, five million followers takes 100 seconds, which is why celebrities are treated differently.
  • Real feeds are also ranked, not just sorted by time. The fan-out decides which posts are candidates, and a ranking model then orders them, often at read time.

Study: News feed fan-out

Once you have played with it, learn the same idea from people who build these systems. Watch first for the picture, then read for the detail.

Check yourself

1 of 4. What is the main cost of push (fan-out on write)?

Go deeper