Design a Social News Feed
Design Twitter's home timeline or Facebook's news feed. The core problem is fanout — how do you push one post to millions of followers fast enough that the feed feels real-time?
What you will learn
- Explain the fanout-on-write vs fanout-on-read tradeoff and when each breaks down
- Design a hybrid fanout strategy that handles celebrity accounts without degrading feed freshness
- Model the feed storage layer and choose between precomputed timelines and query-time assembly
- Handle ranking, pagination, and feed freshness at scale
The news feed — Twitter's home timeline, Facebook's feed, Instagram's scroll — is one of the most studied distributed systems problems. The challenge is deceptively simple: when a user opens the app, show them a ranked, paginated list of recent posts from accounts they follow. The complexity lies in the scale. A single celebrity post triggers a wave of writes or reads that can cascade across the entire system.
Functional requirements:
- Users see a feed of posts from accounts they follow, sorted by recency (or relevance)
- New posts appear in followers' feeds within seconds
- Infinite scroll with pagination — load more as user scrolls
- Users can create posts (text, images, links)
- Like and comment counts visible inline (eventual consistency acceptable)
Non-functional requirements:
- Feed load time < 200ms p99
- Post fan-out latency < 5 seconds (follower sees post within 5s of publish)
- Read-heavy: 100:1 read/write ratio
- High availability — feed downtime is user-visible
Create a free account to read the full chapter — advanced chapters, progress tracking, and quizzes are free with sign-up.