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
Score yourself
3 min read+10 XP
Score yourself
Give yourself 0, 1 or 2 points per row.
| Area | 0 points | 1 point | 2 points |
|---|---|---|---|
| Requirements | Started drawing | Post, follow, feed | Ranking, celebrities, freshness and no-repeat scrolling agreed |
| Estimates | None | Numbers, not used later | Fan-out write volume and celebrity cost drove the design |
| API and data | Skipped | API or tables | Feed API with cursor; posts, follows, feed cache of IDs |
| High-level design | One query per feed | Push or pull only | Hybrid, inactive skipping, celebrity pull, ranking and hydration walked |
| Deep dive | Hand-waved | One topic | Celebrity problem, ranking pipeline or snapshot pagination with numbers |
| Trade-offs | None named | Named when asked | Raised unprompted (freshness vs cost, threshold, cache size) |
| Communication | Long silences | Mostly clear | Thought out loud, checked in, managed time |
12 to 14: strong hire signal. 8 to 11: solid, polish the weak rows. Under 8: redo the round in a week, timer on.
The bar: fresher vs SDE-2
| Fresher | SDE-2 | |
|---|---|---|
| Fan-out | Push or pull | Hybrid with threshold, inactive skipping, backfill on follow |
| Data | Feed table of posts | Feed cache of IDs, time-sortable IDs, hydration |
| Ranking | Newest first | Candidates → score → rules → hydrate |
| Pagination | Offset | Session snapshot with cursor, "new posts" banner |
| Failure | Not mentioned | Rebuild feeds by pulling; cache shard loss handled |
Common mistakes
- Pure fan-out on write, with no plan for accounts with millions of followers.
- Storing full posts in every feed instead of IDs.
- Joining follows and posts in SQL on every feed load.
- Offset pagination over a ranked, changing feed.
- Fanning out to users who haven't opened the app in months.
Quick check
Five questions on this chapter. Pick an answer, then check it.
quiz