Social & feeds
Social news feed - fan-out on write or on read
Fan-out on write against fan-out on read, and when each loses.
The first act plays here. Owned once with credits, never a subscription.
What this board gets wrong on purpose
The tension
Fan-out on write is drawn as the default and it breaks on the celebrity: one publish by an account with ten million followers becomes ten million writes, and while the workers chew through that single post every ordinary post is stuck behind it. The threshold on the fork is a hardcoded number nobody can defend, and the board does not say what happens to an account that crosses it between one post and the next.
Practise this as an interview
Take Social news feed - fan-out on write or on read as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.
Start here
Why this design
The news feed is the canonical read-amplification versus write-amplification question, and it is asked at every company that has a timeline because the answer is not a component, it is a trade. Interviewers use it to see whether you notice that follower counts are heavy-tailed - most authors have a few hundred followers and a handful have tens of millions - and whether you can size a cache from first principles. Real feed teams live inside the hybrid this board draws, and spend their time on the threshold between its two halves.
What you will learn
- Why fan-out on write makes a feed open one cache read, and why it turns a 10M-follower publish into 10M writes and roughly 13 seconds of the entire fan-out fleet.
- Why authors over 10k followers are 6% of posts but would be 93% of fan-out writes, and why the hybrid pulls exactly those at read time instead.
- How to size the feed cache: 500 ids x 24 B for 600M monthly actives is 7.2 TB of RAM, and why it holds ids, not posts.
- Why the read path merges two architectures - a precomputed list and about six pulled author lists - and what the ranker has to dedupe.
- What happens when an account crosses the threshold between two posts, and why the threshold belongs in a per-account column with hysteresis rather than in code.
- Why each region fans out locally from a replicated event stream rather than replicating 22.6 billion feed writes a day.
How to read this board
- Diagram, top to bottom: PUBLISH (one write, one event), then THE FOLLOW GRAPH beside the FAN-OUT DECISION - the diamond is the whole template.
- Then the two answers side by side: FAN-OUT ON WRITE (workers and the feed cache) and FAN-OUT ON READ (one store and a decision not to act), then SERVING, where they merge. Press Play for the eight-step walkthrough of one post.
- Page 1 · Requirements - the questions that decide push or pull before anything is drawn.
- Pages 2 and 3 · Capacity and Storage - the celebrity arithmetic, and why the feed cache is the big number.
- Page 4 · Availability - what degrades, and the failure that hides a post rather than erroring.
- Page 5 · How it works - one post end to end, then Page 6 · Deployment, including how to change the threshold safely.
- Finally the DATA MODEL at the bottom: three tables, and the feed is not one of them.
- The conversation to have: the "10k" on the diamond is a hardcoded number nobody can defend, and the board does not say what happens to an account that crosses it.
1 · Requirements
Ask these before drawing anything
- What is the follower distribution? Not the mean - the tail. If the largest account has 5,000 followers, pure push is correct and this board is over-built. If it has 10 million, pure push is an outage.
- Is the feed reverse-chronological or ranked? Ranked means the candidate set is bigger than the page and somebody scores it; chronological means the merge is the whole job.
- How fresh must it be? "A follower sees the post within five seconds" sizes the fan-out fleet. "Within a minute" lets it run at average load rather than peak.
- How deep does a feed go? People scroll a few hundred items, not a year. The answer bounds every per-user list on this board.
- Does an inactive user need a feed at all? Building timelines for people who have not opened the app in a month is most of the write cost and none of the value.
- Does delete, block or unfollow have to take effect instantly in feeds that were already built? It decides whether those are filtered at read time or chased through the cache.
- What happens to an account whose follower count crosses the threshold? This is the question the board leaves open on purpose.
Functional
- Publish a post (text plus a media reference) and have it appear in every follower’s home feed.
- Follow and unfollow; the next feed open reflects the change.
- Open the home feed: a page of 50 ranked posts, then further pages by cursor.
- Delete a post and have it vanish from every feed, including ones already built.
Non-functional
- Feed open: p99 under 200 ms server-side at 104,000 opens/s peak.
- Publish: acknowledged once the post store has it, p99 under 300 ms. Fan-out is asynchronous and is never on this path.
- Fan-out lag for authors under the threshold: p99 under 5 s from publish to a follower’s feed cache, and under a minute even at peak.
- A celebrity’s post must not delay anybody else’s. This is the requirement pure push cannot meet.
- Posts are durable (three replicas). The feed cache is not: losing it costs latency, never data.
- Feeds are eventually consistent. Two devices may briefly show different feeds and nobody minds.
Out of scope
- The media pipeline and CDN, search, notifications and ads.
- Recommended posts from accounts the reader does not follow - a different candidate source feeding the same ranker.
- Ranking model training. This board treats the ranker as a service that scores candidates.
The rest of this board
Available on Tier Slate
This page publishes the question. The answer — 5 more written pages, an 8-step narrated walkthrough and a 3-table schema — is the board itself, and it opens in Tierslate.
- 5written pages
- 8walkthrough steps
- 3tables15 columns
5 pages behind this one
- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan