Interview Case Studies
Design a Social News Feed
A home timeline of posts from people you follow, and the central choice: do the work when someone posts, or when someone reads?
By the end of this chapter
- Run an interview answer in order, from requirements to scaling
- Estimate read and fan-out load and see which one dominates
- Choose between fan-out on write and fan-out on read, and combine them for high-follower accounts
Clarify the requirements
Start by agreeing scope out loud. A news feed can mean anything from a chronological list to a fully ranked stream with ads; the interviewer wants to see you narrow it.
- Functional: a user can publish a text post, optionally with an image.
- Functional: a user can follow and unfollow other users.
- Functional: a user sees a home feed of recent posts from people they follow, newest first, paginated.
- Out of scope for now: ranking, comments, ads. Mention that ranking would sit on top of the candidate list this design produces.
- Non-functional: loading the feed is fast; aim for p99 under a few hundred milliseconds.
- Non-functional: a new post may take a few seconds to appear for followers. Eventual consistency is acceptable here.
- Non-functional: highly available for reads. A feed that is briefly stale is better than one that fails to load.
Estimate
Sign in to keep a note here. It is free, and nobody else can see it.
Sign inYou’ve reached the end
What this chapter was for:
- Feeds are read far more than they are written, which is the argument for precomputing them at write time.
- Precomputing breaks down for accounts with huge followings, so real answers are hybrids.
- Store post ids in the feed and hydrate on read, so edits and deletes need no fan-out of their own.
- Cursor pagination survives new posts arriving at the top of the feed; offset pagination does not.