A news feed that stays fast at 10 million users
A social app builds each feed when you open it. At 10 million users that is far too slow.
To design a news feed, choose between building feeds when posts are written, which gives fast reads and heavy writes, or when they are read, which is the reverse. Most designs push posts to ordinary followers' feeds, pull posts from very popular accounts at read time, and merge both.
The system today: A social app stores posts and follows in a SQL database. When someone opens the app, the server finds everyone they follow, fetches their recent posts and sorts them. That is fine for the first ten thousand users.
What has to change: The app now has 10 million daily users, some people follow thousands of accounts and a few accounts have millions of followers. Feeds must load in under half a second, and a new post should show up for followers within a few seconds. Design the feed.
Questions to ask first
- Is the feed chronological or ranked?
- How many posts should a feed hold, and how far back can a user scroll?
- How fresh must it be: seconds, or is a minute acceptable?
- Are there accounts with very large followings, and should they be treated differently?
Where the interviewer digs in
- Fan-out on write versus fan-out on read, and a hybrid for very popular accounts
- Storing precomputed feeds and trimming them
- Pagination that does not skip or repeat posts as new ones arrive
What a strong answer covers
- Names the core trade-off: precompute each follower's feed when a post is written (fast reads, heavy writes) or assemble it when read (cheap writes, slow reads).
- Proposes a hybrid: push to followers' feeds for ordinary accounts, pull at read time for accounts with huge followings, and merges the two.
- Stores feeds as bounded lists in a fast store, fed by a queue and workers so a post does not block on delivery.
- Uses cursor-based pagination and handles deleted or blocked posts when reading.
Common mistakes
- Fanning out a celebrity's post to millions of feeds synchronously.
- Offset pagination that shows duplicates when new posts arrive.
- Ignoring inactive users: precomputing feeds for people who never open the app wastes the most work.