Skip to main content

Chapter 11: Design a News Feed System

In this chapter, we are asked to design a News Feed System.

According to Facebook: “News Feed is a constantly updating list of stories in the middle of your home page. News Feed includes status updates, photos, videos, links, app activity, and likes from people, Pages, and groups that you follow.”

This is a popular system design interview question. Variants include designing Facebook News Feed, Instagram Feed, or Twitter Timeline.


Step 1: Understand the Problem and Scope

  • Platforms: Web + Mobile (iOS/Android)
  • Core Features:
    • Users can post content
    • Users can see posts from friends in their feed
  • Sorting: Reverse chronological order (simplified)
  • User Graph: Each user can have up to 5000 friends
  • Scale: 10 million Daily Active Users (DAU)
  • Post Types: Text, images, video supported

Step 2: High-Level Design

Two Main Flows:

  1. Feed Publishing

Feed Publishing

  1. News Feed Building

News Feed Building


Step 3: Deep Dive Design

System Design Architecture

(A) Feed Publishing

Core Components:

  • Web Server: Handles authentication and rate limiting
  • Post Service: Stores post to DB and cache
  • Fanout Service: Distributes post to followers' feeds
  • Notification Service: Notifies friends of the new post

Fanout Models Comparison

ModelProsCons
Push FanoutPrecomputed cache, fast readsPoor performance for celebrities, hot keys
Pull FanoutGood for inactive users, saves CPUSlower read latency
HybridPush for normal users, Pull for celebsComplex logic to split user types

Fanout Models


(B) Feed Retrieval

  1. User sends GET /v1/me/feed
  2. Load balancer routes to web server
  3. Web server calls Newsfeed Service
  4. Service fetches post_id list from feed cache
  5. Uses Content/User Cache/CDN to fetch full post data
  6. Returns final feed JSON to client

Feed Retrieval Flow


Cache Architecture (5 Layers)

  1. News Feed Cache: Stores list of post IDs per user
  2. Content Cache: Hot post content
  3. Social Graph Cache: User relationship graph
  4. Action Cache: User interactions (likes, replies, etc.)
  5. Counter Cache: Like count, comment count, followers, etc.

Cache Architecture

Step 4: Summary & Design Considerations

  • DB Scaling: Vertical vs Horizontal
  • SQL vs NoSQL
  • Master-Slave Replication
  • Read/Write Separation
  • Sharding
  • Stateless Web Layer
  • Caching Wherever Possible
  • Multi-Region Data Centers
  • Message Queues for Decoupling
  • Monitoring Metrics:
    • QPS
    • Feed refresh latency
    • Cache hit rate