Skip to content
BytePatterns

Design a News Feed

System Design Cases: lesson 4 of 20

Pay at write time, at read time, or a little of both.

Lesson 4 of 20 · 7 min

Design a News Feed

Step 1 of 11

Ten million users, 500 posts a second, and fifty reads for every write. The ratio decides everything.

The Idea

Show each user recent posts from the accounts they follow, ranked. Assume 10 million users, 500 posts a second, and fifty reads per write — the ratio decides whether you pay when a post is published or when a feed is opened.

Real-World Example

A delivery round versus a newsstand. Dropping a copy through every subscriber's door is fan-out on write; making everyone walk to the stand and pick their titles is fan-out on read.

The Tradeoff

Fan-out on write gives an O(1) read and turns a celebrity's single post into tens of millions of inbox writes. Fan-out on read publishes instantly and makes every open a large merge. Real systems split it: write for ordinary accounts, read for the few enormous ones.

Your turn

Put the steps in the right order.

  1. Merge the prebuilt inbox with freshly pulled celebrity posts
  2. Write the post once to the author's own timeline
  3. Rank the merged set and return one page
  4. Fan the post id into each ordinary follower's inbox

Mini quiz

1 / 3

Fan-out on write makes opening the app cheap because:

New lessons land every few weeks

Leave an address and we will tell you when the next one is up. That is the only reason we will use it.

One address, stored so we can email you. Nothing else, ever.