System DesignOct 1, 2026⏱️ 2 min read
Design a News Feed System: Fanout-on-Write vs Fanout-on-Read & Celebrity Hybrid

Design a News Feed System: Fanout-on-Write vs Fanout-on-Read & Celebrity Hybrid

The Core Challenge: Merging Timelines in < 100ms

Imagine 10 million DAU where a user follows 500 friends. Querying and sorting the latest posts across 500 followed accounts dynamically in SQL (WHERE user_id IN (...) ORDER BY created_at DESC LIMIT 20) collapses immediately under load.
Instead, feed systems balance pre-computation against read-time assembly using Fanout.
News Feed Hybrid Fanout Architecture

News Feed Hybrid Fanout Architecture


1. Fanout-on-Write (Push) vs. Fanout-on-Read (Pull)

Fanout-on-Write (Push Model)

When Alice publishes a post, background workers fetch Alice's follower IDs from the Graph DB and push post_id directly into every active follower's pre-computed Redis News Feed list.
  • Pro: Reading a home timeline is an $O(1)$ Redis lookup (LRANGE feed:user_123 0 20)—blazingly fast!
  • Con (The Celebrity Problem): If a celebrity with 50 million followers posts a photo, pushing post_id into 50M Redis keys triggers a massive write storm and lags minutes behind! And wasting RAM for inactive users who haven't logged in for months burns budget.

Fanout-on-Read (Pull Model)

No pre-computation happens at write time. When Bob opens the app, the feed service fetches posts from everyone Bob follows and merges them on the fly.
  • Pro: Zero write amplification; works cleanly for celebrities and saves RAM for inactive users.
  • Con: Slow feed reads when following hundreds/thousands of users.

2. The Production Answer: Hybrid Fanout

Production social networks combine both strategies:
  1. Normal Users (< 10K followers): Use Fanout-on-Write (Push) into Redis sorted lists of post_ids (only for active users logged in within the last 30 days).
  2. Celebrities / Mega-Accounts (> 10K followers): Do NOT push to follower caches. Keep their posts in their own user timeline cache.
  3. Feed Read Time: Fetch the user's pre-computed pushed feed from Redis (20 IDs), pull recent posts from the few celebrities they follow, merge/rank them in memory, and hydrate post text/media!

3. Keeping Feed Memory Lean: Store IDs, Not Full Payloads

Redis News Feed Cache:  user:42:feed  ──►  [(post_991, ts_1), (post_840, ts_2), ...]
                                                    │
Hydration Cache:        post:991      ──►  { text, media_cdn_url, author_id }
                        user:7        ──►  { username, avatar_cdn_url }
Never duplicate full post JSON across millions of follower lists. Store lightweight (post_id, user_id) tuples in the feed cache and batch-hydrate post & author metadata (MGET) on read!

Share this article

Comments