Design a News Feed
Open the app and see a fresh, ranked stream of posts from everyone you follow. The whole design is one fork — do you push each post into every follower’s feed as it’s written, pull them all together at read time, or split the difference? Built from zero: a commit-first envelope on 10M users, the push/pull/hybrid deliberation with cost meters computed live, the celebrity hot-key that melts the write path, the feed cache kept as bare <post-id, user-id> lists and why not full posts, the hydration step, an honest paragraph on the ranking hand-off, and the failure sweep.
System design · Systems. The source ↗
A free, interactive, animated visual explainer of Design a News Feed — built to be understood, not skimmed.
Questions
- What is fan-out on write versus fan-out on read?
- Fan-out on write pushes a new post into every follower’s pre-computed feed the moment it is written, so opening the feed is one cheap cache read — but a post costs one write per follower. Fan-out on read does the opposite: writing a post is one append, but opening the feed gathers recent posts from everyone you follow and merges them, which is expensive at read time. Most real designs go hybrid.
- How do you handle the celebrity problem in a news feed?
- A celebrity with millions of followers makes fan-out on write catastrophic — one post becomes millions of feed-cache writes, the classic hot-key. The fix is hybrid: normal accounts are pushed on write, but posts from high-follower accounts are not fanned out; instead each reader pulls those few accounts at read time and merges them into their pushed feed.
- Why does the feed cache store post IDs instead of full posts?
- A feed entry is stored as a tiny record — the post ID plus the author’s user ID plus a few metadata bytes — not the post text and media. Keeping only IDs makes each follower’s copy roughly 20 bytes instead of a kilobyte, so millions of feeds fit in RAM, and an edited or deleted post is fixed in one place rather than rewritten across every copy. The full post is fetched separately at read time.
- What is feed hydration?
- Hydration is the read-time step that turns the feed’s list of post IDs back into displayable posts: for the page of IDs the reader is about to see, the service does a batched multi-get against the post store (and author, media, and counter caches) and assembles the full objects. Only the visible page is hydrated, so the work is bounded by screen size, not feed length.
- Is a news feed chronological or ranked?
- Either — and the design mostly does not care. Fan-out builds the candidate set (the posts eligible to appear); ranking is a separate layer that scores and orders that set. A chronological feed just sorts the candidates by time; a ranked feed scores them with a model. Keeping ranking a hand-off over the candidates, not part of the fetch, is what lets the same feed pipeline serve both.