Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Design a Global Social Media Newsfeed
& Timeline Engine (300M DAU).

Design a 300M DAU social media newsfeed and timeline engine supporting 200K RPS feed reads (<150ms p99), 50M-follower celebrity posts, two-stage ML ranking, and duplicate-free cursor pagination.
Start the journey7 stages· Last modified Nov 24, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

To keep the architecture evolvable without sacrificing reliability, separate ingestion (Kafka partitioned by AuthorID + Media CDN) from Hybrid Fan-Out (active-only Redis ZSETs + Celebrity Pull Cache), Two-Stage ML Ranking, and Snapshot Cursor Pagination.

TL;DR30-second simplified summary
▾

At 200K peak read RPS, media uploads go straight to S3/CDN while Kafka partitioned by author_id drives Hybrid Fan-Out across a 100K-follower threshold. Only 150M recently active users hold 800-item Redis ZSET inboxes (~2TB RAM).

Feed reads merge push inboxes, celebrity pulls, and out-of-network ANN candidates, hydrating via Redis MGET before <40ms LightGBM/DNN scoring with chronological timeout fallback.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Social Newsfeed Hybrid Fan-Out & Ranking
Hybrid newsfeed fan-out combines Fan-Out-on-Write (pushing post IDs to follower Redis timelines for normal users) with Fan-Out-on-Read (pulling celebrity posts at read time), followed by two-stage ML ranking and diversity deduplication.
Full walkthrough · 7 stages
01
foundation

300M DAU Capacity Sizing & Redis Inbox Memory.

Why this matters: Calculate read/write QPS, Kafka fan-out throughput, and Redis RAM for active inboxes.

300M DAU * 10 feed loads/day = 3B reads/day (~35K avg, ~200K peak RPS).

At 10K peak post writes/sec with avg 200 active followers, push fan-out generates ~2M Redis ZADD ops/sec.

Stage 1 - Capacity Model

300M DAU & 2TB Redis Inbox Sizing

300M DAUsource10K Post Writes/sprocessor2 TB Redis Clustercache<150ms p99 FeedsinkAsync ZADD fan-out

1.Active-Only Savings: Skipping 150M dormant accounts saves ~2TB of Redis RAM; dormant users fall back to DB merge.

2.Pipelined ZADD: Batch 100 ZADDs per Redis pipeline to cut network syscall overhead by 100x.

Sizing active-user Redis inboxes at ~2TB makes precomputed timelines economical at 300M DAU.

02
foundation

Post Ingestion, Media CDN & Author-Partitioned Kafka.

Why this matters: Decouple heavy image/video uploads from lightweight timeline fan-out events.

Think of Post Ingestion, Media CDN & Author-Partitioned Kafka as the intuition layer for Design a Global Social Media Newsfeed & Timeline Engine (300M DAU): Decouple heavy image/video uploads from lightweight timeline fan-out events.

Clients upload images/videos directly to S3 via presigned URLs served behind CloudFront/Cloudflare CDN. The API Gateway validates the post, persists metadata to sharded Cassandra/MySQL (posts partitioned by post_id, author_timeline partitioned by author_id), and publishes a tiny PostCreated event to Kafka partitioned by author_id.

Stage 2 - Post Ingestion

Media CDN + Author-Partitioned Kafka

Mobile WritersourceMedia CDNcacheSharded Post StorestorageKafka (by AuthorID)processorPersist post metadata

1.Presigned Uploads: Keep multi-megabyte media bytes completely off the API/Kafka path.

2.Per-Author Ordering: Partitioning Kafka by author_id preserves chronological order per creator.

Direct-to-CDN media uploads keep the ingestion and Kafka fan-out path ultra-lightweight.

Engineering Decision Framework
Problem
How to implement Design a Global Social Media Newsfeed & Timeline Engine (300M DAU) without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
To keep the architecture evolvable without sacrificing reliability, separate ingestion (Kafka partitioned by AuthorID + Media CDN) from Hybrid Fan-Out (active-only Redis ZSETs + Celebrity Pull Cache), Two-Stage ML Ranking, and Snapshot Cursor Pagination.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Design a Global Social Media Newsfeed & Timeline Engine (300M DAU) experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
intermediate

Social Graph Service & Hybrid Fan-Out Workers.

Why this matters: Route normal vs. celebrity posts dynamically using sharded follower adjacency lists.

Fan-Out Workers query the Social Graph Service (sharded Redis/TAO-style graph cache backed by MySQL/Cassandra) for the author's follower_count and active follower IDs.

Authors < 100K followers fan out to follower Redis ZSETs (ZADD + ZREMRANGEBYRANK cap 800).

Stage 3 - Hybrid Fan-Out

Social Graph + Push/Pull Split

Kafka ConsumersourceSocial Graph ServicecachePush Workers(<100K)processorCelebrity Cache(>=100K)storage<100K -> fan-out

1.Dead-Letter Isolation: Route mega-fanout retries to a separate Kafka DLQ so one glitch doesn't stall normal posts.

2.Graph Caching: Cache follower lists in Redis/TAO with write-through invalidation on follow/unfollow.

Social Graph caching and threshold splitting keep fan-out workers fast under celebrity bursts.

04
intermediate

Two-Stage Feed Hydrator & Feature Store.

Why this matters: Merge push inboxes, celebrity pulls, and out-of-network candidates under 40ms.

Think of Two-Stage Feed Hydrator & Feature Store as the intuition layer for Design a Global Social Media Newsfeed & Timeline Engine (300M DAU): Merge push inboxes, celebrity pulls, and out-of-network candidates under 40ms.

On GET /v1/feed, the Timeline Service fetches the user's inbox ZSET (top 400), pulls top 50 posts from followed celebrities, and queries an ANN vector index for 200 out-of-network 'For You' posts. The Hydrator runs parallel Redis MGETs for post/author objects, filters blocked_authors, and fetches user-author affinity features from a Redis Feature Store.

Stage 4 - Merge & Hydrate

Three-Source Candidate Merge & Hydration

User Inbox ZSETcacheCelebrity Pull MergeprocessorOut-of-Network ANNstorageBatch MGET +FeaturessinkMerge celebrity IDs

1.Timeout Budgets: Set a hard 25ms timeout on out-of-network ANN; serve in-network feed if ANN lags.

2.Parallel Scatter: Execute inbox, celebrity, and OON fetches concurrently in one fan-out.

Parallel candidate fetching and batched MGET hydration assemble 650+ candidates in <40ms.

05
intermediate

LightGBM / Two-Tower ML Ranker & Diversity Pass.

Why this matters: Maximize user engagement while enforcing author diversity and fallback safety.

Think of LightGBM / Two-Tower ML Ranker & Diversity Pass as the intuition layer for Design a Global Social Media Newsfeed & Timeline Engine (300M DAU): Maximize user engagement while enforcing author diversity and fallback safety.

The ML Ranking Service (GPU/CPU Triton inference) scores the ~650 hydrated candidates using LightGBM or a multi-task Deep Neural Network predicting P(click), P(like), P(repost), and P(negative_feedback). A Diversity Re-Ranker applies exponential author-repeat decay (0.5^k) and injects sponsored slots before returning the ranked list.

Stage 5 - ML Ranking

Triton ML Scorer & Diversity Re-Ranker

650 Hydrated PostssourceTriton ML RankerprocessorDiversity Re-RankerrouterChrono FallbacksinkSpace out authors

1.Batch Inference: Score all 650 candidates in one vectorized Triton batch rather than per-item RPCs.

2.Explainable Weights: Keep engagement-vs-recency weights configurable via dynamic experiment flags.

Vectorized Triton scoring and author-decay re-ranking deliver personalized feeds in <40ms.

06
advanced

Seen-Post Bloom Filter & Snapshot Cursor Pagination.

Why this matters: Eliminate already-viewed posts and guarantee smooth, duplicate-free infinite scroll.

Think of Seen-Post Bloom Filter & Snapshot Cursor Pagination as the intuition layer for Design a Global Social Media Newsfeed & Timeline Engine (300M DAU): Eliminate already-viewed posts and guarantee smooth, duplicate-free infinite scroll.

To avoid showing posts the user scrolled past 10 minutes ago, the Feed Service checks a per-user 7-day Seen-Post Bloom Filter (~2KB per active user in Redis, updated asynchronously by client viewport beacons). The final ranked list is stored as a 10-minute Feed Snapshot in Redis, returning an opaque Base64 cursor for instant <5ms page 2..N slices.

Stage 6 - Seen & Scroll

Seen-Post Bloom + 10m Feed Snapshot

Ranked 300 PostssourcePer-User Seen Bloomrouter10m Redis SnapshotcacheOpaque Cursor PagesinkSave session snapshot

1.Rotating Daily Blooms: Use 7 daily 300-byte Bloom filters per user so old seen history expires cleanly.

2.Zero ML on Scroll: Paging down slices the cached snapshot without re-invoking Triton.

Per-user rotating Bloom filters and 10m feed snapshots make infinite scroll fast and duplicate-free.

07
advanced

Multi-Region Active-Active & Live Streaming Updates.

Why this matters: Scale globally across continents and push real-time 'New Posts' pills to active clients.

Think of Multi-Region Active-Active & Live Streaming Updates as the intuition layer for Design a Global Social Media Newsfeed & Timeline Engine (300M DAU): Scale globally across continents and push real-time 'New Posts' pills to active clients.

Each region hosts full Read/Cache/ML stacks with local Redis clusters and async cross-region Cassandra/Kafka replication for posts and social graph edges. For users actively viewing the top of their feed, lightweight SSE/WebSocket gateways subscribe to followed-author Redis Pub/Sub channels to display a non-disruptive '3 new posts' pill without jumping the scroll position.

Stage 7 - Global & Real-Time

Multi-Region Stacks & Live Pill Gateway

US Feed StackprocessorEU Feed StackprocessorCross-Region SyncstorageSSE New-Post PillsinkUpdate EU caches

1.No Scroll Jumps: Never auto-prepend live posts while a user is reading; show a tappable pill instead.

2.Regional Isolation: Local Redis/Triton stacks keep feed reads <150ms even during WAN degradation.

Regionalized read/ML stacks and non-disruptive live pills complete a global 300M-DAU timeline.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

How does caching a 150M-active-user Redis inbox tier (rather than all 300M+ registered accounts) affect system cost and correctness?

Recommended Learning Flow