SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 15
Design a ranked news feed
When someone opens a social app, they see a feed of posts from friends, pages they follow and groups they belong to, ordered by what they are most likely to care about rather than by time. Every post has an audience set by its author (public, friends, friends except some people, a group), and people block each other.
Requirements
- Return a ranked feed mixing posts from friends, followed pages and joined groups.
- Never show a post to someone outside its audience, and never show posts between users who have blocked each other.
- Paginate within a feed session without duplicates or skipped posts, even while new posts arrive.
- Let a pull-to-refresh bring in newer posts as a new session.
Constraints and assumptions
- 500 million daily active users, each opening the feed about 10 times a day; peak 150,000 first-page requests per second.
- A typical user has 400 friends, follows 50 pages and belongs to 20 groups; their sources produce 1,500 to 3,000 eligible posts over the last two days.
- The full ranking model costs about 0.2 ms of compute per candidate; first page p99 under 500 ms end to end.
- Audience changes, unfriends and blocks must apply from the next feed request onward.
- A page holds 10 posts; a session lasts about 5 minutes and rarely goes past 100 posts.
Out of scope for the first sketch
Ads in the feed · Training the ranking models · Comments and reaction counts on posts
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design a ranked news feed
Finish your first sketch before answering these. Cross out freely.
- A user scrolls to page 3 while new posts keep arriving. How do you avoid showing duplicates or skipping posts?
- Alice changes a post from Public to Friends after it was already picked as a candidate for Bob, who is not her friend. What stops Bob from seeing it?
- Ranking takes 400 ms at peak. What do you cut, cache or precompute to get the first page out faster?
- How do you stop one content type or one very active friend from filling the whole first page?
Compare afterwards: worked approaches and reading at sketchbook /questions/news-feed/review