37. Design a News Feed
1
The interview prompt2
37.1 What do you ask first?3
37.2 How big is this, really?4
37.3 What are the doors?5
37.4 What do we store?6
37.5 What does the whole system look like?7
37.6 Fan-out on write or on read?8
37.7 How do you solve the celebrity problem?9
37.8 How does ranking work?10
37.9 How do the feed cache and pagination work?11
37.10 What would you say in the last five minutes?12
Score yourself13
Variations to practise14
Sources15
Code lab37. Design a News Feed
37.6 Fan-out on write or on read?
3 min read+10 XP
Step 5: Deep dives (10 minutes)
Chapter 23 compared them; here are the numbers at full size:
| On write (push) | On read (pull) | |
|---|---|---|
| Cost per post | One write per follower: 40 billion a day | One write |
| Cost per feed load | One cache read | ~200 lookups and a merge: 14 million a second at peak |
| Freshness | Seconds to minutes (async) | Always fresh |
| Inactive users | Wasted writes (skip them) | No waste |
| Celebrities | 50 million writes per post | Fine |
Our pick: hybrid. Push for normal accounts (the vast majority of posts), skip inactive followers (halving writes to about 20 billion a day), and pull for celebrities at read time.
Memory code: "Push for most, pull for the giants, skip the sleepers."