Design a Social Media Feed — The Complete System Design Guide
The most asked system design question#
"Design a social media feed" appears in nearly every system design interview at FAANG companies. It tests your understanding of data modeling, caching strategies, real-time delivery, and trade-offs at scale.
Two fundamental approaches#
Fan-out on write (push model)#
When a user posts, immediately write the post to every follower's feed cache.
Pros: Reading the feed is instant — just fetch from a pre-computed list Cons: Expensive for users with millions of followers (celebrity problem)
User A posts → Write to Feed(Follower 1)
Write to Feed(Follower 2)
Write to Feed(Follower 3)
... × 10 million followers
Fan-out on read (pull model)#
When a user opens their feed, fetch recent posts from everyone they follow and merge/rank in real-time.
Pros: Posts are instant — no fan-out cost at write time Cons: Reading is slow — must query many sources and rank on the fly
User opens feed → Fetch posts from Followed User 1
Fetch posts from Followed User 2
Fetch posts from Followed User 3
... merge, rank, return
The hybrid approach (what Twitter/Instagram actually use)#
- Regular users (< 10K followers): fan-out on write to pre-compute follower feeds
- Celebrity users (> 10K followers): fan-out on read, mixed into feed at read time
This gives fast writes for most users while avoiding the celebrity fan-out explosion.
Feed ranking#
Chronological feeds are simple but engagement suffers. Modern feeds use ML-powered ranking:
Signals:
- Engagement probability — Will this user like, comment, share, or save?
- Content type preference — Does this user engage more with photos, videos, or text?
- Relationship strength — How often does the user interact with the author?
- Recency — Newer posts get a boost, but it's not the only factor
- Content quality — Spam score, misinformation flags, content policy
The ranking pipeline:
- Candidate generation — Fetch ~1000 candidate posts from follows + recommendations
- Feature extraction — Compute features for each candidate (author stats, content signals)
- Scoring — ML model predicts engagement probability for each post
- Re-ranking — Apply diversity rules (no 3 posts from same author, mix content types)
- Return top ~50 — Paginated with cursor-based pagination
Data model#
Users: { id, name, avatar, follower_count, ... }
Posts: { id, author_id, content, media_urls, created_at, ... }
Follows: { follower_id, followed_id, created_at }
Feed Cache: { user_id → [post_id, post_id, ...] } // Redis sorted set
Likes: { user_id, post_id, created_at }
Comments: { id, post_id, author_id, content, created_at }
Caching strategy#
- Feed cache — Redis sorted set per user, scored by timestamp. ZREVRANGE for latest posts.
- Post cache — Cache hot posts (< 24h old) in Redis hashes
- User cache — Profile data cached with 5-minute TTL
- CDN — All media (images, videos) served from CDN edge servers
Real-time updates#
Three approaches for showing new posts:
- Polling — Client checks every 30 seconds. Simple, wasteful.
- Long polling — Server holds connection until new data. Better, but connection overhead.
- WebSocket — Persistent connection for instant push. Best UX, most complex.
Most feeds use: WebSocket for the active tab + push notification for background. New posts appear as "3 new posts" banner that loads on tap.
Handling scale#
| Challenge | Solution |
|---|---|
| Hot posts (viral content) | Cache in CDN, separate hot-post cache tier |
| Celebrity posting | Fan-out on read, async job queue for writes |
| Global users | Multi-region deployment, edge caching |
| Feed consistency | Eventually consistent — users won't notice 1-2s delay |
| Thundering herd | Request coalescing, jittered cache expiry |
Pagination#
Cursor-based, not offset-based:
GET /feed?cursor=post_id_123&limit=20
Why not offset? Offset breaks when new posts are inserted — users see duplicates or miss posts. Cursors are stable because they reference a specific post.
Notifications#
When your post gets liked/commented:
- Write event to notification queue
- Notification service batches events (don't send 50 separate "liked your post" emails)
- Push to device via FCM/APNs
- Store in notification inbox for in-app display
Visualize your feed architecture#
See how all these components connect — try Codelit to generate an interactive diagram of a social media feed system with fan-out, caching, and ranking.
Key takeaways#
- Hybrid fan-out — push for regular users, pull for celebrities
- ML ranking beats chronological — but adds complexity
- Redis sorted sets for feed cache — instant O(log n) inserts, O(1) reads
- Cursor pagination, not offset — stable in the presence of new content
- Eventually consistent is fine — users don't need real-time consistency for feeds
- Cache aggressively — hot posts, user profiles, media on CDN
Try it on Codelit
Chaos Mode
Simulate node failures and watch cascading impact across your architecture
90+ Templates
Practice with real-world architectures — Uber, Netflix, Slack, and more
Related articles
Try these templates
Uber Real-Time Location System
Handles 5M+ GPS pings per second using H3 hexagonal geospatial indexing.
6 componentsE-Commerce Checkout System
Production checkout flow with Stripe payments, inventory management, and fraud detection.
11 componentsTwitter-like Feed & Timeline
Social media feed with real-time tweets, fan-out on write, and trending topics.
9 componentsBuild this architecture
Generate an interactive architecture for Design a Social Media Feed in seconds.
Try it in Codelit →
Comments