Design a news feed like Facebook's
hard 50 minShow each person the best recent posts from everyone they follow, in a fifth of a second.
How to approach it
What this question tests, where it gets hard, and how to spend the time.
Read the question
What this problem tests
Can you place the work?
Write time or read time. Interviewers want two numbers compared, not a slogan.
Do you see the uneven part?
The average has 500 followers. A few have 100 million. One design cannot serve both.
Do you count the hidden reads?
Twenty posts on a page means twenty lookups. That is larger than the feed traffic.
Do you protect people?
Blocks, deletions and audience changes must beat every cached copy.
Think
Five questions before you draw
| Ask yourself | Here |
|---|---|
| Who does what? | A person posts; hundreds of others open their feeds later, at different times |
| What must never go wrong? | Showing a post to someone who may not see it; an empty feed |
| What is the hardest thing? | Fan-out when follower counts differ by a factor of a million |
| What breaks first as it grows? | Gathering from 500 accounts on each read, then big accounts, then post lookups |
| What am I giving up? | Freshness by seconds, and storage for ready feeds, in return for fast reads |
Who should do the work?
Time
Spend the 45 minutes
| Minutes | Do | Leave with | Skip |
|---|---|---|---|
| 0 to 5 | Clarify, choose three features, set targets | Post, read feed, new-post hint | Ads, messaging, groups in detail |
| 5 to 10 | Only sums that decide | Push against pull, feed cache size | Video storage, unless asked |
| 10 to 15 | Endpoints and main records | Create post, read feed with a cursor | Profile fields |
| 15 to 25 | Version 1, then grow it | A read and a write, end to end | Model architecture |
| 25 to 40 | Two deep dives: fan-out, then ranking or privacy | A decision with a cost for each | Training pipelines |
| 40 to 45 | Failures, what next, recap | A clear last sentence | New features |
Lines you can open with
- 1
Start
"I will agree scope and scale, get a simple feed working, then spend our time on fan-out and the read path. Is that what you would like?"
- 2
Park something
"Ranking can fill an interview by itself. I will treat it as a function with a time limit and come back."
- 3
When stuck
"Let me look at my two products again. Which one is too large now?"
- 4
Close
"Normal posts are pushed, big accounts pulled, permission is checked at read. The part I would test first is a lost feed cache."
Patterns inside this problem
| Pattern | The signal | Where it lands |
|---|---|---|
| Precompute for reads | 50 reads for each write | Ready feeds in Redis |
| Uneven load | Follower counts differ a million times | Hybrid push and pull |
| Fan-out through a queue | One event, many slow effects | Kafka and workers |
| Hot key | Everyone reads the same post | In-process copy, sharded counters |
| Graceful fallback | A clever part may fail | Newest first when ranking is down |
Do
- Compare push and pull with numbers
- Name the big account problem before you are asked
- Filter at read time
- Say what users see when a part fails
Traps
- Push for everyone
- Fan out before answering the author
- Trusting the cache for privacy
- Strict consistency for a feed
- One database at two billion users
- No rate limits