FullStack AI Hub
Studio
System Design · 09. Whole Systems
14 min
12 steps
Intermediate

Design a News Feed

Combine fan-out on write, feed caches, and hybrid celebrity merging for 200M daily users.

System Design09. Whole SystemsLesson 2 of 4
14 minIntermediate12 steps

Design a News Feed

Combine fan-out on write, feed caches, and hybrid celebrity merging for 200M daily users.

DAILY USERS
200M
FEEDS / SEC
23,000/s
DB LOOKUPS / S
—
P95 FEED LOAD
< 200 ms
Mobile App20%200M DAUWeb Client16%API Gateway28%Posts DB24%Follow Graph22%REQUIREMENTSPostshort text + mediaFeedposts from followed acctsScale200M DAU · 200 followsBudgetP95 < 200 ms
feed open (read)
new post / fan-out
celebrity burst
backlog / timeout
In This LessonStep 1 of 12
What You Will Master
  • ✓Estimate read/write QPS and expose why pull-time joins collapse at scale
  • ✓Precompute per-user home timelines with asynchronous fan-out workers
  • ✓Diagnose why 50M-follower accounts overwhelm pure fan-out on write
  • ✓Combine precomputed timelines with read-time celebrity merging (Hybrid Fan-Out)

Architectural Trade-Off Comparison Matrix

PatternBest ForKey Trade-Off
Fan-Out on Read (Pull)Small apps or celebrity accounts (>10k followers) with huge fan-out costsEvery feed open queries N followed authors (4.6M lookups/s at 200M DAU)
Fan-Out on Write (Push)99.9% of regular users—delivers O(1) Redis timeline reads in < 40 msPure push explodes into 50M cache writes when a mega-celebrity posts
Hybrid Celebrity MergeGlobal social feeds combining push for normal users + read-time merge for ~3 celebsRequires tracking celebrity threshold flags and merging sorted ID lists in memory
ID Hydration + Cursor PagingConsistent post edits/deletes, edge CDN media offload, and zero scroll duplicatesNeeds a fast MGET object cache and opaque cursor tokens instead of OFFSET

Step-by-Step Architectural Breakdown (12 Steps)

Full architectural walkthrough transcript and state transitions for Design a News Feed.

STEP 01 · SETUPJump to step →

Define the product & scale

We are designing a social **News Feed** where users publish short posts and open a reverse-chronological home timeline of everyone they follow.

Target scale: **200M daily active users**, each opening their feed ~10 times per day and following an average of **200 accounts**. Feed opens must feel instant—under **200 ms** at P95.

idea:News feeds are overwhelmingly read-heavy: users open their feed 50×–100× more often than they publish a post.

Functional RequirementsRead-Heavy WorkloadLatency Budget
STEP 02 · SETUPJump to step →

Back-of-the-envelope math

Before picking an architecture, run the numbers: `200M users × 10 feed opens / 86,400 seconds` equals roughly **23,000 feed opens/sec** on average (and 3× higher at evening peaks).

Meanwhile, if 10% of users publish 1 post a day, writes are only **~230 posts/sec**. That 100:1 read-to-write ratio is our biggest architectural clue.

good:Rapid math exposes the real bottleneck early: optimizing writes while ignoring 23,000 reads/s will sink the system.

Back-of-the-Envelope EstimationRead-to-Write Ratio
STEP 03 · TECHNIQUEJump to step →

Attempt 1: Fan-out on Read (Pull)

In the naive **Pull Model** (fan-out on read), publishing a post is cheap—just write one row to `Posts DB`.

When a user opens the app, **Feed Service** fetches their list of 200 followed IDs from `Follow Graph`, queries `Posts DB` for recent posts from all 200 authors, sorts them by timestamp, and returns the top 20.

idea:Pull is dead simple for tiny apps, because you never duplicate feed data or pay background write costs.

Fan-Out on ReadPull ModelRead-Time Join
STEP 04 · SOLUTIONJump to step →

Attempt 2: Fan-out on Write (Push)

Because reads outnumber writes 100-to-1, we flip the work from read time to write time. When Alice publishes a post, a **Fan-out Worker** looks up her followers and pushes the `post_id` into each follower’s **precomputed Feed Cache**.

Now opening a feed is a single **O(1) Redis read** (`LRANGE feed:bob 0 20`) instead of 200 database queries. Feed load drops from **1,850 ms** down to **38 ms**.

good:Store only lightweight post IDs (8 bytes each) inside the Redis timeline cache, then hydrate full post bodies from a shared post cache.

Fan-Out on WritePush ModelPrecomputed Timeline Cache
STEP 05 · TECHNIQUEJump to step →

Decouple publishing with a Message Queue

We never want an author’s "Post" button to hang while pushing IDs into thousands of follower timelines. Instead, **Post Service** writes the post to `Posts DB`, enqueues a `PostCreated` event onto a **Message Queue**, and returns `201 Created` immediately.

A fleet of stateless **Fan-out Workers** drains the queue asynchronously, smoothing out traffic bursts without blocking publishers.

idea:Asymmetry of expectations: authors expect instant publish confirmation, while followers never notice a 1-second delivery delay.

Asynchronous Fan-OutMessage Queue DecouplingEventual Consistency
STEP 06 · PROBLEMJump to step →

The 50M-follower celebrity crash

Everything hums—until a global pop star with **50 million followers** posts a single photo. Pure fan-out on write tries to push 50,000,000 cache entries for that one post!

The **Fan-out Queue** explodes to a massive backlog, **Fan-out Workers** pin at **100% CPU**, and ordinary users wait **12 minutes** for their friends’ posts to appear.

watch:This is the classic "hotkey fan-out storm": a single celebrity post generates as many cache writes as 250,000 ordinary users combined.

Celebrity Fan-Out StormWrite AmplificationQueue Backlog
STEP 07 · TECHNIQUEJump to step →

Skip inactive users during fan-out

Before we solve celebrities completely, we grab a huge win: why push posts into Redis for users who have not opened the app in 30 days?

By filtering fan-out targets to **active users only** (and building timelines lazily if a dormant user returns), we cut memory usage and fan-out work by more than half.

good:Active-user pruning shrinks Redis RAM spend dramatically—only keep precomputed timelines for users active in the last 7–14 days.

Active User FilteringLazy Cache HydrationMemory Efficiency
STEP 08 · SOLUTIONJump to step →

Split authors by follower threshold

The real breakthrough is the **Hybrid Fan-Out** model. We tag any account with more than **10,000 followers** (typically < 0.1% of accounts) as a **Celebrity**.

Regular users continue using fast **fan-out on write**. Celebrities are **skipped** by the fan-out workers completely—their posts sit cleanly in a tiny **Celebrity Posts Cache**.

idea:Skipping just the top 0.1% of high-follower accounts eliminates over 90% of peak fan-out write amplification.

Hybrid Fan-OutFollower ThresholdCelebrity Posts Cache
STEP 09 · SOLUTIONJump to step →

Merge at read time: my list + 3 celebrities

Now watch a reader open their feed: **Feed Aggregator** grabs the user’s precomputed **Feed Cache** (regular friends) in 1 call, plus the recent posts of the **3 celebrities** they follow from **Celebrity Cache**.

It merges those 4 tiny sorted lists in memory in under 2 ms and returns a unified timeline. Total read latency stays at **52 ms** with zero fan-out storms.

good:Hybrid fan-out gets the best of both worlds: O(1) push for 99.9% of authors and tiny bounded pull for mega-accounts.

Read-Time MergeK-Way Sorted MergeHybrid Timeline
STEP 10 · TECHNIQUEJump to step →

Hydrate posts & offload media to a CDN

Our merged timeline only contains 20 integer `post_id`s. Before returning JSON to the app, **Feed Aggregator** batch-fetches post text and author profiles from a shared **Object Cache** (`MGET`).

Images and videos never touch your application servers—every media URL points directly to edge **CDN** nodes close to the user.

idea:Keeping timelines as ID lists means if an author edits a typo or deletes a post, you update one cached object rather than millions of feeds.

Object HydrationEdge CDN OffloadPost ID Normalization
STEP 11 · TRADE-OFFJump to step →

Cursor pagination & ranking stage

Offset pagination (`OFFSET 40`) breaks as soon as new posts arrive at the top of the feed—causing users to see duplicate items while scrolling. Instead, we pass an opaque **cursor** (`before_post_id`) to slice deterministically.

If the product shifts from chronological to algorithmic ranking, a lightweight **Ranker** scores the top ~200 candidate IDs right after the hybrid merge.

watch:Algorithmic ranking adds 20–40 ms of inference time—keep the candidate pool tight (~200 posts) and cache ranked pages briefly.

Cursor PaginationCandidate GenerationFeed Ranking
STEP 12 · RECAPJump to step →

News Feed architecture recap

We started from rapid math (**23,000 feeds/s** vs **230 posts/s**), watched pure pull collapse under **4.6M lookups/s**, and saw pure push stall when a **50M-follower celebrity** posted.

The production answer is **Hybrid Fan-Out**: asynchronous push for regular users, read-time merge for celebrities, ID-based object hydration, edge CDN media delivery, and cursor pagination—hitting **94 ms P95** cleanly.

good:Interview formula: quantify the read/write ratio first, propose Push vs Pull, surface the celebrity edge case, then land on Hybrid Fan-Out.

News Feed ArchitectureEnd-to-End System Design

Related Production Deep-Dives & Simulators

Included In Free Course
Free · Verifiable Credential

FS-102LLM Systems Foundations

Build a connected mental model from tokens through retrieval evaluation security and operations.

24 concepts~18h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.