
System Design Interview: Design Instagram πΈ
AS
Anthony SandeshInstagram 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.

π― 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 π.
