Dashboard/System design/33. Design Newsfeed System

SYSTEM DESIGN · LESSON 33 OF 52 · 14 MIN VIDEO · 1 TOPICS

Design Newsfeed System

Module Progress (0 / 1 Lessons Completed)0%
System design Track (0 / 52 Modules) · Overall 0/80 (0%)0%
⌁

Narrated HD Video Lesson (14 min) · Pro

Lesson Overview + Section #01 + RESHADED Checklist + Quiz #1 are unlocked free below (no login required). Unlock all 80 HD video lessons and deep-dive sections — or watch our two free sample video lessons first.

0% READSec 01/01 · System Design: Newsfeed System
SYSTEM DESIGN VIDEO LESSON & GUIDE

Design Newsfeed System

Designing a planetary-scale Newsfeed System (such as Facebook or LinkedIn) requires aggregating posts from heterogeneous sources—friends, groups, and public pages—into a personalized, ML-ranked stream for 1,000,000,000 daily active users (2,000,000,000 total users). Under an extreme 50:1 read-to-write asymmetry (116,000 feed loads/sec versus 2,300 new posts/sec), computing ranked feeds from disk on demand is infeasible. L4–L6 interviewers evaluate how candidates bound in-memory Feed Cache footprints (1.6 TB for 1B active users), isolate background feed generation from low-latency feed publishing, balance hybrid push/pull fan-out across 50M-follower pages, and implement two-stage relevance ranking.

WHAT YOU WILL MASTER IN THIS LESSON
  • Derive end-to-end capacity and RAM sizing under a 50:1 read-to-write workload (116K RPS reads, 2.3K RPS writes, 20 TB/day media, and 1.6 TB Feed Cache holding 200 8-byte post IDs per active user).
  • Architect decoupled Post Ingestion, Feed Generation, and Feed Publishing tiers backed by polyglot persistence (SQL, sharded KV, Graph DB, Blob/CDN, and Redis).
  • Combine hybrid fan-out (pushing to recently active friends while pulling 50M-follower pages at read time) with multi-signal relevance ranking (Affinity * Weight * Freshness evolving to two-stage ML).
  • Deliver cursor-paginated feeds from memory in < 200 ms alongside lightweight long-polling new-post notifications and pull-based cache-miss fallbacks.
SYSTEMATIC INTERVIEW CHECKLIST · RESHADED + 45-MIN CLOCK

8-Step RESHADED Execution Checklist

Follow this exact sequence from the Intro narration on every system design prompt so you never miss requirements, math, contracts, or the 13-minute deep dive.

0 / 8 Checked
INTERVIEWER SCORECARD · WHAT MAKES A STRONG HIRE?

5 Signals Bar Raisers Grade (L4 vs. L5 Senior vs. L6 Staff)

Senior (L5 / E5 / Senior SDE) Bar — Autonomous Pacing, Depth & Proactive Trade-Offs: Owns the 45-minute clock without prompting, derives every component quantitatively, surfaces failure modes (hot shards, stampedes, dual writes) BEFORE being asked, and defends consistency vs. latency trade-offs.
1. Scoping
✓ STRONG HIRE SIGNAL

Clarifies users, read/write skew, p99 latency, consistency bounds, and explicit non-goals in minutes 2–8.

✗ NO-HIRE RED FLAG

Jumps straight into drawing load balancers and microservices at minute 2 without asking a single question.

2. Right-Sized Design
✓ STRONG HIRE SIGNAL

Starts with the simplest working architecture justified by the math (e.g., 1 NVMe SQL primary + replicas + Redis for 40 writes/s & 3 TB).

✗ NO-HIRE RED FLAG

Recites a memorized Kafka + multi-DC Cassandra diagram that contradicts their own traffic calculations.

3. Technical Depth
✓ STRONG HIRE SIGNAL

Drives deep into 1–2 hard bottlenecks (partition keys, hot-key mitigation, transactional outbox, KV-cache batching) at minute 27.

✗ NO-HIRE RED FLAG

Skims across 12 boxes at identical buzzword depth and runs out of time before the deep dive.

4. Explicit Trade-Offs
✓ STRONG HIRE SIGNAL

Uses 3-part reasoning: 'A queue here because SMTP spikes to 3 s; checkout stays <60 ms, and we accept eventual email delay + retry dedup.'

✗ NO-HIRE RED FLAG

Name-drops tools ('We put Kafka and ZooKeeper here') without stating the alternative or operational cost.

5. Communication
✓ STRONG HIRE SIGNAL

Thinks aloud every 30–45s, checks alignment at phase transitions, and treats 'What if X fails?' as a cue for where points are awarded.

✗ NO-HIRE RED FLAG

Goes silent for 5 minutes while drawing or defends a flawed assumption defensively when nudged.

ARCHITECTURE & DATA-FLOW SLIDES · SLIDE 1 OF 4Section 01: System Design: Newsfeed System
ARCHITECTURE / DATA FLOW DIAGRAM
weeklyFriendsGroupsevery few minutesPagesread heavyNewsfeed systempage of 20Your feedranked list
SECTION 01 OF 1

1. System Design: Newsfeed System

★ FREE PREVIEW
Key Takeaway: Materialize per-user lists of 8-byte post IDs in a 1.6 TB distributed RAM cache via asynchronous hybrid fan-out, rank candidates by predicted engagement rather than strict timestamp, and serve paginated feeds from memory.
SECTION 01 DIAGRAMS · SLIDE 1 OF 4System Design: Newsfeed System
ARCHITECTURE / DATA FLOW DIAGRAM
weeklyFriendsGroupsevery few minutesPagesread heavyNewsfeed systempage of 20Your feedranked list

Requirements & Back-of-the-Envelope Capacity Estimation

A social newsfeed merges updates from disparate publishing cadences—friends posting weekly, interest groups posting hourly, and news pages publishing every few minutes—ordered by predicted user interest rather than raw creation time. For 2,000,000,000 registered users with 1,000,000,000 DAU opening their feed 10 times daily (10,000,000,000 loads/day) and 1 in 5 users authoring 1 post daily (200,000,000 posts/day), reads outnumber writes 50:1. To render a feed within < 2 s over high-latency mobile networks, backend server execution must complete in < 200 ms (p99), trading strict global freshness for eventual consistency (<= 10 s propagation delay) and uninterrupted availability (AP). Crucially, storing 200 8-byte post_id references (1.6 KB) per active user requires 1,000,000,000 * 1.6 KB = 1.6 TB of cluster RAM—proving precomputed in-memory feeds are economically viable.

  • Functional Scope: Author text/photo/video posts with audience ACLs (friends, public, group), view a personalized ranked feed, receive foreground New Posts notifications, and mutate follow edges across friends, pages, and groups.
  • Non-Functional Priorities: < 200 ms backend latency, horizontal scalability across 2x peak traffic (232,000 RPS), zero post data loss, and graceful fallback when cache shards fail.
MetricDerivation FormulaCalculated EstimateEngineering Decision
Feed Read QPS(1B DAU * 10 opens) / 86,400 s~116,000 RPS avg (~232,000 RPS at 2x peak)Serve feed pages strictly from Feed Cache + Post Cache in RAM
Post Write QPS(1B DAU * 0.2 posts) / 86,400 s~2,300 RPS avg (50:1 read-to-write ratio)Invest compute at write time (fan-out) to make 50x more reads O(1)
Post Metadata Storage200M posts/day * 1 KB200 GB/day (~73 TB/year)Store once in sharded KV/wide-column DB keyed by post_id
Media Blob Storage(200M * 20% photos) * 500 KB40M * 500 KB = 20 TB/day (~7.3 PB/year)Offload binary blobs to S3 and serve via edge CDN
Feed Cache Footprint1B active users * 200 IDs * 8 B1.6 TB total RAM (~16–32 Redis nodes)Cache only 8 B IDs + compact float scores for active (<= 30d) users
Stateless Web/Feed Fleet232,000 peak RPS / 2,000 RPS per server~116 servers peak (+ multi-region spares)Separate stateless fleets for Post Service vs. Feed Publishing

API Specification, Polyglot Data Model & Decoupled Architecture

Client APIs authenticate via bearer JWTs and use monotonic cursor=<post_id> pagination so incoming top-of-feed posts never shift offsets or duplicate items mid-scroll, paired with a lightweight GET /v1/feed/new?since=<post_id> check for foreground toast badges. Beneath the API, five distinct data records map to specialized stores: User profiles in SQL, immutable/edited Post metadata in a sharded KV/wide-column store, typed Follow edges (friend, page, group) in a distributed Graph store, Media URLs pointing to object storage, and an ephemeral Feed Cache in Redis storing (post_id, score) tuples—never duplicating post text across millions of feeds. Architecturally, the Write Path (Load Balancer -> Web Auth/Rate-Limit Tier -> Post Service -> Post Store + Blob Store -> Async Queue) is physically isolated from background Feed Generation and latency-sensitive Feed Publishing so heavy fan-out spikes never degrade read p99 latency.

Architectural TierCore Services & StoresResponsibility & Scaling Driver
Write Ingestion PathWeb Tier + Post Service + Post Store + Blob StoreEnforces auth/rate limits, assigns time-sortable post_id, persists once, enqueues event (2.3K RPS)
Background Feed GenerationQueue + Feed Generation Workers + Social Graph + Feed CacheAsynchronously resolves friend/group/page followers and inserts (post_id, score) into Redis
Online Feed PublishingFeed Publishing Service + Feed Cache + Post Cache + CDNHydrates top 20 cached IDs via batched MGET in tens of milliseconds (116K–232K RPS)
// Core Newsfeed REST API
POST /v1/posts      Body: { "text": "...", "media_ids": ["m_12"], "audience": "friends" } -> 201 { "post_id": "918273645" }
GET  /v1/feed       ?count=20&cursor=918273645                                            -> 200 { "items": [...], "next_cursor": "..." }
GET  /v1/feed/new   ?since=918273645                                                      -> 200 { "has_new": true, "count": 4 }
POST /v1/follow     Body: { "target_id": "p_881", "type": "page" }                        -> 200 OK

// Logical Record Schemas
User      (user_id PK, name, email UNIQUE, joined_at)                 -- Relational SQL
Post      (post_id PK, author_id, text, audience, created_at)         -- Sharded KV / Wide-Column
Follow    (user_id, follows_id, type ENUM[friend,page,group], since)  -- Distributed Graph Store
Media     (media_id PK, post_id, kind ENUM[photo,video], blob_url)    -- Metadata + Blob Store
FeedCache (user_id -> SortedSet<(post_id: int64, score: float32)>)    -- Replicated Redis RAM

Hybrid Feed Generation & Multi-Signal Relevance Ranking

Pure Push (fan-out-on-write) multiplies 2,300 posts/sec by 300 average connections for ~690,000 Redis writes/sec—manageable until a public page with 50,000,000 followers posts, triggering 50M writes and wasting RAM on dormant accounts. Pure Pull (fan-out-on-read) avoids write cost but explodes 116,000 reads/sec * 300 followees into ~34,800,000 backend lookups/sec. A Hybrid model pushes posts only from ordinary users/groups to followers active within the past 14–30 days, while pulling and merging high-follower pages on read. Once candidates are gathered, chronological sorting is replaced by Relevance Ranking: a classic baseline multiplies Affinity (interaction closeness with author), Weight (media engagement multiplier, e.g., photo 2.0 vs. link 1.0), and Freshness (time-decay factor <= 1.0). Production feeds evolve this into a two-stage ML pipeline—computing initial scores at write time and running neural re-ranking strictly over the top 200 cached candidates at read time.

Candidate PostAuthor AffinityContent WeightTime-Decay FreshnessFinal Score (`A * W * F`) & Rank
Best friend's photo (5 h ago)0.9 (high interaction)2.0 (rich photo)0.5 (5 h decay)0.90 -> Rank #1 (Top of Feed)
Classmate's status (1 h ago)0.5 (moderate)1.0 (plain text)0.9 (1 h decay)0.45 -> Rank #2
News page link (just now)0.3 (passive follow)1.0 (outbound link)1.0 (0 h decay)0.30 -> Rank #3 (Despite newest)
Interview Signal: ML Ranking Latency Budget: Never score 10,000+ raw posts with a heavyweight deep neural network synchronously on GET /v1/feed. Use lightweight retrieval/push to Bound the candidate pool to ~200–500 IDs in Feed Cache, then run feature-hydrated ML re-ranking in < 40 ms.

Feed Publishing, New-Post Signaling & Design Evaluation

On GET /v1/feed, Feed Publishing reads the next 20 ranked post_ids after cursor from Feed Cache, batch-fetches full post bodies and author summaries from Post Cache (falling through to Post Store only on misses), and returns JSON containing CDN URLs so mobile clients download images/video in parallel from edge servers. To notify open apps of fresh content without 1,000,000,000 blind 1-minute polling loops (nearly 100% empty responses) or 1B dedicated chat-grade WebSockets, a lightweight Notifier pushes compact invalidation signals over adaptive long-polling or shared HTTP/3 multiplexed connections while the app is foregrounded—illuminating a tap-to-refresh New Posts pill rather than jarring the viewport mid-scroll. If a user's Feed Cache shard fails or evicts due to inactivity, Feed Publishing transparently falls back to pull-based reconstruction.

RequirementArchitectural MechanismWeak Spot / BottleneckProduction Mitigation
Low Latency (< 200 ms)Precomputed Feed Cache + batched Post Cache RAM reads + edge CDNRead-time ML re-ranking latencyRestrict online neural re-ranking to top 200 cached candidates
Scalability (1B DAU)Stateless web/publishing fleets; sharded Post Store & Feed Cache1.6 TB+ RAM growth from 2B total usersMaterialize Feed Cache strictly for users active in last 14–30 days
High AvailabilityMulti-AZ cache/DB replicas + automatic pull fallback on cache missCold-cache thundering herd on regional Redis failoverRequest coalescing (singleflight) + degraded chronological pull fallback
Bounded Fan-Out (50M Pages)Async Kafka queue + hybrid push/pull split + per-user rate limitsViral post hot keys in Post CacheLocal L1 in-process cache (1–2 s TTL) on Feed Publishing nodes
ACTIVE RECALL & TRADE-OFF PROBES

System Design Checkpoint Quizzes (1)

CHECKPOINT QUIZ #1

In "System Design: Newsfeed System" (Requirements & Back-of-the-Envelope Capacity Estimation), how does a production-grade design handle "Post Write QPS" (Engineering Decision)?