Skip to content

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:

  1. User Feed (Home Timeline)

  2. Show posts from:

    • Followed users
    • Sponsored / recommended content
    • Feed must be:

    • Personalized

    • Ranked
    • Paginated (infinite scroll)
    • Post Creation
  3. Users can create posts with:

    • Images or videos
    • Captions
    • Hashtags
    • Location (optional)
    • New posts should appear in followers’ feeds quickly
    • Feed Ranking
  4. Rank posts using:

    • Recency
    • Engagement signals (likes, comments)
    • User affinity
    • Optional ML-based ranking
    • Interactions
  5. Support:

    • Likes
    • Comments
    • Saves
    • Engagement should affect feed ranking
    • APIs
  6. Create post API

  7. Fetch feed API
  8. Like/comment APIs
  9. Media Delivery

  10. Efficient delivery of images/videos

  11. Adaptive quality for different network conditions

Non-Functional Requirements

Your system must meet the following constraints:

  1. Scale

  2. Hundreds of millions of users

  3. Tens of billions of posts stored
  4. Millions of feed reads per second globally
  5. Latency

  6. P99 latency ≤ 200 ms for feed fetch

  7. Media loading optimized via CDN
  8. Freshness

  9. New posts visible to followers within:

    • Seconds (best effort)
    • < 1 minute worst case
    • Availability
  10. ≥ 99.99% uptime

  11. Resilient to data center and regional failures
  12. Consistency

  13. Eventual consistency acceptable for feeds

  14. Strong consistency required for user actions (likes/comments)

What You Should Deliver

Provide a practical, production-oriented design that includes:

  1. Requirement clarification & assumptions
  2. High-level architecture

  3. Core services (Feed service, Post service, Media service)

  4. Data flow (post creation → feed generation → feed read)
  5. Feed generation strategy

  6. Fan-out-on-write vs fan-out-on-read

  7. Hybrid approaches
  8. Handling celebrity users
  9. Data storage choices

  10. Feed storage

  11. Post storage
  12. Metadata vs media separation
  13. Caching strategy
  14. Ranking architecture

  15. Online vs offline ranking

  16. Feature computation
  17. How ranking fits latency constraints
  18. Media handling

  19. Upload flow

  20. Storage (object storage)
  21. CDN integration
  22. Scalability strategy

  23. Horizontal scaling

  24. Hot user mitigation
  25. Feed cache invalidation
  26. Failure handling

  27. Backpressure on fan-out

  28. Retry mechanisms
  29. Graceful degradation (e.g., stale feed)
  30. Rough capacity estimates

  31. Posts/day

  32. Feed reads/sec
  33. Storage requirements
  34. 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:

  1. 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.)
  2. The feed cache cluster restarts empty at peak. What stops the database from collapsing? (Admission control, request coalescing, serving a degraded feed.)
  3. A CDN rule starts caching /api/feed/me.json for everyone. (Web cache deception: private responses are no-store, and cacheability follows origin headers.)
  4. 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.