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
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
| Strategy | Writes a second | Read lookups a second | Opening a feed | Celebrity post delay |
|---|---|---|---|---|
| 70k | 2.3k | 3 ms | 1.7 min | |
| 231 | 694k | 123 ms | none | |
| 47k | 14k | 5 ms | none |
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.
24 minDesigning INSTAGRAM: System Design of News Feed
Gaurav Sen · 763K views
Then
26 minDesign Twitter - System Design InterviewNeetCode · 676K views
31 minSystem Design Mock Interview: Design InstagramAced (formerly Exponent) · 564K views
27 minSystem Design: How to design Twitter? Interview question at Facebook, Google, MicrosoftSuccess in Tech · 543K views
37 minTwitter system design | twitter Software architecture | twitter interview questionsTech Dummies - Narendra Lakshmana Gowda · 366K views