CASE STUDY

Instagram

616 words·Advanced

How to use this case study

SDE-2 / Mid

Study the full Instagram case study. Focus on understanding the core components and how they interact. Focus on sections 1-3: requirements, API design, and high-level architecture. Understand the news feed generation (pull vs push model) and media storage pipeline.

SDE-3 / Senior

Study the full Instagram case study. Focus on understanding the core components and how they interact. Be ready to discuss the fan-out service design, CDN caching strategy for media, and how to handle the social graph at scale (1B users). Know the trade-offs between chronological vs ranked feeds.

Staff / Principal

Study the full Instagram case study. Focus on understanding the core components and how they interact. Be prepared to discuss the media processing pipeline (thumbnail generation, video transcoding), the consistency model for follower counts, and how to design the Explore page recommendation system. Discuss multi-region deployment.

# Instagram\

\

---\

\

0) Problem Restatement\

Design a social media platform like Instagram where users can post photos/videos, follow other users, like/dislike posts, search content, and view a personalized news feed. Core challenges include handling massive media uploads, efficiently generating news feeds for millions of users, storing and serving media at scale, and managing the social graph.\

\


1) Requirements\

\

1.1 Functional\

  • Post photos and videos: Users can upload and share media.\
  • Follow and unfollow users: Users can follow/unfollow other users.\
  • Like or dislike posts: Users can like/unlike posts from followed accounts.\
  • Search photos and videos: Search by captions, hashtags, and location.\
  • Generate news feed: View posts from followed users in chronological order.\
  • Comment on posts: Users can comment on posts.\
  • Share posts: Users can share posts with others.\
  • View user profiles: See user's posts, followers, following count.\
  • Notifications: Notify users of likes, comments, new followers.\
\

1.2 Non-Functional\

  • Scalability: Support 1 billion+ users, 500M daily active users.\
  • Availability: 99.99% uptime.\
  • Low Latency: News feed load < 500ms, image load < 200ms.\
  • Storage: Petabytes of photos and videos.\
  • Consistency: Eventual consistency acceptable for likes/follows.\
  • Reliability: No data loss for uploaded media.\
\

1.3 Scale Estimates\

  • Users: 1 billion total, 500M daily active users (DAU).\
  • Posts: 100M photos/videos uploaded per day.\
  • Avg media size: Photos 2 MB, videos 20 MB.\
  • Storage per day: 100M posts × 2 MB (avg) = 200 TB/day.\
  • Total storage: 200 TB/day × 365 days × 5 years = 365 PB.\
  • News feed requests: 500M DAU × 10 feeds/day = 5B feed requests/day (~60K/sec).\
  • Follow/unfollow: 50M operations/day.\
  • Likes: 4 billion likes/day.\
\

---\

\

1.4) API Specifications\

\

Post Management APIs\

  • POST /api/posts - Create new post with photo/video and caption\
  • GET /api/posts/{post_id} - Get post details including media, caption, likes count\
  • DELETE /api/posts/{post_id} - Delete a post\
  • PUT /api/posts/{post_id} - Edit post caption or location\
\

Social Interaction APIs\

  • POST /api/follow - Follow a user\
  • DELETE /api/follow/{user_id} - Unfollow a user\
  • POST /api/likes - Like a post\
  • DELETE /api/likes/{post_id} - Unlike a post\
  • POST /api/comments - Comment on a post\
  • GET /api/comments/{post_id} - Get comments for a post\
\

Feed & Discovery APIs\

  • GET /api/feed - Get personalized news feed (posts from followed users)\
  • GET /api/explore - Get trending and recommended posts\
  • GET /api/search - Search posts by caption, hashtags, or location\
  • GET /api/hashtags/{tag} - Get posts with specific hashtag\
\

User Profile APIs\

  • GET /api/users/{user_id} - Get user profile with stats (followers, following, posts count)\
  • GET /api/users/{user_id}/posts - Get all posts by a user\
  • GET /api/users/{user_id}/followers - Get list of followers\
  • GET /api/users/{user_id}/following - Get list of users being followed\
\

Media APIs\

  • POST /api/upload - Upload photo or video\
  • GET /api/media/{media_id} - Get media file (returns CDN URL)\
\

Notification APIs\

  • GET /api/notifications - Get user notifications (likes, comments, new followers)\
  • PUT /api/notifications/{notif_id}/read - Mark notification as read\
\

---\

\

2) High-Level Architecture\

\

2.1 Overview\

  • Upload Pipeline: User → Upload Service → Object Storage (S3) → CDN.\
  • Feed Pipeline: User → Feed Service → Follow Graph → Posts DB → Ranked Feed.\
  • Social Graph: Follow Service manages followers/following relationships.\
  • Key components: Media storage (S3 + CDN), feed generation (fan-out), search indexing, notification system.\
\

2.2 Architecture Diagram\

```mermaid\

---\

config:\

layout: elk\

---\

flowchart TB\

%% User and Frontend\

User[\

More Case Studies

Practice with a Mock Interview

Apply what you learned in a live system design mock interview with our AI interviewer.

Start System Design Interview →