📰 Design Social Media Feed — System Design Interview Guide
Hard · Social & Fan-Out
Design the news feed system for a social platform like Twitter/X or Facebook where users see posts from people they follow, in reverse-chronological or ranked order.
Open the interactive Social Media Feed design on PrepGrind → Drag load balancers, caches, databases, and queues onto a canvas, run a live traffic simulation to watch latency and bottlenecks under load, and follow the full interview walkthrough below — free, in your browser.
Functional requirements
- Users can create posts (text, images, videos)
- Users can follow / unfollow other users
- Users see a personalized feed of posts from followees
- Feed is paginated and supports infinite scroll
- Like, comment, and repost interactions
Non-functional requirements & scale
- 500M daily active users; 100M posts created per day
- Feed load p99 < 200ms
- Each user can have up to 10M followers (celebrity problem)
- Eventual consistency for feed updates is acceptable
- Posts must not be lost — durable write guarantee
Capacity estimation
500M DAU. Average user follows 300 accounts. Each post creation fans out to all followers. Celebrity user with 10M followers = 10M writes on every tweet. Pull model: expensive per feed load. Push model: expensive per post write. Hybrid is required.
Core entities
- User — userId, username, followerCount, followingCount, isVerified
- Post — postId (Snowflake), authorId, content, mediaUrls[], createdAt, likeCount
- Follow — followerId, followeeId, createdAt (graph edge)
- FeedItem — userId, postId, score, insertedAt (denormalized feed cache)
API design
POST /api/v1/posts— Create post. Body: { content, mediaIds? }. Returns { postId, createdAt }GET /api/v1/feed?cursor=&limit=20— Returns paginated feed items with cursor-based pagination.POST /api/v1/posts/:id/like— Like a post. Idempotent.POST /api/v1/users/:id/follow— Follow a user. Updates graph + triggers fan-out.
High-level design
Post created → Fanout Service reads follower list → writes postId to each follower's feed cache (Redis sorted set). On feed load: read from Redis feed cache, hydrate post details. Celebrities use pull-on-read to avoid 10M fan-out writes.
Deep dives
📤 Fan-Out Strategy
Push model: on post create, write postId to every follower's feed cache. Fast reads (O(1)), expensive writes (O(followers)). Pull model: on feed load, fetch posts from all followees. Slow reads, cheap writes. Hybrid: push to regular users (<1000 followers), pull for celebrities at read time. Merge results in Feed Service.
⭐ Celebrity Problem
A celebrity with 10M followers posting = 10M Redis writes in seconds. Solution: skip fan-out for celebrities (mark isHighProfile). On feed load: pull celebrity posts separately from PostDB, merge with pre-built feed cache. Use caching at the celebrity post level (1 cache entry serves 10M users).
📄 Feed Pagination
Use cursor-based pagination (not offset). Cursor = last seen Snowflake postId (timestamp-embedded). Redis sorted set keyed by userId, scored by post timestamp. ZREVRANGEBYSCORE with cursor for O(log N) pagination. Cache up to last 800 feed items per user; older posts fetched from DB.
🏆 Feed Ranking
Chronological: simple sort by createdAt. Ranked: ML model scores based on engagement prediction, recency, relationship closeness. Scoring can be pre-computed offline (batch job updates feed order) or real-time using feature store. Twitter uses a separate ranking service after initial candidate retrieval.
Scaling considerations
- Cassandra for post storage: wide-column, tunable consistency, good write throughput
- Redis sorted sets for feed cache: ZADD/ZREVRANGE in O(log N)
- Kafka partitioned by userId for ordered fan-out processing
- Separate read cluster for feed hydration vs write cluster for post creation
- CDN for media (images/videos) — store in S3, serve via CloudFront
What interviewers expect by level
- Junior: Describe post creation and feed retrieval. Know the difference between push and pull fan-out.
- Mid: Design the hybrid fan-out with celebrity threshold, Redis sorted set for feed cache, cursor pagination.
- Senior: Full pipeline: Kafka-driven fan-out workers, Cassandra post sharding, Redis cluster, ML ranking, celeb pull-merge.
- Staff: Multi-region replication, consistency models for cross-region feeds, cost analysis of push vs pull at 500M DAU, graceful degradation.
Practice more system design case studies
- Design URL Shortener
- Design Chat System
- Design Video Streaming
- Design Ride-Sharing Platform
- Design E-Commerce Platform
- Design UPI Payment Gateway
- Design Google Docs
- Design Tinder
- Design Google Drive / Dropbox
- Design Instagram
- Design Type-Ahead Search
- Design Web Crawler
- Design Ticket Booking (BookMyShow)
- Design Pastebin
- Design Notification System
- Design Rate Limiter (Standalone)
- Design Simple Web App
- Design Food Delivery (Swiggy)
- Design Stock Trading System
- Design Live Streaming (Twitch)
- Design Distributed Key-Value Store
- Design Ad Click Aggregation
- Design Monitoring / Metrics (Datadog)
- Design Online Judge (LeetCode)
- Design FB Post Search
- Design Yelp
- Design Cache Layer
- Design Message Queue
- Design Full Production Stack
PrepGrind runs entirely in your browser, free, no installation required. Loading the interactive playground…