System Design Cases10 lessons22 quiz questions

Design: News Feed (Facebook/Twitter)

10-session plan covering fan-out strategies, ranking, real-time updates, and scale.

What You Will Learn

  • Requirements & Core Concepts
  • Capacity Estimation
  • Fan-out Strategies
  • Data Model
  • Feed Ranking
  • API Design & Pagination
  • Real-Time Updates
  • Like Counters & Interactions
  • Media Pipeline
  • Mock Interview

Overview

10-session plan covering fan-out strategies, ranking, real-time updates, and scale. Session 1: Requirements & Core Concepts Interview Opening Interviewer: "Design a news feed system like Facebook or Twitter." Candidate: "Let me scope this. Core feature: when a user opens the app, they see a ranked list of posts from people they follow. Correct?" Interviewer: "Yes." Candidate: "A few clarifying questions: Is following unidirectional (Twitter) or bidirectional friendship (Facebook)? What content types — text, images, videos, links? What's the follower limit per user? Are there 'celebrity' users with millions of followers? Do we need real-time updates or is a refresh-based feed acceptable? What ranking signals — chronological, or ML-based ranking?" Interviewer: "Unidirectional following like Twitter. Text and images. No explicit follower limit — celebrities exist. Real-time updates via WebSocket when user is active. Ranking: recency-weighted with engagement signals." Functional Requirements Users follow other users (unidirectional) Post creation: text (up to 500 chars) images (up to 4 images per post) News feed: ranked list of posts from followed accounts Feed updates: new posts appear in real-time when user is on app Pagination: infinite scroll (load more as user scrolls) Interactions: like, comment, share (basics — no detailed design needed) Non-Functional Requirements Feed load latency: p99 < 200ms for feed fetch Post creation latency: p99 < 500ms High availability: 99.99% Eventual consistency: OK if new post takes up to 5 seconds to appear in followers' feeds Scale: 300M DAU, 500M total users, celebrities with up to 100M followers The Central Design Challenge: Fan-out When a user with 100M followers posts, you need to update 100M feed caches. This is the defining challenge. Two strategies: Fan-out on write (push): on post creation, immediately push post to each follower's feed cache Fan-out on read (pull): on feed request, pull recent posts from all followed accounts and merge Hybrid: push to regular users' caches, pull for celebrities We will design the hybrid approach — the only practical solution at this scale. Interview Q&A Q: What's the difference between a timeline and a news feed? A: A timeline is strictly chronological posts from accounts you follow. A news feed is ranked — uses ML signals (engagement, recency, relationship strength) to order posts. Twitter started as a timeline, Facebook always had a ranked feed. Modern Twitter (X) uses a hybrid. Q: Why does the celebrity follower problem matter so much? A: At 6,000 posts/second (300M DAU posting), if a celebrity with 100M followers posts, naive fan-out generates 100M cache writes instantly — 100M × (cache write latency 0.5ms) = 50,000 seconds of work. Impossible in real-time. This forces the hybrid design. Java Implementation Python Implementation

Sample Quiz Questions

1. What is 'fan-out on write' in the context of a news feed?

·Difficulty: easy/5

2. A celebrity has 50 million followers and posts 10 times per day. Fan-out on write generates how many feed updates per day?

·Difficulty: medium/5

3. Why is cursor-based pagination preferred over offset-based for news feeds?

·Difficulty: medium/5

+ 19 more questions available in the full app.

Related Topics

Master Design: News Feed (Facebook/Twitter) for Your Next Interview

Get access to full lessons, adaptive quizzes, cheat sheets, code playground, and progress tracking — completely free.