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:
- Feed Publishing
- News Feed Building
Step 3: Deep Dive Design
(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
Model | Pros | Cons |
---|---|---|
Push Fanout | Precomputed cache, fast reads | Poor performance for celebrities, hot keys |
Pull Fanout | Good for inactive users, saves CPU | Slower read latency |
Hybrid | Push for normal users, Pull for celebs | Complex logic to split user types |
(B) Feed Retrieval
- User sends
GET /v1/me/feed
- Load balancer routes to web server
- Web server calls Newsfeed Service
- Service fetches
post_id
list from feed cache - Uses Content/User Cache/CDN to fetch full post data
- Returns final feed JSON to client
Cache Architecture (5 Layers)
- News Feed Cache: Stores list of post IDs per user
- Content Cache: Hot post content
- Social Graph Cache: User relationship graph
- Action Cache: User interactions (likes, replies, etc.)
- Counter Cache: Like count, comment count, followers, etc.
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