Home/Labs/Feed Fan-out Strategy
All 280 Labs
INTERACTIVE LAB📰

Feed Fan-out Strategy Lab (Interactive)

Pick push, pull, or hybrid fan-out and watch write cost trade against read latency. Compare fan-out-on-write cost to fan-out-on-read latency, using a celebrity threshold to split the hybrid feed model.

News Feed Fan-Out: Push vs Pull vs Hybrid

Post as a normal user or a celebrity and watch write amplification, feed-read latency, and the 3.2 TB Redis timeline bill.

Redis writes per post1,500,000≈ 15,000,000/s during the post
Post accepted in60.4 msfan-out continues async via worker pool
Feed read latency2 msLRANGE of precomputed timeline
Push-mode timeline RAM3200.0 GB500M × 800 IDs × 8 B

› Normal account (1,500,000 followers): push pre-computes each follower timeline; reads stay at ~2ms.

› Redis stores only post IDs (ZADD timeline:{uid} score=post_id); hydration multi-GETs metadata once per feed page.

› Inactive users' timelines are dropped and lazily rebuilt on next login (data hydration).

How It Works Under the Hood

News feeds pick their poison between write and read cost. Fan-out-on-write pushes a new post into every follower timeline list at posting time, so reads are trivial at around 2 ms, but a celebrity with millions of followers causes millions of writes per post. Fan-out-on-read leaves timelines empty and assembles them at view time by querying everyone followed, so writes are cheap but reads balloon past 100 ms and O(following) queries. The hybrid everyone actually ships pulls from normal accounts but pre-pushes celebrity posts, capped in memory to only recent IDs per user. Pick a strategy and watch the write count and read latency diverge across author follower counts.

Core Architectural Principles

  • Fan-out-on-write: one post becomes one row per follower, so a celebrity post can trigger millions of writes.
  • Fan-out-on-read: near-zero writes but assembling a timeline costs O(following) queries and roughly 115 ms.
  • Hybrid: push only celebrity authors, pull the rest, holding about 800 recent IDs per user in RAM.
Interview Round Script

Frame it as write amplification versus read latency and land on hybrid as the pragmatic answer, justified by the follower distribution — few celebrities, many small graphs. Quantify the celebrity write storm and the pull read cost. Mention timeline caching, materialized timelines for offline users, and how you handle the first-few-seconds active-now read on a hot post.

Key Trade-Offs

Push gives fast reads at huge write cost for large graphs; pull defers cost to read time and hurts latency for heavy followers.

Related Curriculum Chapter

Design a News Feed System (Twitter / Facebook / LinkedIn)

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs