Tutorials System Design Mastery
Case Study: Designing Instagram (Billions of images)
On this page
Case Study: Designing Instagram
Instagram's core challenge is Write Volume (millions of photo uploads) and Latency (feed scrolling must be instant). We must handle billions of images and trillions of relationships.
1. Image Storage (Object Store)
We don't store images in a database. We store them in an Object Store like AWS S3 or Azure Blob Storage. The database only stores the metadata (Image ID, User ID, URL). We use a **CDN** (CloudFront) to cache images globally.
2. The "News Feed" Calculation
Generating a feed in real-time by joining Followers and Posts tables is too slow (O(N)). We use Fan-out on Load:
- When User A posts a photo, we find all 1 million followers.
- We inject the Post ID into the 1 million individual "Pre-computed cache" lists of those followers.
- When a follower opens the app, we just read their pre-computed list. Instant speed.
4. Interview Mastery
Q: "How do you handle 'Celebrity' Fan-out?"
Architect Answer: "If Justin Bieber posts (>100M followers), trying to update 100 million caches at once would crash the task queue. This is the **Thundering Herd** problem. We use a hybrid approach: For normal users, we use Fan-out. For celebrities, we **Pull**. When a user opens their feed, we merge their pre-computed 'Normal' feed with the latest posts from the few celebrities they follow. This prevents the write-surge."
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!