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.
Agree on the scope
Ask what changes the design, then commit to a short list.
Clarifying requirements
Interviewer
Let's design Facebook's news feed. What would you ask?
You
Scale first, then features, then limits:
- How many daily users? I will assume 2 billion.
- How many friends and follows on average? I will assume 500 in all.
- How often do people open the feed? I will assume 10 requests a day, of which 3 start a visit and 7 ask for more.
- How many post? I will assume 20% of users, one post each a day.
- Is the order by time, or ranked?
- Text, photos, video? Who may see a post?
- Must new posts appear without a refresh?
Interviewer
Those are fine. Ranked, with photos and video, audience settings, and live hints. Some accounts have 100 million followers. How does that affect you?
You
It decides the design. A normal post is 500 small writes. That account's post is 100 million for one click of a button, and everyone else's posts wait behind it. So I expect two paths: push for normal accounts and pull for big ones.
Interviewer
Which quality targets would you set?
You
In order: availability, then latency, then freshness.
- First page in 200 ms at p99, measured at our servers.
- 99.99% available, about 53 minutes a year. Never an empty feed.
- A normal post reaches friends' feeds in 5 seconds; a hint to open apps within 10.
- Your own post is visible to you at once.
- An unfriend, block or deletion applies to the next feed request.
- Posts are durable before we say "posted". Ready feeds may be lost and rebuilt.
In scope
- Personal feed, ranked, endless scrolling
- Create, edit and delete posts with text, photos, video, links, places
- Audience: public, friends, custom list, only me
- Like, comment, share and reaction counts
- Hints that new posts exist
- Reach and reaction numbers for authors
Out of scope for now
- Ads and billing
- Messaging
- Training the ranking model
- Full search
- Live video
Quality targets
| Quality | Target | Why |
|---|---|---|
| Latency | first page under 200 ms p99 | It is the first screen of the product |
| Availability | 99.99%, with degraded modes | A simple feed beats an error page |
| Freshness | 5 s for normal posts, 10 s for hints | Seconds are fine; minutes feel broken |
| Consistency | eventual for feeds and counts, your own posts at once | Nobody can compare two people's feeds |
| Privacy | correct on the next request | A wrong audience is a real harm |
| Durability | no lost posts | Feeds can be rebuilt; posts cannot |
| Spikes | 3x peak daily, 10x events with degraded modes | Elections, finals, outages elsewhere |
Each answer changes the design
| You ask | If the answer is | Then |
|---|---|---|
| Ranked or newest first? | Newest first | No ranking service, and the cursor is simply a post ID |
| Is there a follower limit? | Yes, 5,000 | Push for everyone; no big account path |
| How many users? | 100,000 | One database and a good query; stop at version 1 |
| Must hints be instant? | Within 100 ms | Open connections for all, no batching, far more servers |
| Can posts be edited? | Yes | Feeds must hold IDs, not copies |
| Are reads mostly by a few active users? | Yes | Push only to warm feeds, rebuild the rest |