The Problem: Why Timelines Are Hard
What is a "home timeline," in one breath?
When you open Twitter, you see a reverse-chronological-ish stream of tweets from the accounts you follow (plus, in the algorithmic era, some you don't). That stream is the home timeline. It is not the same as a user's profile timeline (the tweets they authored). The home timeline is a per-viewer, personalized merge of many authors' tweets.
That one word — personalized — is the whole problem. There is no single "the timeline" you can compute once and cache for everybody. There are ~200M different timelines, one per viewer, and each one changes every time any of the (possibly thousands of) accounts that viewer follows posts something.
So the system is solving a fan-out problem: one write (a tweet) must become visible in up to tens of millions of distinct reads (timelines). Everything in this guide is a consequence of that asymmetry.
The two numbers that define the whole design
Keep these two facts in your head; every decision below falls out of their ratio.
| Quantity | Rough scale | Consequence |
|---|---|---|
| Reads (timeline views) | ~300,000 timeline requests/sec | Reads dominate by orders of magnitude. The read path must be cheap. |
| Writes (tweets) | ~5,000/sec avg, ~12,000+/sec at peak | Writes are rare by comparison — so we can afford to do more work per write. |
The read:write ratio is enormous — roughly tens of reads for every write, and each read would otherwise touch hundreds of authors. This is the single most important observation in the entire system:
When reads vastly outnumber writes, you move work off the read path and onto the write path. Pay once at write time to make every subsequent read trivial. Fan-out on write is exactly this trade applied to timelines.
The rest of the guide is what happens when that beautiful trade meets a Justin Bieber.
Three requirements — personalized, read-dominated, sub-100ms — each easy alone, brutal together.
The intuition first
Imagine a newspaper. A newspaper is easy at scale because everyone gets the same paper. You print one edition, truck it to a million doorsteps, done. The content is computed once.
Twitter is a newspaper where every single subscriber gets a different edition, the edition is re-typeset the instant any contributor files a story, and the subscriber expects the fresh edition to appear the moment they glance at their phone. There is no "one edition." There are 200 million editions, each a function of who that specific person follows.
That's the shape of the problem. Now make it concrete.
The three requirements, and why each is individually easy
| Requirement | Why it's easy in isolation |
|---|---|
| Personalized | If you didn't care about latency, just query "tweets from everyone I follow, newest first" on every view. |
| Read-dominated / cheap reads | If everyone saw the same feed, you'd compute it once and cache it globally — one read serves all. |
| Sub-100ms | If the data were tiny, any database does this. |
Each requirement has an obvious solution. The trouble is the obvious solution to each one violates the other two.
PERSONALIZED ───────────────► forces per-user computation
│ │
│ ▼
│ (200M distinct feeds)
▼ │
SUB-100ms ◄──── conflicts ──-──────┘
▲
│
READ-DOMINATED ──► 300K reads/sec; if each read does
O(followed-accounts) work, you die
The arithmetic that rules out the naive approach
Suppose an average user follows ~200 accounts (heavy users follow thousands). The naive read does:
for each of ~200 followed accounts:
fetch their recent tweets (a query / index lookup)
merge all results by time
sort, take top N
At 300,000 timeline reads/sec, each fanning out to ~200 author lookups, that's ~60 million author-lookups per second just to render timelines — before ranking, before media, before anything. And it's spiky: when a popular account posts, everyone refreshes at once.
No relational database, and no amount of read replicas, makes 60M random-access lookups/sec at single-digit-millisecond latency affordable. The naive design is dead on arrival. The parts from fan-out on read to hybrid model are the search for something better.