Social & feeds
Home timeline - materialise it, then keep it honest
Why one post is fanned out into hundreds of precomputed timelines, and why the celebrity cannot be.
The first act plays here. Owned once with credits, never a subscription.
What this board gets wrong on purpose
The tension
Every timeline here is a denormalised copy that nothing repairs. Deletes, blocks, mutes, unfollows and gone-private accounts never travel back into the 150 million lists that already hold those ids, so the read path fetches rows in order to throw them away - which means a timeline gets SLOWER the longer an account has existed, and a page of twenty tweets can require hydrating sixty. The trim is the second half of it: past eight hundred ids the materialised timeline simply does not exist, so deep scroll falls through to a query path that is barely exercised, has no cache behind it, and is the one nobody load tests.
Practise this as an interview
Take Home timeline - materialise it, then keep it honest as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.
Start here
Why this design
The home timeline is the canonical fan-out question: one write must become visible to hundreds of readers, and the follower distribution is so skewed that no single strategy survives both the median account and the largest one. Interviewers use it to probe whether you size by the amplified number rather than the request rate, and whether you can see what a precomputed, denormalised copy costs to keep correct. Every social feed, activity stream and notification inbox inherits the same trade.
What you will learn
- Why fan-out on write turns 2,300 tweets/s into 463,000 list writes/s, and why that - not the tweet rate - sizes the system.
- Why the lists hold ids, not bodies, trimmed to 800: 2.9 TB of RAM instead of 28.8 TB, and what the trim leaves behind for deep scroll.
- How the hybrid works as data: an exclusion list of authors who are never fanned out and are pulled live at read time.
- Why hydration, not the 52,000 timeline reads/s, sizes the tweet store at 3.1M fetches/s - and why the storage-layer read:write ratio collapses to about 2:1.
- Why the visibility filter is the price of the copy, and why it is the one stage that must fail the request rather than degrade.
- Why the read path gets 99.95% and the write path 99.9%, and how timeline shards are split without a big-bang reshard.
How to read this board
- Diagram, top left first: COMPOSE · ONE WRITE, then FAN-OUT ON WRITE · ONE WRITE BECOMES N beneath it, then WHAT THE READ PATH MERGES on the right.
- Then READ · BUILD ONE TIMELINE, FIVE HOPS along the bottom of the diagram, left to right. Press play for the eight-step walkthrough.
- THE DATA MODEL under the diagram: users, tweets, follows, the materialised timeline_entries and the excluded_authors list.
- Page 1 · Requirements - the questions to ask first, starting with chronological or ranked.
- Pages 2 and 3 · Capacity and Storage estimation - fan-out amplification, hydration load, and what the 800-entry trim saves in RAM.
- Page 4 · Availability - different targets for read and write, and what degrades rather than dies.
- Page 5 · How it works, then Page 6 · Deployment plan, including resharding the timeline store.
- Then the conversation to have: every timeline is a copy that nothing repairs, so deletes and blocks are paid for at read time, and past 800 ids the timeline falls through to an uncached path nobody load tests.
1 · Requirements
Clarifying questions to ask first
- Is the timeline chronological or ranked? Ranking changes everything: a chronological timeline can be a pure merge, a ranked one needs features at read time and cannot be trimmed by time alone.
- How stale may a timeline be? Seconds, or is a missing tweet a bug?
- Do we owe read-your-own-writes? Seeing your own tweet immediately is the one staleness users notice within a second.
- What is the follower distribution? The p50 and the p99.99 are six orders of magnitude apart and they need different machinery.
- Are there private accounts, blocks and mutes? Each one turns a precomputed list into a list that must be re-checked at read time.
- Is deep scroll a product requirement, or may the timeline simply end?
Functional
- Post a tweet; it appears in the home timeline of every follower.
- Read a home timeline: the most recent tweets from the accounts you follow, ranked, paginated.
- Follow and unfollow; the effect on the timeline may be eventually consistent.
- Delete a tweet; it must stop being served.
- Blocked, muted and protected authors must not appear.
Non-functional
- Timeline read p99 under 200 ms at the API, measured server-side.
- Fan-out lag p99 under 5 seconds from post to a follower list, for ordinary accounts.
- 99.95% availability on the read path. The write path may be less available: failing to post is visible and recoverable, failing to read is the product being down.
- Eventual consistency is acceptable for other people's tweets. Read-your-own-writes is not negotiable.
- Deletes and blocks must take effect within one request, not within one TTL.
Explicitly out of scope
Search, direct messages, notifications, media upload, ads insertion, and the ranking model itself. The ranker is drawn as one box because its internals are a different board.
The rest of this board
Available on Tier Slate
This page publishes the question. The answer — 5 more written pages, an 8-step narrated walkthrough and a 5-table schema — is the board itself, and it opens in Tierslate.
- 5written pages
- 8walkthrough steps
- 5tables22 columns
5 pages behind this one
- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan