Synthesis: How It All Interlocks
Staff-level understanding is seeing where one layer's guarantee is paid for by another layer's cost. The timeline system is a stack of trades, each one buying something and billing something.
The read:write asymmetry is the seed of everything
Every design choice traces back to the why timelines are hard part’s ratio (~300K reads/sec vs ~5K writes/sec):
read >> write
→ move work to write time (Section 2 fan-out on write)
→ but write cost is O(followers) (Section 3 write amplification)
→ which explodes for celebrities (Section 3 the celebrity problem)
→ so don't fan out for them; pull instead (Section 4 hybrid)
→ merge push + pull at read time (Section 4)
→ store cheap IDs in bounded ZSETs (Section 5)
→ fan-out is async → eventual consistency (Section 6)
→ order via Snowflake IDs (Section 6)
→ all of this is just CANDIDATES for ranking (Section 9)
Pull the first domino (reads dominate) and every subsequent choice falls out by necessity.
Each layer's guarantee is paid for by another layer's cost
| This guarantee... | ...is paid for by this cost elsewhere |
|---|---|
| Fast reads (the fan-out on write part: O(1) timeline fetch) | Write amplification (see write amplification) — work moved onto the write path |
| Bounded writes for everyone (the hybrid model part: no 100M fan-out) | Two code paths + read-time merge (see hybrid model) — complexity and a little read cost |
| Tiny, predictable RAM per user (the Timeline Service part: IDs, capped at ~800) | Hydration hop at read time + deep-scroll falls back to pull |
| Availability & low latency (the eventual consistency part: async fan-out) | Eventual consistency — momentary disagreement, occasional out-of-order delivery |
| Cheap candidate generation (see the parts from fan-out on write to eventual consistency) | Ranking must be layered on top (see algorithmic timeline) to turn raw candidates into a good feed |
| ML can iterate freely (the algorithmic timeline part: ranking is a top layer) | A delivery/ranking contract must be maintained; ranking adds latency |
The celebrity problem is the load-bearing insight
If you remember one thing: the optimal architecture is two architectures, chosen per-account by follower count. Push and pull have opposite failure profiles (the write amplification part table), so the system uses each only in the regime where it's cheap. The boundary between them (the ~20K cutoff) is the single most consequential number — and it's a business/economics decision disguised as a technical threshold. A junior engineer sees "Twitter uses fan-out." A staff engineer sees "Twitter uses two fan-out strategies separated by a tunable, business-chosen cost boundary, and accepts permanent two-code-path complexity as the price of scaling to mega-accounts."
The whole stack in one diagram
┌──────────── a user posts a tweet ────────────┐
│ store durably (T-bird) + Snowflake ID │
└───────────────────┬──────────────────────────┘
author N < cutoff │ author N > cutoff (celebrity)
▼ ▼
┌──── fan-out on WRITE ──┐ └─► (no fan-out; pull at read)
│ ZADD tweet-id into │ │
│ every follower's │ │ also ─► Earlybird
│ home_timeline ZSET │ │ (search index, Section 8)
│ (async → Section 6) │ │
└───────────┬────────────┘ │
▼ │
┌───────── viewer opens home timeline ──────────────┘
│ 1. ZREVRANGE home_timeline:{viewer} (push half, precomputed)
│ 2. pull recent tweets of followed celebrities (pull half)
│ 3. MERGE by Snowflake ID, de-dup ◄── candidate set
│ 4. + out-of-network candidates (SimClusters/UTEG, Section 9)
│ 5. light rank → heavy rank → filter → mix (Section 9)
│ 6. hydrate tweet bodies from tweet cache (Section 5)
▼
"For You" / Home timeline (sub-100ms for delivery; a bit more with ranking)