// Product-Scale Systems
Design a news feed
System Design track · 25 min
- Compare fanout-on-write and fanout-on-read, and say who pays the cost in each.
- Explain why celebrities break the push model and how the hybrid design fixes it.
- Name the three caches and stores behind a fast feed.
Open any social app and your home feed appears almost instantly: posts from hundreds of people you follow, already sorted. Behind that screen is one question that decides the whole design: when do you build each person's feed? The moment someone posts, or the moment someone opens the app?
That question has a name, fanout: one post spreading out to many feeds. This lesson is about where to pay for it.
- Publishing: a post is created and must reach the feeds of everyone who follows the author. This is the fanout problem.
- Reading: a user opens the app and expects the feed built, ranked and shown fast, in under about 200 ms, no matter how publishing works.
- Scale: about 500M posts a day (500,000,000 ÷ 86,400 ≈ 6,000 per second). Reads outnumber writes about 100 to 1. The average user follows about 300 accounts, and a handful of celebrities have tens of millions of followers each.
The moment a post is created, a fanout worker writes the post's ID into every follower's ready-made feed in the cache. Opening the app then costs one cheap lookup: read your list of post IDs, fetch the posts, done.
For a normal author with 300 followers, one post costs 300 writes. Trivial.
Now a celebrity with 50M followers posts a selfie. That is 50,000,000 cache writes. Even at 100,000 writes per second, 50,000,000 ÷ 100,000 = 500 seconds, more than eight minutes of write storm for one photo. And most of those followers will not even open the app today.
Flip it: write nothing extra when someone posts, and build the feed when someone reads. A post costs exactly one write, and the celebrity problem disappears.
But now every app open must fetch the recent posts of all ~300 accounts you follow, merge them, rank them and return the top ones, all inside the 200 ms budget. Reads are 100 times more common than writes, so you have swapped a write storm for a heavy bill on every single page load, forever.
Fanout is a question of when you pay. Push pays at write time, so reads are nearly free. Pull pays at read time, so writes are nearly free. Neither is wrong. The hybrid simply uses each one where it is cheap.
The fanout worker checks the author's follower count. Below a threshold (for example 1M followers, tuned by measurement), it pushes the post into followers' feeds as before. Above it, the post stays only on the celebrity's own timeline. When you open the app, the system takes your ready feed from the cache and merges in the latest posts from the few celebrities you follow.
Normal posts land in feeds instantly. Celebrity posts are pulled from one hot, well-replicated timeline, and only when someone actually reads.
- Pick the normal user and switch between push and pull. Watch where the cost moves: post time or read time.
- Now pick the celebrity with push, then switch to hybrid. See the write storm vanish while normal users stay on push.
- Feed cache: for each user, a ready list of the newest few hundred post IDs, filled by the fanout worker. This is what makes a read one lookup.
- Post cache: the posts themselves (text, media links, like counts), stored by post ID, so building a feed does not hit the database once per post.
- Social graph store: who follows whom, split across servers (sharded). It answers “who follows this author?” on write and “which celebrities does this user follow?” on read.
A plain newest-first list is the starting point. Ranking sits on top of it. The usual signals are recency (newer first), closeness (you often interact with this person), and predicted engagement (a model guesses whether you will like, reply or stop to read).
Rank well and the app feels alive. Rank badly, burying your best friend's news under a stranger's ad, or promoting anger because anger gets clicks, and people leave and trust drops. The failures of ranking are social, not only technical, so treat it as a product decision.
Why does a celebrity break push fanout, and what does the hybrid do with her posts?
Answer in your head first, then check.
Split the design into publishing and reading. Push makes reads one lookup but chokes on celebrities. Pull makes writes trivial but makes every page load heavy. The hybrid, push for normal users and pull for celebrities, is how real feeds work. A feed cache, a post cache and a social graph carry the load, and ranking decides how the product feels.
Pick a system you own where one write goes out to many readers: notifications, a group chat, a shared dashboard. Count the fanout: the average number of recipients per write, and the maximum. If the maximum is a hundred times the average, you have a celebrity problem. Decide the threshold where push turns into pull before your first famous customer finds it for you.
- Compare fanout-on-write and fanout-on-read, and say who pays the cost in each.
- Explain why celebrities break the push model and how the hybrid design fixes it.
- Name the three caches and stores behind a fast feed.
Product-Scale Systems