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.1 What do you ask first?
3 min read+10 XP
Step 1: Requirements (5 minutes)
| Letter | Candidate asks | Interviewer answers |
|---|---|---|
| Scope | "Text, photos, videos? Likes and comments in the feed? Ranked or time order? Ads?" | "Text and photos (media stored elsewhere). Show like counts. Ranked, not just time order. Skip ads." |
| Count | "How many users, follows and posts?" | "200 million daily users. They follow about 200 accounts on average; some accounts have tens of millions of followers. About one post per user a day on average." |
| Access pattern | "How often do people open the feed?" | "About 10 times a day each." |
| Latency | "How fast must the feed load? How soon should a new post appear?" | "Under a few hundred ms. A new post should reach followers within seconds to a minute." |
| Exactness | "Must every post appear? In strict order?" | "Ranked, so not strict order. Missing a post from someone you follow is bad; slight delays are fine." |
Agreed requirements:
- Functional (verbs): users post; users follow others; the app shows a ranked feed of posts from followed accounts, paginated as they scroll; new posts appear within seconds to a minute.
- Non-functional (adjectives): feed loads fast (under ~300 ms), highly available, scales to celebrities with tens of millions of followers, eventually consistent (a short delay is fine), no repeats or gaps while scrolling.
Interviewer pushback:
- "Why does the celebrity detail change anything?" → Because the obvious design, copying each new post into every follower's feed, costs one write per follower. For an account with 50 million followers, that's 50 million writes for one post (37.7).
Memory code: "Ask about followers, posts, opens, and who has millions of fans."