Fan-out on Write (The Push Model)

The model this introduces: push. When you tweet, immediately write that tweet's ID into the precomputed timeline of every follower. Reads become a single cache fetch. The cost moves to write time — and for most users that's fine.

The intuition first

This is the "every subscriber has a personal mailbox" model. The moment you publish, a delivery worker drops a copy of your story into the mailbox of every one of your subscribers. When a subscriber checks their mail, it's already sitting there, pre-sorted. Checking the mailbox (the read) is instant. The delivery (the write) is where all the labor went.

How it works

Each user has a home timeline — a precomputed, ordered list of tweet IDs — living in the Timeline Service (a Redis cluster; details in the Timeline Service part). The flow:

user 7 posts a tweet  (tweet_id = T)
   │
   ▼
┌─────────────────────────────────────────────────┐
│  FAN-OUT SERVICE                                 │
│                                                  │
│  1. write T to the tweet store (durability)      │
│  2. graph: "who follows user 7?" → followers     │
│         followers = [42, 88, 109, 555, ...]      │
│  3. for each follower f:                         │
│         ZADD home_timeline:{f}  score=T  member=T│  ◄── push into each mailbox
│  4. (each timeline is trimmed to ~800 newest)    │
└─────────────────────────────────────────────────┘

Later, viewer 42 reads:
   GET home_timeline:42  →  [T, ...already merged & sorted...]  ── one fetch, done

The read is now a single lookup of a precomputed list. No graph traversal, no per-author fan-out at read time. That's how you hit sub-100ms at 300K reads/sec: the read does almost nothing.

The key inversion

            PULL (Section 1)                         PUSH (Section 2)
   write:  O(1)  ─ cheap                write:  O(followers) ─ expensive
   read:   O(followed) ─ expensive      read:   O(1) ─ cheap   ◄── the win

   Work is on the FREQUENT event        Work is on the RARE event
   (300K reads/sec)  ✗ wrong side       (5K writes/sec)   ✓ right side

This is the central trade. You are trading write amplification for read simplicity. Because writes are ~60× rarer than reads and each read would otherwise be ~200× more expensive, the trade pays off massively — for the typical user.

Why it's worth doing extra work at write time

Three compounding reasons:

  1. Writes are rarer. ~5K/sec vs ~300K/sec. Doing 200× more work on the rare event is cheaper in aggregate than doing it on the common one.
  2. Write-time work is amortized over many reads. A tweet posted once may be read by that follower across many sessions. Computing the merge once at write time and serving it from cache many times is the textbook caching win.
  3. Write-time work can be asynchronous. The user who posted doesn't have to wait for fan-out to finish (see eventual consistency). The tweet is durably stored immediately; delivery to mailboxes happens in the background. So the poster's latency is unaffected even though the system does a lot of work.

Pros and cons

✅ Pros ❌ Cons
Reads are O(1) — one cache fetch of a ready list. This is what makes sub-100ms possible. Writes are O(followers) — a tweet costs as many writes as you have followers.
Predictable read latency — no dependence on slow author shards at read time. Write amplification explodes for high-follower accounts (see write amplification).
Cheap to rank/serve — the candidate set is already assembled. Storage amplification — each tweet ID is duplicated into every follower's list (mitigated by storing IDs not bodies, and trimming — the Timeline Service part).
Great for the long tail — most users have modest follower counts, so fan-out is small. Wasted work on inactive followers — you deliver to mailboxes that may never be checked.

The crack that the write amplification part widens

That last "con" — write amplification — is fine when a user has 200 or 2,000 or even 20,000 followers. The fan-out is bounded and the delivery finishes fast. But the cost is linear in follower count, and Twitter has accounts with follower counts in the tens and hundreds of millions. Linear cost × astronomical follower count = catastrophe. That's the next part.