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."

Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

System Design Mastery
Course syllabus
1. Distributed Systems Fundamentals
2. Database Scalability
3. Caching & CDN Strategies
4. Event-Driven Architecture
5. High Availability & Load Balancing
6. Microservices & API Gateway
7. Monitoring & Disaster Recovery
8. FAANG System Design Interview
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details