💬
✉️
📸
▶️

Loading…

Design Twitter: feed fanout and timeline system design

TwitterGuided Mode

Hybrid: Solving the Celebrity Problem

@elonmusk has 170M followers — pure push would require 170M Redis writes per tweet. The hybrid Feed Service skips fanout for celebrity accounts. On read, it merges the pre-built cache with live celebrity posts.

Request Flow

1

Celebrity posts — no fanout

The Feed Service checks follower count. Above the threshold, the tweet is written only to the Database. No cache writes, no queue job.

// On POST /tweet:
if (author.followerCount > CELEBRITY_THRESHOLD) {
  db.insert(tweet);
  return; // no fanout
}
// Regular user: proceed with push fanout
2

Merge on read

When @alice loads her timeline, the Feed Service fetches her pre-built Cache (regular follows) AND queries the Database for recent celebrity posts, then merges.

GET /timeline:
1. cache = LRANGE timeline:alice 0 99
2. celebPosts = db.recentPosts(
     alice.celeb_follows
   )
3. return merge_sort(cache, celebPosts).slice(0, 20)

Why We Need This

The hybrid approach cut Twitter's write amplification by an estimated 40%. It also reduced Redis write pressure during viral moments from celebrity accounts.

Key Insight

The hybrid model is the state of the art for feed systems. Regular users get push-based O(1) reads. Celebrity content is fetched on demand and merged. The threshold between push and pull is the single most important tuning parameter in the system.

Step 6 of 6