πŸŽ‰ Launch Sale: Get 30% off annual plans with code LAUNCH30

← Back to Blog
Social Mediaβ€’Intermediateβ€’34 min read

Design a Twitter/X Home Timeline

Asked at:TwitterMetaLinkedInPinterest
Tech:Horizontal scalingShardingConsistencyAvailabilityCachingCircuit breaker

The 20-Million-Write Problem

A user with 50 followers posts a tweet. Your system writes 50 timeline entries β€” one into each follower's precomputed feed. Simple, fast, and the read path is a single sorted-set lookup. Now a celebrity with 20 million followers posts a tweet. Your system must write 20 million timeline entries. At peak, if 10 celebrities post within the same minute, that is 200 million timeline writes in 60 seconds β€” 3.3 million writes per second from just 10 tweets. Meanwhile, a normal user's tweet generating 50 writes waits in the same queue. The celebrity's fanout is starving the system.

This is the fundamental tension in feed systems: precompute the timeline (fast reads, expensive writes) or assemble it on demand (cheap writes, expensive reads). Neither extreme works at Twitter's scale. The answer is a hybrid β€” and the interesting part is where you draw the line and how you merge the two approaches at read time.

This post walks through designing a home timeline system from first principles. We will start with a correct but slow baseline, add fanout-on-write for normal users, introduce the hybrid celebrity strategy, and layer on ranking and caching. Every decision will be driven by the read/write asymmetry that defines this system: 1.85 million feed reads per second versus 46,000 tweets per second.

Let us begin.

1. Requirements β€” What "Show Me My Feed" Actually Means

The home timeline is the core product surface of Twitter. When a user opens the app, they expect to see recent tweets from people they follow, ordered by time (or relevance), loading in under 200 milliseconds. Behind that expectation is a system that must handle extreme read volume, asymmetric write amplification, and the celebrity skew problem.

Functional Requirements

  1. Post a tweet. A user creates a tweet (text, optional media reference). The tweet must eventually appear in the home timeline of every follower.
  2. Follow and unfollow. A user can follow or unfollow another user. Follow changes must be reflected in subsequent timeline reads β€” if you unfollow someone, their tweets should stop appearing.
  3. Load home timeline. A user opens the app and sees a paginated feed of recent tweets from accounts they follow. The feed must be fast, fresh, and correctly scoped to current follow relationships.

Non-Functional Requirements

  1. Home timeline p95 under 200 ms. The feed is the first screen users see. If it is slow, they leave.
  2. Extreme read scale. 1.85 million feed reads per second at peak. The read path dominates everything.
  3. Eventual consistency acceptable. A tweet appearing in a follower's feed 5-10 seconds after posting is fine. A tweet appearing 5 minutes late is noticeable.
  4. Handle celebrity skew. Accounts with millions of followers must not destabilize the write path for everyone else.

Scope Control

In scope: tweet posting, follow graph, home timeline assembly, fanout strategy, caching, basic ranking.

Out of scope: search/discovery, trending topics, ads injection, direct messages, notifications.

Now we need to understand the asymmetry. The ratio of reads to writes determines whether we precompute or assemble on demand.

Login to continue reading

You reached the preview limit. Sign in to unlock the remaining sections.

Continue Learning

πŸŽ‰ Launch Sale!

30% off annual plans with code LAUNCH30

View Pricing