The Hybrid Model (The Actual Answer)

The production answer is neither push nor pull. It's push for low-follower accounts, pull for high-follower accounts, merged at read time. The cutoff between them is the most important — and most political — number in the system.

The intuition first

Back to mailboxes (see fan-out on write) and made-to-order (see fan-out on read). Most of your correspondents are happy to drop mail in your mailbox — cheap for them, instant for you. But a few correspondents have hundreds of millions of subscribers; making them deliver individually would break the postal service. So for those few, you don't get home delivery — instead, when you check your mail, the post office also runs to the newsstand and grabs whatever those few celebrities just published, and staples it into your stack on the spot.

Your inbox = (pre-delivered mail from normal folks) merged with (freshly-fetched celebrity headlines). Best of both.

How it works

At write time (fan-out service):

user posts a tweet
   │
   ├─ is this author a "high-follower" account (N > cutoff)?
   │
   ├─ NO  → fan out on write: ZADD tweet into every follower's timeline  (Section 2)
   │
   └─ YES → DO NOT fan out. Just store the tweet. Mark author as "celebrity."
            Their followers will pull this at read time.

At read time (timeline service):

viewer 42 opens home timeline
   │
   ├─ 1. fetch precomputed timeline:  ZREVRANGE home_timeline:42   (the push half)
   │         → tweet IDs from all the NORMAL accounts 42 follows
   │
   ├─ 2. which celebrities does 42 follow?   (small list, from the graph)
   │         → [celebA, celebB]
   │      fetch their recent tweets directly (the PULL half)
   │
   ├─ 3. MERGE the two streams by Snowflake ID (time order), de-dup, take top N
   │
   ├─ 4. (rank — Section 9)
   │
   └─ 5. return
   ┌──────────────────────────┐     ┌───────────────────────────┐
   │ PUSH half (precomputed)  │     │ PULL half (read-time)     │
   │ tweets from ~all accounts│     │ tweets from the handful of│
   │ you follow with N<cutoff │     │ celebrities you follow    │
   │  [t9, t7, t5, t2, ...]   │     │  [c8, c3]                 │
   └────────────┬─────────────┘     └─────────────┬─────────────┘
                │                                  │
                └──────────────► MERGE ◄───────────┘
                         (sort by Snowflake ID = time)
                                  │
                                  ▼
                          home timeline for viewer 42

Why merge at read time works cheaply

The pull half is cheap precisely because of the cutoff. A given viewer follows only a handful of celebrities (you don't follow 10,000 mega-accounts). So step 2 fetches tweets from maybe 0–50 authors, not hundreds. The expensive read-amplification of the fan-out on read part doesn't reappear, because we only pull from the few accounts for which pull is cheap. The push half handles the long tail of normal accounts where push is cheap. Each half operates only in the regime where it's inexpensive.

The cutoff: a business decision in a technical costume

Where do you draw the line between "fan out on write" and "handle at read time"? The brief's number is ~20,000 followers. The exact value is a tuning knob, and choosing it is the crux of the whole design. Crucially:

The cutoff is not derived from a clean technical formula. It's a cost/complexity trade-off the business chooses. There is no follower count at which physics suddenly forbids fan-out. There is a follower count above which fan-out's cost (write bandwidth, burst risk, fan-out latency) exceeds the read-time merge's cost — and that crossover depends on cluster economics, traffic patterns, and how much operational complexity you'll tolerate.

What moving the cutoff does:

Move the cutoff... Effect
Lower (e.g., 5K) More accounts treated as "celebrities" → less fan-out write load, but more accounts handled by read-time pull → heavier, slower reads, larger merge.
Higher (e.g., 100K) Fewer celebrities → simpler reads, but more accounts doing big fan-outs → more write amplification and burst risk.

You tune it to balance write-side cost against read-side cost given your actual hardware and traffic. That's an operations/economics decision, not a law of nature — which is exactly why it "looks technical but is really a business call."

The cost you pay for the hybrid: two code paths

Nothing is free. The hybrid's price is complexity:

  • Two delivery paths (push and pull) that must be kept consistent.
  • A merge step on every read that must correctly interleave precomputed and freshly-pulled tweets, de-duplicate, and honor ordering.
  • Classification logic: deciding/maintaining who counts as a celebrity, and handling accounts that cross the threshold (an account that grows past the cutoff must switch modes — and you must avoid both double-delivery and gaps during the transition).
  • Edge cases: what about a normal user who suddenly goes viral mid-tweet? What about an account right at the boundary?

A staff engineer accepts this complexity consciously, because the alternative (pure push) doesn't function at all for mega-accounts and the alternative (pure pull) doesn't function at all at read scale. Two hard-but-bounded code paths beat one impossible one.

Pros and cons of the hybrid

✅ Pros ❌ Cons
Reads stay fast — push half is precomputed; pull half is tiny (few celebrities per viewer). Two code paths to build, test, and keep consistent.
Writes stay bounded — no account ever fans out to 100M timelines. Read-time merge logic adds complexity and a little read cost.
Each model used only where it's cheap — optimal cost on both sides. Threshold tuning & mode transitions are fiddly and error-prone.
Scales to mega-accounts — celebrity tweets are one write, pulled on demand. Mental model is harder — "where does this tweet live?" now depends on the author.