DBRaven
Twitter

Twitter Timeline Fan-Out Architecture

Twitter's timeline system collapsed under pure fan-out-on-write at celebrity follower counts, forcing a hybrid model where high-follower accounts are merged at read time into precomputed follower timelines: trading read-path complexity for write-path tractability.

Social Platform

Twitter's timeline delivery architecture underwent a fundamental inversion between 2012 and 2014. The original model pre-computed every follower's home timeline on each tweet: when a user tweeted, a Flock worker fanned out the tweet ID to every follower's timeline cache in Redis. This is optimal for ordinary users but collapses for accounts with tens of millions of followers: a single tweet from Lady Gaga (40M followers in 2012) required writing to 40 million Redis sorted set entries before the tweet was visible to any follower. Twitter introduced a hybrid model: most users receive eager fan-out at write time, but accounts above a follower threshold (~1 million) are excluded from precomputed fan-out. When a follower loads their timeline, the system performs a read-time merge of their precomputed timeline with real-time queries for the high-follower accounts they follow. The result is a mixed read/write cost distribution calibrated to actual account topology.

Scale at Decision Point

Users

200 million monthly active users; ~500 million tweets per day in 2012

Data Volume

Timeline cache in Redis covering hundreds of millions of user timelines; ~800 tweets per second ingest rate

Request Rate

~300,000 timeline reads per second; fan-out workers processing millions of writes per second during tweet spikes

Redis clusters storing timelines as sorted sets by tweet timestamp; Flock service for social graph; Manhattan (Twitter's distributed key-value store) for persistent tweet storage

Architecture Evolution

Initial Architecture

Pure fan-out-on-write model: when a tweet is created, a fleet of Flock workers walks the social graph and writes the tweet ID to every follower's timeline cache in Redis. Timeline reads are O(1): return the pre-populated sorted set. The model is read-optimal but write-amplified by the follower count. For ordinary users (median ~200 followers), fan-out of a single tweet requires ~200 Redis writes. For celebrities with 40M followers, a single tweet requires 40 million writes that must complete before the tweet is considered delivered.

rediskafka
  • Fan-out latency for high-follower accounts can take minutes: tweet not visible to followers until fan-out completes
  • A single tweet from a celebrity triggers a write spike that can saturate the Redis fan-out worker fleet
  • Redis storage grows proportionally to follower count * active users * timeline depth
  • Unfollow operations require deleting tweet IDs from the follower's timeline cache: expensive at high follower counts

Evolved Architecture

Hybrid fan-out model with a follower-count threshold (approximately 1 million followers). Accounts below the threshold receive standard eager fan-out: their tweet IDs are written to all followers' Redis timeline caches at write time. Accounts above the threshold (designated as high-value producers, internally referred to as having a special account classification) are excluded from precomputed fan-out. At read time, the timeline service performs a merge: it retrieves the follower's precomputed timeline from Redis and executes a real-time fan-in query for the high-follower accounts the user follows, merging and sorting the results by timestamp before delivery. The merge is bounded because users typically follow fewer than 10 celebrity accounts, limiting the read-time overhead.

rediskafka
  • Timeline read path now involves a conditional merge step: latency higher for users following many high-follower accounts
  • Threshold logic creates an edge case: an account that crosses the follower threshold must have its fan-out model switched without timeline gaps
  • Read-time celebrity merge adds latency during celebrity posting spikes: all followers load timelines simultaneously
  • System complexity increased: two fan-out code paths must be maintained and tested

Key Transitions

2012Discovery of fan-out collapse at celebrity follower scale

Trigger

Incidents during high-profile events (award shows, sporting events) revealed that celebrity tweets created cascading write saturation in the Flock fan-out workers. A single tweet from a 40M-follower account triggered 40 million Redis ZADD operations, taking 5-10 minutes to complete fan-out propagation. During this window, followers saw a timeline that did not include the tweet: a visible product defect during precisely the moments of highest engagement.

Before

Pure fan-out-on-write for all accounts regardless of follower count

After

Investigation phase; fan-out bottleneck identified and documented internally

Outcome

Internal recognition that pure fan-out-on-write has a fundamental ceiling at celebrity follower counts. Architecture team began designing the hybrid model.

Lessons

  • Write amplification from fan-out grows linearly with follower count: there is no optimization that avoids this at 10M+ followers
  • High-engagement moments (live events) create coordinated write spikes that compound the fan-out problem
2013Hybrid fan-out: eager writes for regular users, read-time merge for celebrities

Trigger

Product commitment to sub-second timeline delivery for all users regardless of which celebrity accounts they follow. The engineering team needed a model that bounded write amplification without degrading read latency for followers of high-follower accounts.

Before

Pure fan-out-on-write causing multi-minute delivery delays for celebrity tweets

After

Hybrid model: follower-count threshold determines write-time vs read-time fan-out strategy

Outcome

Celebrity tweet delivery latency dropped from minutes to sub-second for followers. Write amplification from high-follower accounts was bounded. Read path for users following celebrities added ~20ms of merge overhead: acceptable given the improvement to write-side scaling. The hybrid model was presented at QCon 2013 and became a well-cited reference architecture for social feed systems.

Lessons

  • Fan-out-on-read is only viable when the number of high-follower sources per user is small: users follow few celebrities, making the read-time merge bounded
  • The threshold for switching from write-time to read-time fan-out is an empirical question: Twitter's ~1M follower threshold reflects their specific infrastructure cost curve
  • Hybrid models require careful handling of accounts that cross the threshold: a gradual migration or snapshot-based approach avoids timeline gaps
2014Timeline service extraction and social graph decoupling

Trigger

Timeline delivery logic had become coupled to the social graph service (Flock), making it difficult to optimize timeline construction independently. Separating the timeline service allowed independent scaling of graph traversal and timeline cache management.

Before

Timeline fan-out tightly coupled to Flock social graph service

After

Dedicated timeline service with its own cache layer; Flock provides graph queries on demand

Outcome

Timeline read path now independently scalable from social graph write path. Flock's graph mutation load (follows/unfollows) no longer competes with timeline cache read traffic.

Lessons

  • Social graph queries and timeline cache management have different scaling properties: separating them enables independent optimization
  • Write path (graph mutations) and read path (timeline delivery) should be independently deployable services in a social platform at scale

Key Lessons

Fan-out-on-write breaks at celebrity follower scale; the threshold is between 100K and 1M followers depending on infrastructure cost

The economics of fan-out-on-write depend on write cost per follower and read traffic per timeline. For ordinary users, pre-computing timelines is efficient because each user's followers see their tweet at low marginal cost. At celebrity scale, a single tweet requires millions of writes that must complete synchronously : the write cost exceeds any read-side savings. Twitter's threshold of approximately 1 million followers reflects the point where the write cost curve crosses the read-side merge cost curve.

Applicable when: You are building a social feed system and need to select a fan-out strategy for accounts with highly asymmetric follower distributions

Hybrid fan-out is only tractable when high-follower sources per user is bounded

The read-time merge for celebrity accounts is bounded by how many high-follower accounts a given user follows. Typical users follow 2-5 celebrity accounts. If users regularly followed 100 celebrity accounts, the read-time merge would be computationally expensive. The model works because follow distributions are asymmetric: most users follow few celebrities.

Applicable when: You are evaluating fan-out-on-read and need to estimate read path overhead per timeline request

Write spikes from social events are temporally correlated: fan-out infrastructure must handle burst multipliers of 10-50x

Award ceremonies, sporting events, and breaking news create coordinated tweet storms where thousands of high-follower accounts post simultaneously. Fan-out infrastructure must be provisioned for these burst multipliers, not average load. The hybrid model reduces burst severity by limiting write amplification for the highest-follower accounts.

Applicable when: You are capacity planning a social platform that will experience correlated write spikes during live events

Related Scenarios

Sources

3 sources are pending verification and have been hidden until a followable citation is available.