My Brain CellsMy Brain Cells
HomeBlogAbout

Β© 2026 My Brain Cells

XGitHubLinkedIn
System Design Interview: Design Instagram πŸ“Έ

System Design Interview: Design Instagram πŸ“Έ

AS
Anthony Sandesh
Instagram is one of the world’s largest social platforms, centered around sharing photos and videos. In this post, we’ll break down how to design Instagram step by step β€” just like you’d explain in a system design interview.
We’ll cover requirements, architecture, scaling challenges, data modeling, caching, APIs, and more β€” with diagrams to keep things visual.

βœ… Functional Requirements

  • Upload and share photos/videos (with captions, tags).
  • Profiles & follow system (social graph).
  • News feed (personalized timeline of posts).
  • Likes & comments on posts.
  • Search & discovery (users, hashtags, posts).
  • Direct messaging (real-time chat).
  • Notifications (likes, follows, comments).

βš™οΈ Non-Functional Requirements

  • Scalability β†’ handle hundreds of millions of users.
  • Low latency β†’ feed generation < 200ms.
  • High availability β†’ 24/7 uptime.
  • Durability β†’ never lose photos.
  • Eventual consistency β†’ acceptable for feeds/likes.
  • Security & privacy β†’ protect user data.

πŸ›οΈ High-Level Architecture

Key ideas:
  • Load balancer spreads requests across many stateless app servers.
  • Microservices handle user, media, feed, notifications, messaging.
  • CDN + Object Store for massive photo/video storage.
  • Caches (Redis/Memcached) to speed up hot data.
  • SQL + NoSQL mix: relational DB for users/posts, NoSQL for feeds.

πŸ–Ό Media Storage & Delivery

  • Use distributed object storage (e.g., S3, GCS) for photos/videos.
  • Store multiple sizes (thumbnail, medium, full) at upload.
  • Serve via CDN for low-latency global delivery.
  • Metadata (caption, tags, URL) stored in DB, not the binary file.

πŸ“° Feed Generation

Options

  • Fan-out on write (Push): When Alice posts β†’ copy into all followers’ feeds. (Fast reads, heavy writes).
  • Fan-out on read (Pull): Bob opens app β†’ fetch posts from people he follows. (Cheap writes, slow reads).
  • Hybrid: Push for most users, pull for celebrities with millions of followers.

Implementation

  • Feed entries stored in a Feed DB (NoSQL like Cassandra/DynamoDB).
  • Async workers process fan-out events via queues.
  • Use Redis caching for hot feeds.

πŸ—ƒ Data Modeling

Users Table
Posts Table
Follows Table
Likes Table
FeedEntries (NoSQL Example)

⚑ Caching Strategies

  • CDN β†’ cache media globally.
  • Redis/Memcached β†’ cache feeds, user profiles, like counts.
  • TTL-based expiration for feeds.
  • Write-through cache for likes/comments counters.

πŸ”Œ API Design Examples

  • All endpoints paginated.
  • Rate limiting via API Gateway.
  • Stateless β†’ each request carries auth token.

πŸ”” Notifications & πŸ’¬ Messaging

  • Use event-driven architecture for likes/follows/comments.
  • Notification service stores alerts + pushes to APNs/FCM.
  • Messaging via persistent connections (WebSockets/MQTT) for real-time chat.

βš–οΈ Load Balancing & Rate Limiting

  • Load balancers at all layers β†’ no single point of failure.
  • Geo load balancing β†’ route users to nearest data center.
  • Rate limiting at API Gateway β†’ e.g., 100 feed requests/min per user.
  • Implemented with Redis counters or token bucket algorithm.

notion image

🎯 Conclusion

Designing Instagram is a masterclass in system design:
  • Object storage + CDN for media.
  • Push-based feed with hybrid fallback for scale.
  • SQL + NoSQL + Cache for different workloads.
  • Event-driven notifications and real-time messaging.
  • Load balancing & rate limiting to keep things reliable.
With this architecture, Instagram can handle billions of daily requests while still delivering photos in milliseconds πŸš€.

More posts

System Design: Complete Guide for Interviews

System Design: Complete Guide for Interviews

Deep Dive into NVIDIA TensorRT with PyTorch and ONNX

Newer

Deep Dive into NVIDIA TensorRT with PyTorch and ONNX

VS Code Keyboard Shortcuts Every Developer Should Know

Older

VS Code Keyboard Shortcuts Every Developer Should Know

On this page

  1. βœ… Functional Requirements
  2. βš™οΈ Non-Functional Requirements
  3. πŸ›οΈ High-Level Architecture
  4. πŸ–Ό Media Storage & Delivery
  5. πŸ“° Feed Generation
  6. Options
  7. Implementation
  8. πŸ—ƒ Data Modeling
  9. ⚑ Caching Strategies
  10. πŸ”Œ API Design Examples
  11. πŸ”” Notifications & πŸ’¬ Messaging
  12. βš–οΈ Load Balancing & Rate Limiting
  13. 🎯 Conclusion