Instagram feed
Design a scalable, low-latency feed system for an Instagram-like social network that serves personalized feeds to hundreds of millions of users worldwide.
The system must support real-time post delivery, ranking, and media-heavy content, while handling massive read and write traffic with high availability and reliability.
You are expected to design this as if it were going into production at Instagram scale.
Functional Requirements¶
Your design must support:
-
User Feed (Home Timeline)
-
Show posts from:
- Followed users
- Sponsored / recommended content
-
Feed must be:
-
Personalized
- Ranked
- Paginated (infinite scroll)
- Post Creation
-
Users can create posts with:
- Images or videos
- Captions
- Hashtags
- Location (optional)
- New posts should appear in followers’ feeds quickly
- Feed Ranking
-
Rank posts using:
- Recency
- Engagement signals (likes, comments)
- User affinity
- Optional ML-based ranking
- Interactions
-
Support:
- Likes
- Comments
- Saves
- Engagement should affect feed ranking
- APIs
-
Create post API
- Fetch feed API
- Like/comment APIs
-
Media Delivery
-
Efficient delivery of images/videos
- Adaptive quality for different network conditions
Non-Functional Requirements¶
Your system must meet the following constraints:
-
Scale
-
Hundreds of millions of users
- Tens of billions of posts stored
- Millions of feed reads per second globally
-
Latency
-
P99 latency ≤ 200 ms for feed fetch
- Media loading optimized via CDN
-
Freshness
-
New posts visible to followers within:
- Seconds (best effort)
- < 1 minute worst case
- Availability
-
≥ 99.99% uptime
- Resilient to data center and regional failures
-
Consistency
-
Eventual consistency acceptable for feeds
- Strong consistency required for user actions (likes/comments)
What You Should Deliver¶
Provide a practical, production-oriented design that includes:
- Requirement clarification & assumptions
-
High-level architecture
-
Core services (Feed service, Post service, Media service)
- Data flow (post creation → feed generation → feed read)
-
Feed generation strategy
-
Fan-out-on-write vs fan-out-on-read
- Hybrid approaches
- Handling celebrity users
-
Data storage choices
-
Feed storage
- Post storage
- Metadata vs media separation
- Caching strategy
-
Ranking architecture
-
Online vs offline ranking
- Feature computation
- How ranking fits latency constraints
-
Media handling
-
Upload flow
- Storage (object storage)
- CDN integration
-
Scalability strategy
-
Horizontal scaling
- Hot user mitigation
- Feed cache invalidation
-
Failure handling
-
Backpressure on fan-out
- Retry mechanisms
- Graceful degradation (e.g., stale feed)
-
Rough capacity estimates
-
Posts/day
- Feed reads/sec
- Storage requirements
-
Trade-offs
- What consistency is sacrificed and why
- What is computed async vs sync
- What is cached aggressively vs recomputed
Expectations¶
- Be concrete (mention specific techniques like push vs pull feeds, Redis, object storage, CDN)
- Avoid unnecessary theory
- Clearly justify architectural decisions
- Optimize for simplicity first, then scale
- Assume this system will evolve for 10+ years
Interview Kit¶
Read first: Solution · Caching §7 layers, §7.5 CDN security · Load control §11 recovery · Sharding
Curveballs. The interviewer changes one thing mid-design. The hint in italics is what a strong answer reaches for:
- A user with 300M followers posts. Push, pull, or hybrid, and where exactly is the threshold? (Hybrid: pull for celebrities, and state the follower-count cut-off and why.)
- The feed cache cluster restarts empty at peak. What stops the database from collapsing? (Admission control, request coalescing, serving a degraded feed.)
- A CDN rule starts caching
/api/feed/me.jsonfor everyone. (Web cache deception: private responses areno-store, and cacheability follows origin headers.) - Ranking model latency doubles. What does the feed serve while it's slow?
Must answer (security, privacy, operations):
- Private accounts and blocks in fan-out: what happens to already-fanned-out posts when someone is blocked
- Account deletion: removing posts from millions of precomputed feeds
Phase it (MVP → Growth → Scale): MVP: pull model with SQL ORDER BY created_at plus cache. Growth: fan-out-on-write into Redis lists. Scale: hybrid fan-out, ranking service, multi-region feeds.
Score yourself with the rubric.