“Design Instagram” is one of the most reported questions from Meta interviews, and a favourite at many product companies. It looks like the news feed plus YouTube, and it is: the new part is handling hundreds of millions of photos a day without letting those heavy bytes crush your servers.
Step 1 · Requirements
- Functional: upload a photo (or short video) with a caption; follow people; see a home feed of people you follow; like and comment; post stories that vanish after 24 hours; view a profile grid.
- Non-functional: feed loads fast (under ~500 ms); uploads never get lost; images look sharp on any phone; highly available (a slightly stale like count is fine); very read-heavy.
- Out of scope (say it): Explore and Reels recommendations, direct messages (see the chat design), ads, search.
Step 2 · Estimates
- Users: 500 million daily active users.
- Uploads: 100 million photos a day ≈ 1,200 uploads/s on average, maybe 3,000/s at peak.
- Storage: ~3 MB original + ~1 MB of resized versions = 4 MB × 100 M = 400 TB a day, about 150 PB a year. This is why bytes go to object storage, never the database.
- Reads: each user opens the feed ~10 times a day and sees ~20 photos → 100 billion image views a day. Reads outnumber writes about 1,000 to 1. Caches and the CDN are the whole game.
Step 3 · API
POST /media/upload-url { type: "image/jpeg", size: 3100000 } → { mediaId, uploadUrl (pre-signed, 10 min) }
PUT {uploadUrl} (photo bytes, sent straight to object storage)
POST /posts { mediaIds: ["m_81"], caption: "Goa sunset 🌅" } → { postId }
GET /feed?cursor=… → [{ postId, author, imageUrls: { s150, s640, s1080 }, likeCount, … }], nextCursor
POST /posts/{id}/likes → 204
POST /stories { mediaId } → { storyId, expiresAt }Step 4 · Design
The upload: keep heavy bytes away from app servers
🎮 Where should the photo bytes go?
Photo traffic through app servers
≈ 0 GB/s
only small API calls
App servers needed just for uploads
2
storage scales on its own
Drag the slider to peak traffic and flip the switch. With pre-signed URLs, app servers only hand out permission slips; storage and the CDN carry the heavy bytes. That is why every big media app uploads this way.
| Data | Where it lives | Why |
|---|---|---|
| Photo and video files | Object storage + CDN | Huge, never edited, cheap per GB, served close to users |
| Users, posts, captions, follows | Sharded relational DB (or a wide-column store) | Structured; queried by user; needs reliable writes |
| Feed lists (post IDs per user) | Redis / in-memory cache | Read on every app open; rebuildable |
| Like and view counts | Fast counter store, saved to DB in batches | Very hot writes; exact-to-the-second not needed |
| Stories | DB rows with expiresAt + TTL | Disappear after 24 hours automatically |
IDs that sort by time and know their shard
Instagram's engineers described a neat ID scheme: a 64-bit number built from the time, the shard that owns the data, and a sequence number. Sorting IDs sorts posts by time, and the ID itself says which database shard to read. It's a cousin of the Snowflake IDs from the URL shortener.
| 41 bits: milliseconds since a custom epoch | 13 bits: shard ID | 10 bits: sequence | → about 69 years of IDs, 8,192 shards, 1,024 IDs per shard per millisecond
Step 5 · Scale and reliability
- Shard metadata by user ID: a profile grid (“all posts by Riya”) is a single-shard query, and the shard is inside the post ID.
- Feed: push post IDs to followers' feed lists in the background through a queue; pull in celebrity posts at read time. The full reasoning is in the news feed lesson.
- Hot likes: count likes in Redis (or split a hot post's counter across several keys) and write totals to the database every few seconds. Store the “who liked” rows separately, so a user can't like twice.
- CDN everything: image URLs point at the CDN with the size in the path. Files are never edited, so they can be cached for a very long time.
- Processing failures: the queue retries failed resizes; the post stays “processing” until its sizes exist. Workers are idempotent, so a retry just overwrites the same files.
- Privacy and safety: strip EXIF location data; run images through automated safety checks before they reach followers; private accounts check permissions before returning post details.
🧠 PATH memory card
Remember the Instagram design for good
Picture it · Anchor it · Trace it · Hit-recall it. Four quick steps that turn “I read it once” into “I can explain it in an exam”.
- P
Picture it
Your brain remembers scenes far better than definitions.
← swipe to see the whole picture →
At a big wedding, the photographer doesn't hand heavy albums to the security guard. The guard signs a permission slip, and the photographer puts the albums straight into a locker room. A print shop takes each photo and makes small, medium and large prints. Guests pick up copies from a kiosk near their own seats instead of queueing at the locker.
- A
Anchor it
A silly sentence you can't forget, where every word maps to the concept.
“Slip, Locker, Print shop, Kiosk”
- Permission slip→Pre-signed URL from the post service
- Locker room→Object storage for original files
- Print shop→Queue + workers: resize, convert, strip GPS
- Kiosk near you→CDN edge serving the right size
- Guest list→Metadata DB + feed fan-out
- T
Trace it
Run it by hand on a tiny example once. Doing beats reading.
Riya taps Share on a 3 MB sunset photo. The app getsm_81and a 10-minute upload URL, PUTs the file to storage, and a “file uploaded” event lands in the queue. A worker writes 150, 640 and 1080 px WebP versions with GPS removed. The app creates postp_9f2; fan-out writes it into her 400 followers' feed lists. Arjun opens the app in Pune, the feed returnsp_9f2, and the 640 px image arrives from the Mumbai CDN edge. - H
Hit-recall it
Test yourself now, then again on the day each card comes back.
Card 1 / 8 · new0 mastered · 0 practisedSay the answer out loud first, then flip and be honest.
Follow-up questions interviewers ask
- “Support video (Reels)?” Same upload path, but workers transcode into several bitrates for adaptive streaming, as in the YouTube design.
- “Show a new post to its author instantly?” Insert it into the author's own feed and profile cache right away (read-your-own-writes), even before fan-out finishes.
- “A user deletes a post?” Mark it deleted in metadata so feeds skip it at read time; remove files and CDN copies in the background.
Where to go next
Instagram can show a like count that's a few seconds old. The next part can't be even slightly wrong: two fans, one seat, in design BookMyShow. Want the algorithm behind a ranked feed? Practise heaps and top-K.
Key takeaways
- ✓Upload photos straight to object storage with pre-signed URLs; app servers only hand out permission.
- ✓A queue and workers resize images, convert formats and strip GPS data.
- ✓Metadata goes in a database sharded by user; images are served by a CDN.
- ✓Feeds use hybrid fan-out; hot like counters are aggregated and batch-written.
- ✓Stories store an expiry time and are filtered out after 24 hours.
Frequently asked questions
How does Instagram store photos?
The image files go to object storage (like Amazon S3), which is cheap and scales without limit. A database stores only the metadata: who posted it, the caption, the time and the storage keys of each resized version. Users download the images through a CDN, so most requests never reach Instagram's own servers.
What is a pre-signed URL?
A temporary link, signed by the server, that lets a client upload (or download) one specific file directly to object storage for a few minutes. The app server checks the user and hands out the link; the heavy file bytes then go straight to storage instead of through the app servers.
Why does Instagram resize every photo?
A phone shows a 150-pixel thumbnail in a grid and a 1080-pixel image in the feed. Sending the full original everywhere would waste mobile data and slow scrolling. Workers create a few standard sizes (and modern formats like WebP or AVIF) once, after upload, and the app requests the size it needs.
How does the Instagram home feed work?
The same way as other social feeds: when someone posts, the post ID is pushed into a precomputed feed list for each follower (fan-out on write), except for accounts with millions of followers, whose posts are pulled in when the follower opens the app (fan-out on read). A ranking step then orders the candidates.
How do Instagram stories disappear after 24 hours?
Each story is saved with an expiry time. Reads only return stories whose expiry is in the future, and a time-to-live (TTL) setting or a cleanup job removes the expired records and files later. The story never needs to be deleted at exactly the 24-hour mark to vanish from the app.
🧠 Quick check: Instagram design
1. Where should the 3 MB photo bytes go when a user uploads?
2. Why strip EXIF data from uploaded photos?
3. A celebrity with 300 million followers posts. Best feed strategy?
4. A post gets 50,000 likes a minute. How should the like counter work?
Checking your access…