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.4 What do we store?
3 min read+10 XP
posts post_id (time-sortable ID, Chapter 10), author_id, text, media_ids, created_at
(a wide-column or sharded store, by post_id)
follows follower_id → followee_id (both directions indexed; sharded by user)
feed_cache user_id → list of post IDs, newest first, capped at 800 (Redis, sharded by user)
celebrities set of author IDs above the follower threshold
counts post_id → likes, comments (separate counters, updated asynchronously)
Interviewer pushback:
- "Why time-sortable post IDs?" → Feeds sort and paginate by recency; IDs that sort by time (like Snowflake IDs) make "newest first" and "after this ID" cheap without extra timestamps.
Memory code: "Posts once, follows both ways, feeds as lists of IDs."