Design a Ranked Home News Feed for a Large Social Network
Company: Meta
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Onsite
Design the home news feed for a large social network. When users open the app, they see a ranked, infinitely scrollable list of recent posts from the friends and pages they follow. When they publish a post, it should show up in their followers' feeds.
Design the backend that accepts new posts and serves each user's feed.
```hint Where to pay the cost
Decide whether a feed is assembled when a post is written or when the feed is read, then test that choice against an account with an enormous follower count.
```
```hint Narrow before you rank
Scoring every post a user could possibly see on each request is too slow; think about what produces a small candidate set first.
```
### Constraints and Clarifications
- Media storage and delivery can be treated as an existing service; focus on post metadata and feed assembly.
- Scale, freshness targets, and ranking signals are not given; ask for them or state assumptions.
### Clarifying Questions
- How many daily active users are there, how many accounts does a typical user follow, and what is the largest follower count to support?
- Is the feed ranked or chronological, and which signals may ranking use?
- How quickly must a new post appear in followers' feeds?
- Are ads or recommended posts from accounts the user does not follow in scope?
- How must deletions, edits, and audience restrictions on a post be reflected in feeds that already contain it?
### What a Strong Answer Covers
- Fan-out on write versus fan-out on read, and a hybrid for accounts with very large follower counts
- Precomputed per-user feed storage and bounds on its size
- Candidate generation followed by ranking within a latency budget
- Cursor-based pagination that stays stable while new posts arrive
- Correct handling of deletes, edits, privacy changes, and unfollows
- Caching, sharding, and hot-key handling
- Failure handling, graceful degradation, and freshness metrics
### Follow-up Questions
- An account with a very large follower count publishes a post. Walk through what happens on the write path and on a follower's next read.
- How do you make sure a deleted post, or a post whose audience was narrowed, disappears from feeds quickly?
- How would you serve the feed of a user returning after months of inactivity?
- How would you test a new ranking model without hurting feed latency?
Overview: A system design question on building the home news feed of a large social network: publishing posts and serving each user a ranked, paginated feed of posts from the accounts they follow. It tests fan-out strategy, accounts with huge follower counts, ranking under a latency budget, and correctness for deletes and privacy.