Design Instagram
Understanding the Problem
📸 What is Instagram? Instagram is a photo and video sharing app. Users post photos with captions, follow other accounts, and scroll a feed of posts from the accounts they follow. Accounts can be public, or private, in which case a follow has to be approved first.
On the surface this looks like Twitter with pictures, and the feed part really is close to the same problem. What changes is the weight of each post. A tweet is a few hundred bytes; a photo is a few megabytes that has to be uploaded over a phone connection, resized into several versions, stored for years and delivered to millions of screens. Most of the interesting design is in that media pipeline.
Functional Requirements
Core Requirements
- Users should be able to upload a post: one or more photos (or a short video) with a caption.
- Users should be able to follow and unfollow other users, including requesting to follow a private account.
- Users should be able to view a feed of recent posts from the accounts they follow, newest first, paging as they scroll.
Below the line (out of scope)
- Likes, comments and their notifications.
- Search, Explore and recommended content.
- Stories (a separate problem: see /system-design/instagram-stories).
- Filters and editing, which happen on the device before upload.
- Long-form video. We'll support short clips and note where a full video pipeline would plug in.
Non-Functional Requirements
Ask your interviewer about scale and what matters most. We'll assume 500 million daily active users and 100 million new posts a day.
Core Requirements
- The system should load the feed in under 500ms, with images appearing almost immediately as the user scrolls.
- The system should be highly available, favoring availability over consistency. A new post can take a few seconds to reach followers' feeds.
- Uploads should be reliable on flaky mobile networks. A dropped connection shouldn't mean starting a 20MB upload over.
- Media must be durable. A photo that was posted should never be lost.
- The system should scale to hundreds of petabytes of media at a sustainable cost.
Below the line (out of scope)
- Strong consistency for counts (likes, followers).
- Content moderation, though we'll leave a hook for it in the processing pipeline.
The numbers explain where the effort goes:
- Upload rate: 100M posts / 86,400s ≈ 1,200 posts/s on average, maybe 3-5x at peak.
- Ingress: at roughly 2MB per original photo (phones compress before upload), that's about 2.4GB/s coming in.
- Storage: an original plus a handful of resized versions is about 3MB per photo, so ~300TB a day, or on the order of 100PB a year.
- Feed reads: 500M users opening the feed ~10 times a day is 5B feed loads, about 58k/s.
- Image egress: if each user scrolls past ~100 images a day at ~200KB each (feed-sized, not the original), that's 50B × 200KB = 10PB a day, roughly 115GB/s or close to 1 Tbps.
Nearly a terabit per second of image traffic can't come from our own servers. The design has to put a CDN in front of every image and keep application servers out of the byte path, on both upload and download.
When the numbers say "petabytes", say out loud which bytes go where. The metadata (posts, follows, feeds) is a normal distributed database problem. The media is an object storage and CDN problem. Keeping those two paths separate is the core of a good answer.