SD System Design In Depth
0%
design system-designfeedssocial-network

Design: a social feed

Module 6.2: Interactive Product System Designs Updated Sep 18, 2026
📄 Cheat Sheet
Design FB News Feed System Design Interview w/ ex: Meta Senior Manager
Hello Interview Design FB News Feed System Design Interview w/ ex: Meta Senior Manager Watch on YouTube ↗

Compact, focused treatment of fan-out on write vs read and the hybrid for high-follower accounts, which is the core dilemma of this lesson.

0:00 / --:--

The Core Architectural Dilemma: Fan-out on Write vs. Fan-out on Read

When designing news feeds (Twitter/X, Facebook, LinkedIn), the fundamental architectural choice is how and when to assemble the timeline for each user.

flowchart TD Author["Author Posts Tweet"] --> Router{"Fan-out Strategy"} Router -->|Regular User| FanoutWrite["Fan-out on Write: Push to all followers' timeline caches"] Router -->|Celebrity / High Follower| FanoutRead["Fan-out on Read: Store in author's tweet list only"] FanoutWrite --> Cache[("Redis Timeline Caches")] Consumer["User opens feed"] --> Merge["Timeline Merger Service"] Cache --> Merge FanoutRead --> Merge Merge --> Feed["Ranked Home Feed"]

Fan-out on Write (Push Model)

When a user posts a status update, a background worker looks up all followers and immediately injects the post ID into each follower's pre-computed in-memory feed cache (e.g., Redis List or sorted set):

  • Pros: Generating the timeline when a user opens the app is virtually instant (O(1) read from Redis cache).
  • Cons: Severe write amplification. If a celebrity with 80 million followers posts, the system must perform 80 million cache writes, overloading background queues.

Fan-out on Read (Pull Model)

Posts are only written to the author's own timeline. When a follower opens their home feed, the system queries the latest posts of everyone they follow and merges them dynamically:

  • Pros: Writes are constant time O(1). No write amplification for celebrities.
  • Cons: Read latency is high; fetching and merging posts from hundreds of followed accounts on every feed refresh causes database and CPU bottlenecks.

The Production Hybrid Solution

Modern social networks implement a hybrid fan-out model:

  • Standard users (e.g., < 25,000 followers) use Fan-out on Write, pre-populating followers' Redis feeds.
  • Celebrity accounts (e.g., > 25,000 followers) bypass fan-out on write. Instead, when a follower views their feed, the system fetches the celebrity's recent posts and merges them into the cached timeline in real time.

Worked example: write amplification

  • 200 million daily active users, 40 million posts per day, and an average of 300 followers per author gives 12 billion timeline inserts per day, about 140,000 per second on average and perhaps 500,000 at peak. That is manageable across a Redis fleet.
  • A single account with 80 million followers would add 80 million inserts for one post, taking minutes even at 500,000 per second. That is why the hybrid threshold exists.
  • Timeline memory: if each of 200 million users keeps 800 IDs at 8 B, that is about 1.3 TB of raw IDs, perhaps 3 to 4 TB with Redis overhead. Caching only active users, and capping lists (Twitter publicly described keeping about 800 entries per home timeline), keeps this bounded.

Strategy comparison

StrategyPost costFeed-read costFreshnessWeak spot
Push (fan-out on write)One insert per followerOne range read plus hydrationSeconds of fan-out lagCelebrities, deletes (must also be fanned out)
Pull (fan-out on read)One insertRead N followees and k-way mergeImmediateUsers who follow many accounts; expensive at read time
HybridPush for ordinary authors, skip for big onesCached timeline plus a merge of a few celebrity listsGoodMore complex; the threshold needs tuning
Ranked feed (Facebook, Instagram)Candidates indexed per authorGather thousands of candidates, then ML rankingGoodRanking latency and cost

Read path for the hybrid

flowchart LR R["Open feed"] --> T[("Home timeline cache: pushed IDs")] R --> C["Followed celebrity list"] C --> CP[("Recent posts per celebrity")] T --> M["Merge by score, dedupe"] CP --> M M --> H["Hydrate posts, authors and counts in batches"] H --> F["Filter blocked or deleted posts, then rank"] F --> P["Page of 20 plus a cursor"]

Meta's ranked News Feed gathers candidates from followed sources at read time and scores them with ML models. That is closer to "pull plus ranking" than to a pure pushed list, because the ordering depends on the viewer and the moment. Twitter's classic home timeline was mostly push into Redis, with celebrity tweets merged at read time.

Check yourself Question 1 of 3
Push model weak spot recall
From: Fan-out on Write (Push Model)

In a pure fan-out-on-write feed, what happens when an account with 80 million followers posts?

Feed Fan-out Calculator

Push Model (Write Fan-out)

Writes/sec: 0

Reads/sec: 0

Pull Model (Read Fan-out)

Writes/sec: 0

Read Amplification: High (Compute intensive)

Key Takeaways

Understand the classic trade-off: Fan-out on Write (fast reads, heavy writes) vs Fan-out on Read (fast writes, slow reads).
Employ a hybrid approach: push regular user updates to followers' Redis caches, but pull celebrity updates dynamically on read.
Cap pre-computed timeline lengths (e.g., latest 800 tweet IDs) to control cache memory footprint.
Store only post IDs in timeline caches and hydrate post text, images, and user profiles in a single batched multi-get.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue