Fan-out on Read (The Pull Model)
The model this introduces: pull. Store nothing per-viewer. At read time, go gather. Writes are trivial; reads do all the work — and the work is too expensive.
The intuition first
This is the "I'll make your sandwich when you order it" model. The kitchen stores raw ingredients (tweets, in their author's storage). When you sit down (open the app), the chef runs around gathering ingredients from everyone you follow and assembles your plate on the spot. Nothing is pre-made. Every order is bespoke and slow.
How it works
There are two stores involved:
- The tweet store ("T-bird" — historically sharded MySQL fronted by the Gizzard framework): every tweet, keyed by its tweet ID, sharded by ID.
- The social graph ("Flock" / FlockDB): the edges — who follows whom. Lets you answer "who does user X follow?" and "who follows user X?"
On a timeline read:
GET /home_timeline (viewer = user 42)
│
├─ 1. graph: "who does 42 follow?" → [7, 19, 88, 230, ... ~200 ids]
│
├─ 2. for each followed id: fetch their recent tweets from the tweet store
│ author 7 → [t,t,t]
│ author 19 → [t,t]
│ author 88 → [t,t,t,t]
│ ...
│
├─ 3. merge all tweets, sort by tweet ID (time order), take top N
│
└─ 4. return
Because tweet IDs are Snowflake IDs (see eventual consistency) — 64-bit, time-ordered — the merge is a k-way merge of already-sorted lists. Clean conceptually.
Pros and cons
| ✅ Pros | ❌ Cons |
|---|---|
| Writes are O(1) — a tweet is one insert into the author's own store. No matter how many followers, posting is instant. | Reads are O(followed accounts) — every view fans out to hundreds of lookups. |
| No precomputed state to store — no per-user timeline to maintain, no storage amplification. | Read latency is high and unpredictable — bounded by your slowest author shard. One slow shard = slow timeline. |
| Always fresh — you read the live state of every author, so no staleness. | Repeated, wasteful work — you recompute the same merge every refresh even if nothing changed. |
| Trivial for celebrities — a 100M-follower account is just one write, same as anyone. | Read amplification at fleet scale — 300K reads × ~200 lookups = ~60M lookups/sec. Economically impossible at low latency. |
Why it fails — the precise reason
The failure is read amplification: the work per read is multiplied by your follow count, and there are a lot of reads. You've put the expensive fan-out on the side of the system that runs 300,000 times per second. That is exactly backwards from the read:write ratio in the why timelines are hard part.
The lesson that motivates the fan-out on write part: you have a rare event (a tweet) and a frequent event (a read). Pull does the heavy work on the frequent event. Flip it: do the heavy work on the rare event, and make the frequent event cheap. That flip is fan-out on write.
Pull is not useless, though — remember it. It is exactly the right tool for celebrities (see hybrid model), because for a celebrity the write side is the expensive side. We will bring pull back as half of the hybrid.