Load/Bearing
High-level design · 13 of 22

News feed and fan-out

Precompute every user's feed when someone posts, or assemble it when they open the app? The answer is both.

A news feed shows each user recent posts from the accounts they follow. Users read their feed far more often than anyone posts, and some accounts have millions of followers. The core decision is when to do the work of matching posts to readers.

Numbers

QuantityMathResult
Daily active users200M
New posts200M × 1 per day ÷ 86,400≈ 2,300/s
Feed loads200M × 10 per day ÷ 86,400≈ 23,000/s
Feed inserts if every post is pushed2,300 × 200 average followers≈ 460,000/s

Fan-out on write (push)

When someone posts, a worker looks up their followers and adds the post ID to each follower's precomputed feed, typically a capped Redis sorted set of the newest few hundred IDs. Reading a feed is then a single cheap lookup.

POST APIPOSTS DBpost rowsFANOUT QUEUEpost idFANOUT WORKERSbatch by followerFEED CACHEuser → [post ids]
Push: the post is stored once, and its ID is copied into every follower's feed in the background.

Where it breaks: a celebrity with 10 million followers creates 10 million feed writes per post, and each of those followers' feeds updates late. Most of that work is wasted on followers who won't open the app today. Deletes and edits have to be fanned out too.

Fan-out on read (pull)

Store only each author's own posts. When a user opens the feed, fetch recent posts from everyone they follow and merge them, a k-way merge by time or score.

Where it breaks: a user who follows 2,000 accounts triggers 2,000 lookups per feed load, at 23,000 loads per second. Reads become slow and expensive, and that's the operation users do most.

The hybrid most systems use

That answers the celebrity question: a post by an account with 10M followers costs one write, plus a cache entry that millions of feed reads share.

Storage

Ranking and pagination

Chronological feeds sort by time. Ranked feeds first gather candidates (pushed IDs plus pulled celebrity posts), then score them with a model and keep the best. Paginate with a cursor (the last ID or score seen), not an offset: new posts arriving at the top would make offset pages shift and repeat.

Interview checklist

Practise it

Level 14: Fan-out

Put this into practice against live traffic. Your progress in the game is saved in your browser.

Play level 14

Further reading