Applied Design: Social Feed
Fan-out strategies, timeline assembly, and real-time delivery at scale.
Functional Requirements
- Users can create posts (text, images, videos)
- Users can follow/unfollow other users
- Users see a timeline of posts from people they follow
- Timeline is ranked by relevance (not just chronological)
- Posts appear in followers' timelines within 5 seconds
- Support likes, comments, and shares
Non-Functional Requirements
- Scale: 500M DAU, 1B total users
- Latency: Feed loads in <200ms
- Availability: 99.99%
- Read-heavy: 100:1 read:write ratio
Post Creation Flow
Feed Reading Flow
Fan-Out: The Core Tradeoff
| Approach | How It Works | Pro | Con |
|---|---|---|---|
| Fan-out on Write (Push) | When user posts, write to all followers' timelines immediately | Feed reads are fast (pre-computed) | Celebrity: 90M writes per post |
| Fan-out on Read (Pull) | When user opens feed, query all followed users' posts and merge | Writes are fast (just store the post) | Slow reads if following 1000+ users |
| Hybrid ✓ | Push for normal users, pull for celebrities (>10K followers) | Best of both worlds | More complex implementation |
The Hybrid Approach (Twitter/X)
Twitter uses the hybrid model. For normal users (<10K followers), fan-out on write pushes post IDs into followers' timeline caches. For celebrities (>10K followers), their posts are fetched on-demand at read time and merged with the pre-computed timeline. This keeps write latency bounded while still delivering fast reads.
Feed Ranking
Chronological feeds are simple but engagement-poor. Modern feeds use ML-based ranking:
- Candidate generation: Collect ~1,000 candidate posts (from timeline cache + celebrity pulls)
- Feature extraction: Post age, author affinity, engagement signals, content type, user preferences
- Scoring: ML model predicts P(engagement) for each candidate
- Re-ranking: Diversity rules (don't show 5 posts from same author in a row), ads insertion, anti-spam filtering
- Truncation: Return top 20 posts, paginate with cursor
Case Study: Twitter's Timeline Architecture
Twitter's fan-out service writes ~4,500 tweets/sec to 500M+ timeline caches. Each timeline is stored as a sorted set in Redis. When you open Twitter, your feed is already pre-computed — the app fetches post IDs from your timeline cache, then hydrates them with post details. For celebrities like Obama or Taylor Swift, their tweets are not fanned out — they're merged on-read. This hybrid approach handles both the "hot celebrity" and "normal user" patterns efficiently.
Takeaway: The hybrid fan-out model is the industry standard. Pre-compute when you can, pull on-demand when you must.
Case Study: Instagram's Ranked Feed
In 2016, Instagram switched from chronological to ML-ranked feeds. The ranking model predicts engagement probability for each candidate post, considering: relationship closeness, post age, content similarity to past engagement, and post type (photo, video, carousel). The switch increased average session time by 10% — users saw more relevant content and scrolled deeper.
Takeaway: Ranked feeds dramatically increase engagement. The ranking model is the secret weapon — invest in ML if your product depends on content discovery.
- The Infrastructure Behind Twitter Scale — Timeline service, fan-out, and caching at 500M tweets/day.
- Serving Facebook Multifeed — How Facebook assembles the News Feed from multiple ranking models.
- System Design Interview Vol. 1 by Alex Xu — Chapter 11 (Design a News Feed System). (ByteByteGo, 2020)
Related Simulators
Next Design
Design: Real-time Chat
WebSocket connections, presence heartbeats, message ordering, and offline sync.
Continue Journey