Skip to content

Case study: News feed

Design a news feed: fan-out on write versus fan-out on read, a queue that turns load spikes into delay, and idempotent fan-out under at-least-once delivery.

35 min9 steps

By the end you can
  • Compute fan-out write amplification and the cost of a celebrity post
  • Choose between fan-out on write, fan-out on read and a hybrid from the read/write ratio and follower distribution
  • Make fan-out idempotent under at-least-once delivery and paginate a live feed correctly
  • Predict how the design behaves under a post surge, a worker crash and a cache flush

Requirements

Features

  • Publish; newest-first followed-account feed; pagination

Targets

  • Feed p99 <200 ms; posts visible within seconds; reads:posts 100:1

Isolation

  • Posting fast during fan-out lag; stale feeds acceptable

Which clarifying question most affects the fan-out design?

Answer this step to continue.

What this lesson simplifies

  • Fan-out to ~200 followers is modelled as one batched write per post whose cost reflects the batch; follower feeds are not individual records.
  • Ranking, hydration of post bodies and the follow graph are discussed, not simulated.
  • The runnable cell runs 1,500 requests/s with 10% posts.

Sources

  1. A. Silberstein, J. Terrace, B. F. Cooper, R. Ramakrishnan. Feeding Frenzy: Selectively Materializing Users' Event Feeds, 2010.
  2. R. Krikorian (Twitter). Timelines at Scale, 2013.
  3. R. Nishtala et al.. Scaling Memcache at Facebook, 2013.

Reviewed by Content lead on . Revision 1.