The Algorithmic Timeline: Ranking on Top
Everything in the parts from fan-out on read to eventual consistency produces a candidate set of tweets — the raw material. The algorithmic timeline ("For You") is a ranking layer that re-orders and filters those candidates with ML. Crucially, ranking is layered on top of delivery — it doesn't replace fan-out; it consumes its output.
The intuition first
The parts from fan-out on read to eventual consistency are the grocery delivery — they get the right ingredients into your kitchen (candidate tweets you could see). The algorithm is the chef that decides what to actually plate, in what order, and what to leave in the fridge. The chef can't cook with ingredients that were never delivered — so delivery (fan-out) is still foundational. Ranking is a consumer of delivery, not a substitute for it.
The clean separation: delivery vs. ranking
┌──────────────────── DELIVERY (raw timeline, Sections 1–6) ──────────────┐
│ fan-out (push) + read-time pull (celebrities) │
│ → produces an unranked, time-ordered CANDIDATE SET of tweet IDs │
└───────────────────────────────┬─────────────────────────────────────────┘
│ candidates
▼
┌──────────────────── RANKING (algorithmic timeline, Section 9) ──────────┐
│ add out-of-network candidates → score with ML → filter → mix/order │
│ → produces the "For You" feed │
└─────────────────────────────────────────────────────────────────────────┘
This layering is why a "chronological" feed and an "algorithmic" feed coexist: both consume the same delivery substrate. Chronological = "show candidates sorted by Snowflake ID." Algorithmic = "show candidates sorted by predicted relevance." The expensive, scale-defining machinery (fan-out, timeline service) is shared; ranking is a swappable top layer.
The stages of the algorithmic pipeline
Based on Twitter's open-sourced recommendation algorithm, the "For You" pipeline runs roughly these stages each time you load the feed:
1. Candidate sourcing (retrieval). Gather a few thousand candidate tweets from multiple sources:
| Source | What it provides |
|---|---|
| In-network | Tweets from accounts you follow — i.e., the fan-out/timeline output of the parts from fan-out on write to eventual consistency. Historically ~half the feed. |
| Out-of-network | Tweets from accounts you don't follow, retrieved via graph traversal (e.g., "people your follows engaged with" — UTEG) and embedding-based similarity (e.g., SimClusters — communities of users/tweets in an embedding space). This is the search-style retrieval the Earlybird part hinted at. |
2. Light ranking. Score the large candidate set with a cheap model to whittle thousands down to hundreds. Cheap-but-fast, because you can't run a heavy model on every candidate.
3. Heavy ranking. Score the survivors with a large neural network (Twitter's was a multi-task model — on the order of tens of millions of parameters — predicting the probability of various engagements: like, reply, retweet, dwell, "this is good for the conversation," report, etc.). These predicted probabilities are combined into a single relevance score.
thousands of candidates
│ light ranker (cheap model)
▼
hundreds of candidates
│ heavy ranker (big neural net: P(like), P(reply), P(reply→author replies), ...)
▼
scored & ordered candidates
4. Filtering / heuristics ("the rules"). Apply hard constraints after scoring: deduplicate, drop tweets you've already seen, enforce author diversity (don't show 5 tweets from one person in a row), respect blocks/mutes, demote low-quality or flagged content, balance in-network vs. out-of-network, insert non-tweet content (ads, who-to-follow, etc.).
5. Mixing & serving. Interleave everything into the final ordered feed, hydrate tweet bodies (see Timeline Service), and return.
Why ranking is layered, not fused, into delivery
This is the staff-level "why":
- Different scaling axes. Delivery scales with follower graph and post rate; ranking scales with model complexity and candidate count. Fusing them would couple two independently-evolving systems. Keeping ranking as a top layer lets the ML team iterate on models daily without touching the fan-out infrastructure.
- Delivery must be cheap and reliable; ranking can be best-effort. If the ranker is slow or degraded, you can fall back to chronological over the same candidate set and still show a usable feed. If delivery fails, there's nothing to rank. So you want the robust, must-not-fail part (delivery) separate from the fancy, can-degrade part (ranking).
- Candidate generation reuses delivery output. The in-network candidates are the the parts from fan-out on write to eventual consistency timeline. The algorithm doesn't rebuild that; it consumes it and adds out-of-network candidates on top. Reuse, not replacement.
- Latency budget. Delivery already gave you a precomputed candidate set cheaply (see fan-out on write). That leaves the bulk of the ~sub-100ms-to-low-hundreds-ms budget for ranking the bounded candidate set, rather than spending it gathering candidates from scratch.
How the pieces you learned feed the algorithm
Sections 2/4 fan-out + pull ──► IN-NETWORK candidates ──┐
│
Section 8-style retrieval ──► OUT-OF-NETWORK candidates ──────────────────────┤
(SimClusters embeddings, UTEG graph walks) │
▼
light rank → heavy rank → filter → mix
│
▼
"For You" feed
Notice that every earlier part reappears here as an input: Snowflake IDs (see eventual consistency) order in-network candidates; the timeline service (see Timeline Service) supplies them cheaply; the hybrid (see hybrid model) ensures celebrity tweets are present; eventual consistency (see eventual consistency) means the candidate set is "recent-enough" rather than perfectly complete; and search-style retrieval (see Earlybird) supplies out-of-network candidates. The algorithm is the capstone that consumes the whole stack.
Pros and cons of layering ranking on top
| ✅ Pros | ❌ Cons |
|---|---|
| Delivery infra and ML evolve independently | Two systems to operate; clear contract needed between them |
| Graceful degradation (fall back to chronological) | Ranking adds latency on top of delivery |
| Reuses fan-out output as in-network candidates | Out-of-network retrieval adds its own heavy infrastructure |
| Can A/B and iterate on models without touching fan-out | "Why am I seeing this?" becomes hard to explain (opacity) |