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.7 How do you solve the celebrity problem?
3 min read+10 XP
An account with 50 million followers posting once means 50 million feed writes. At 500,000 writes a second, that one post takes 100 seconds to reach everyone, and it competes with every other post's fan-out.
The fix:
- Keep a celebrity set: accounts above a follower threshold (say 1 million), recomputed regularly.
- Don't fan out their posts. Store them once.
- At read time, each user pulls recent posts from the few celebrities they follow (say 12 lookups), which are hot, shared and cacheable: every follower reads the same celebrity's latest posts, so they sit in memory.
Edge cases to mention:
- Someone becomes a celebrity overnight (a viral account): the threshold check runs often, and fan-out stops once they cross it; their already-pushed posts stay where they are.
- Mid-size accounts (100,000 followers) are pushed, but at lower priority so they don't block small accounts' posts.
Memory code: "Don't deliver to millions; let millions come and pick it up."