📸 Design Instagram — System Design Interview Guide
Medium · Social & Media
Design Instagram — a photo and video sharing platform where users post content, follow others, see a personalized feed, and interact via likes, comments, and stories.
Open the interactive Instagram 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
- Post photos and short videos with captions and tags
- Follow/unfollow users
- View a personalized feed of posts from followees
- 24-hour Stories that auto-delete
- Like, comment, and save posts
- Explore page with trending and recommended content
Non-functional requirements & scale
- 2B monthly active users; 500M daily
- 100M photos/videos uploaded per day
- Feed load time < 200ms (P95)
- Stories must expire in exactly 24 hours
- Photos must be served from CDN; images load < 1 second on 4G
- Search across captions and hashtags in < 100ms
Capacity estimation
100M uploads/day means aggressive CDN and storage strategy. Feed generation: Instagram uses ML-ranked feed (not chronological since 2016). Stories = TTL-based ephemeral posts. Photo processing: multiple sizes (thumbnail, standard, HD). Scale: 2B users × avg 5 posts viewed/day = 10B feed post loads/day.
Core entities
- Post — postId (Snowflake), userId, mediaUrls[], caption, hashtags[], likeCount, commentCount, createdAt
- Story — storyId, userId, mediaUrl, viewerIds[], expiresAt (createdAt + 24h), createdAt
- User — userId, username, bio, profilePic, followerCount, followingCount, isVerified
- FeedItem — userId, postId, score (ML rank), insertedAt
API design
POST /api/v1/posts— Create post. Body: { mediaIds[], caption, tags[] }. Triggers async fan-out.GET /api/v1/feed?cursor=&limit=12— Get ranked feed. Returns posts with pre-signed CDN URLs.POST /api/v1/stories— Create story. TTL auto-set to 24h.GET /api/v1/stories/:userId— Get user's active stories (not expired).
High-level design
Photo upload → S3 → Lambda resize → CDN. Post → Kafka → Fanout service writes to follower feed caches. Feed read: Redis sorted set by ML score, hydrate post details from Cassandra + CDN photo URLs.
Deep dives
📱 Photo Processing Pipeline
Upload: client sends photo to Upload Service which stores in S3 and returns postId. Async: Lambda triggered by S3 event → resize to 4 variants (thumbnail 150px, small 320px, medium 640px, HD 1080px) → store back in S3 under fixed paths. CDN automatically serves from nearest edge on first access, then caches. p99 < 100ms for cached images.
⏰ Stories with TTL
Stories expire in 24h. Two approaches: (1) Scheduled job scans DB for expired stories — doesn't scale. (2) Redis TTL: store storyId in Redis with TTL = 86400s. On expiry, Redis key-expiry event (pub/sub) triggers cleanup job. (3) Store expiresAt in Cassandra; filter at read time (simple, no cleanup needed). Production: use approach 3 + async cleanup batch.
🔍 Hashtag Search
Index posts by hashtag in Elasticsearch. Tag a post → async worker indexes hashtag→postId. Search #travel → Elasticsearch returns top posts (by recency + engagement). Trending hashtags: count hashtag appearances in last 1h using Kafka + Flink windowed aggregation → top-K by count stored in Redis. Explore page = trending hashtags + recommended based on engagement history.
🏆 Feed Ranking (ML)
Instagram moved from chronological to ML-ranked feed in 2016. Signal features: content type (video vs photo), author relationship strength (DM frequency, tag history), predicted likes/comments, time since post, hashtag overlap with interests. Model: neural network. Inference at feed request time on top-K candidates from feed cache. Online learning updates model daily.
Scaling considerations
- CDN handles 90%+ of photo traffic — S3 is origin, CloudFront is edge
- Cassandra for posts (write-heavy, wide-column reads by userId)
- Redis sorted set per user for feed cache (score = ML rank + recency)
- Hybrid fan-out: push to small-follower users, pull for celebrities at read time
- Elasticsearch for hashtag/caption search with async indexing via Kafka
What interviewers expect by level
- Junior: Describe photo upload to S3, basic feed generation, follow/unfollow. Understand CDN for photos.
- Mid: Fan-out strategy, Redis feed cache, story TTL implementation, photo processing pipeline.
- Senior: Hybrid fan-out with celebrity optimization, ML ranking, hashtag search, CDN strategy for 100M uploads/day.
- Staff: 2B user scale, multi-region CDN strategy, ML model deployment for ranking, GDPR compliance for photo deletion.
Practice more system design case studies
- Design URL Shortener
- Design Social Media Feed
- 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 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…