LOAD-BEARINGfree
Architecture labTier 13 · unit 3 of 31

News feed

Each user sees a reverse-chronological feed of posts from accounts they follow. A handful of accounts have tens of millions of followers.

Envelope500M users · 10:1 read:write · feed load p99 < 200 ms

What the design must do

  • Post creation writes once and returns fast
  • Feed reads served from a precomputed list
  • Celebrity accounts must not trigger millions of writes
  • Media served from the edge

The worked envelope

Assumed. 500M registered, 150M daily active, ten feed opens per active user per day, 10:1 read:write, average following 200.

Worked envelope
Feed reads150M × 10 = 1.5B/day ≈ 17k/s, peak ~50k/s
Posts10:1 → 150M/day ≈ 1.7k/s, peak ~5k/s
Fan-out writes150M posts × 200 followers = 30B/day ≈ 350k/s, peak ~1M/s
Feed cache500 entries × 32 B × 150M users ≈ 2.4 TB
Post storage150M/day × 1 KB = 150 GB/day = 55 TB/yr
Celebrity caseone post, 80M followers = 80M writes from one request

What the numbers decide. Compare the two lines that matter. Reads peak at 50k/s — large but ordinary. Fan-out writes peak at a million a second, and a single celebrity post is 80 million writes on its own. The write amplification, not the read volume, is the entire problem.

That asymmetry is what forces the hybrid. Fan-out on write is correct for the 99.9% of accounts with a few hundred followers, because it makes the read a single range scan. It is catastrophic for the long tail of accounts with millions, so those get pulled at read time and merged. And note the feed cache is 2.4 TB — a cluster, not a box, so consistent hashing and hot-key handling arrive as consequences of this table rather than as decoration.

The decisions, and what each one costs

Hybrid fan-out: push for ordinary accounts, pull for celebrities

Because
At 200 followers a post is 200 cheap writes and the read becomes one range scan; at 80M followers the same write is a self-inflicted outage
The cost
Two code paths, a threshold to tune, and a read that must merge two sources and re-sort
Rejected
Pure fan-out on write (one post can be 80M writes) and pure fan-out on read (every feed open becomes a 200-way scatter-gather)

Precomputed feed lists in a memory cluster, post bodies in a separate store

Because
The feed row only needs a post id and a score — 32 bytes — so 2.4 TB holds every user’s timeline, while 55 TB/yr of bodies stays on cheaper storage read only for what is displayed
The cost
Two round trips per feed render, and a cache miss means rebuilding a timeline from scratch
Rejected
Storing rendered feed content, which multiplies 2.4 TB by the size of a post and re-renders on every edit

Feed is eventually consistent — a post may take seconds to appear

Because
Making 200 fan-out writes synchronous puts them on the poster’s critical path and couples their publish latency to their follower count
The cost
A user can refresh and not see their own post, which is the one case that reads as broken
Rejected
Synchronous fan-out; the compromise is to inject the author’s own posts into their own feed at read time

Cap stored timelines at ~500 entries

Because
Deep scrollback is a fraction of a percent of sessions, and an uncapped list makes the 2.4 TB unbounded
The cost
Paging past the cap falls back to a slower query path
Rejected
Unbounded timelines, where inactive users accumulate cost forever for reads that never happen

Components in the reference design

Client
Browser or mobile app
Load Balancer
L7 routing, TLS termination, health checks
App Service
Stateless business logic
Cache
Redis / Memcached, sub-ms lookups
SQL DB
Relational, ACID, joins
Queue
Work distribution, one consumer per message
Worker
Async consumer, background jobs

The reference design

The central decision: fan-out on write or on read.

Fan-out on write pushes each new post into every follower's precomputed feed list at post time. Feed reads become one cache read — extremely fast. Post writes become O(followers), which is fine at 300 followers and impossible at 80 million.

Fan-out on read queries the posts of everyone you follow and merges at read time. Writes are trivial; reads are a fan-out merge on every single feed load, which is the wrong place to put the cost given the 10:1 read ratio.

The answer is hybrid, and saying so is the whole point of this problem. Fan out on write for ordinary accounts. Mark accounts above a follower threshold as celebrities and skip fan-out for them entirely; at read time, fetch the small number of celebrity accounts a user follows and merge their recent posts into the precomputed list. Best of both, because the expensive case is rare and the rare case is cheap to handle separately.

Storage. Posts in a durable store keyed by post ID. Feeds are lists of post IDs in Redis, capped at a few hundred entries — nobody scrolls to post 900, and an unbounded list is an unbounded memory bill. Hydrate IDs into full posts on read.

Async everything. Fan-out goes through a queue. Post creation returns as soon as the post is durable; the feed propagation happens behind it. A few seconds of delay before followers see a post is completely acceptable, and pretending otherwise costs you the entire design.

Inactive users. Do not fan out to accounts that have not opened the app in 30 days. In most social products that is a majority of the follower graph, and skipping them is the single largest cost saving available.