Design: news feed

System Design · lesson 14 of 32 · 4 min read

Compare fan-out on write and on read, and see why real feeds use both at once.

Open this lesson in the learning hub

Key points

  • A feed is posts from the accounts you follow, newest first. The hard requirement is that a read must be fast for every user at once.
  • Fan-out on write: when someone posts, push the post id into each follower’s feed list in Redis. Reads become one lookup.
  • That breaks on celebrities. One post to 50M followers is 50M writes, and most of those feeds are never opened.
  • Fan-out on read: fetch the accounts a user follows and merge their recent posts at request time. Cheap writes, slow reads.
  • Hybrid is what real systems ship: fan out for normal accounts, pull for the few huge ones, merge the two at read time.
  • Keep only the newest ~1,000 ids per user; older pages fall back to the database. Ranking is a layer on top - get delivery right first.

Precompute for the many, compute on demand for the few, and merge the two at read time.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the System Design course, and every lesson in it is listed on the System Design contents page.