The whole course ▾

System Design · Mock interview 2 of 20

Design Instagram: posting and viewing photos

Updated 22 Oct 2026 · By Akshay, software engineer, India · 9 min read

Design Instagram, posting and viewing photos.

Try it first

Before you read the interview, answer the question yourself. Give yourself 10 minutes: say your design out loud, or sketch it on paper. What would you ask? Which numbers matter? Which boxes, and what's the hard part? Then read on, and score yourself with the feedback at the end.

Got a doubt? Ask in the comments under the video.Subscribe

Requirements

Requirements
Clarifying questions
->
Photos only, or video too? -> Photos
->
A feed of people you follow? -> Yes
->
How many daily users? -> 100 million
->
Likes and comments? -> Not today
Functional requirements
Upload a photo with a caption
Follow other people
See a feed of followed accounts
Open any photo quickly
Non-functional requirements
->
100 million daily users
->
Feed loads in under 500 ms
->
A photo is never lost
->
Available beats perfectly consistent
Out of scope
Videos and stories
Likes, comments and search
Direct messages
interviewer
Hi, good to see you. Shall we start?
candidate
Yes, let's. I'll sketch on the whiteboard as I go.
interviewer
Today, let's design Instagram. Posting photos, and viewing them.
candidate
Okay. That's a big product, so before I draw anything, let me ask a few questions to narrow it down.
interviewer
Sure.
candidate
Is it photos only, or video too?
interviewer
Photos only.
candidate
Do users see a feed of the people they follow?
interviewer
Yes.
candidate
How many daily users should I plan for?
interviewer
About a hundred million.
candidate
And likes and comments?
interviewer
Not today.
candidate
Great, that's much smaller. Let me write what users can do. Upload a photo with a caption. Follow other people. See a feed of the accounts they follow, newest first. And open any photo quickly.
candidate
Then how well it has to work. A hundred million daily users. The feed loads in under five hundred milliseconds. A photo, once uploaded, is never lost. And if I have to choose, I'd rather stay available than be perfectly consistent. Is it okay if a new photo shows up in a friend's feed a few seconds late?
interviewer
Yes, that's fine.
candidate
Good, because that choice shapes a lot of the design.
candidate
I'll leave out videos and stories, likes, comments and search, and direct messages. Does that list look right to you?
interviewer
Looks right. Go ahead.

Estimation

Estimation
Back of the envelope
10M uploads a day ÷ 100,000 s ~ 100/s
Peak ~ 3 × 100 = 300 uploads/s
100M users × 10 feeds = 1B feed loads/day
1B ÷ 100,000 s ~ 10,000 feed reads/s
10M × 2 MB = 20 TB a day ~ 7 PB a year
Follows: ~200 each; a celebrity: 50M followers
WHAT THE NUMBERS DECIDE
Readsbeatwrites100to
1:optimisereads.And7
PBayearmeansobject
storage,neveradatabase.
candidate
Let me do some quick numbers. Only the ones that change the design.
interviewer
Sure. Roughly how much traffic and storage are we talking about?
candidate
I'll use two shortcuts: a day is about a hundred thousand seconds, and peaks are about three times the average.
candidate
Say one user in ten posts a photo a day. That's ten million uploads, about a hundred a second, with a peak around three hundred. If each user opens the app about ten times a day, that's ten feeds each: a billion feed loads a day, so about ten thousand feed reads a second. At two megabytes a photo, that's twenty terabytes of new photos a day, about seven petabytes a year.
interviewer
What about followers?
candidate
People follow about two hundred accounts on average. But a celebrity can have fifty million followers. I'll keep that in mind.
candidate
So, two decisions. Feed reads beat uploads a hundred to one, so this is read-heavy, and I'll optimise reads with caches and a CDN. And seven petabytes a year means photos go into object storage, never into a database.
interviewer
Makes sense.

API and data

API and data
Users
id, name
Photos
id, user_id, key,
caption, time
Follows
follower, followee
1 : many
1 : many
Endpoints
1
POST /photos -> a presigned
upload URL
2
POST /photos/{id}/publish
3
POST /users/{id}/follow
4
GET /feed?cursor=… -> 20
photos
5
GET /users/{id}/photos -> a
profile grid
candidate
Next, the API, and the data.
interviewer
What does the API look like?
candidate
Let me list the endpoints: the method, the path, and what comes back.
candidate
POST slash photos returns a presigned upload URL. When the upload finishes, the app calls publish with the caption, and only then does the photo appear. Follow adds a follow. GET slash feed returns twenty photos at a time, with a cursor, so scrolling never repeats or skips a photo while new ones arrive. And GET slash users, an ID, slash photos fills a profile grid.
interviewer
Why the presigned URL?
candidate
So the image bytes go straight to storage, and never pass through our servers.
candidate
Three tables. Users. Photos: the owner's ID, the photo's key in object storage, the caption and the time. And follows: who follows whom. The photo table only stores a key, a few bytes, never the image.
interviewer
Which database?
candidate
Postgres. Small rows with clear relationships. And one index from day one: photos by user and time, because that's exactly what a feed asks for.
interviewer
Why not a NoSQL store?
candidate
We could. But the queries here are simple lookups on a few hundred million rows, Postgres handles that well with the right index, and I get transactions for free.

High-level design

High-level design
Mobile
app
Load
balancer
Photo
service
Photos
DB
Object
storage
Resizer
background
worker
POST
/photos
1
save
metadata
2
upload photo
3
new file
4
3 sizes
5
Feed
service
CDN
GET
/feed
photos of
people I follow
load
images
only on a
miss
Reading a feed
1
Who do I follow?
2
Their recent photos
3
Merge by time, keep 20
4
Image URLs point at the CDN
TWO GOALS
Keepthebytesaway
fromtheservers,and
thereadsawayfrom
thedatabase.
candidate
Okay, let me draw the main design.
interviewer
Walk me through it.
candidate
Two paths: posting a photo, and reading the feed. I'll start with the upload.
candidate
The mobile app calls POST slash photos through the load balancer, which picks one of many photo service instances. They keep nothing between requests, so any of them can take any request. The service saves the photo's details in the photos DB and returns a presigned URL. The app uploads the photo straight to object storage. Storage announces the new file, and a background resizer makes three sizes: a thumbnail, a feed size and a full size.
interviewer
Why resize in the background?
candidate
So the upload returns at once. Resizing takes a second or two, and the user shouldn't wait for it.
candidate
Now reading. GET slash feed reaches the feed service, which asks the database for recent photos from everyone you follow, and returns twenty, each with an image URL. The app loads the images from the CDN, which only goes to object storage on a miss.
interviewer
So the image traffic never hits your servers?
candidate
Right. Only the ten thousand feed requests a second do.
candidate
So a feed request does four things. Look up who I follow. Fetch each account's recent photos. Merge them by time and keep the newest twenty. And return image URLs that point at the CDN.
interviewer
Steps two and three sound expensive.
candidate
They are. That's where the time goes.
interviewer
So where are you now?
candidate
I have two goals. Keep the image bytes away from our servers, which is done. And keep the reads away from the database, which isn't done yet.
interviewer
Then let's talk about that.

Deep dive: the feed

Deep dive: the feed
Pull: build it when asked
Query everyone I follow
Merge by time, take 20
Slow for big follow lists
Push: build it in advance
Write each photo into followers' feeds
Reading is one lookup
Costly for celebrities
THE CHOICE
Pull,plusacacheofeach
user'srecentphotoIDs:fast
enoughforpeoplefollowinga
fewhundredaccounts.
High-level design
Mobile
app
Load
balancer
Photo
service
Photos
DB
Object
storage
Resizer
background
worker
POST
/photos
1
save
metadata
2
upload photo
3
new file
4
3 sizes
5
Feed
service
CDN
GET
/feed
photos of
people I follow
load
images
only on a
miss
Recent
photos
Redis, per
user
last 100
photo IDs
Reading a feed
1
Who do I follow?
2
Their recent photos
3
Merge by time, keep 20
4
Image URLs point at the CDN
TWO GOALS
Keepthebytesaway
fromtheservers,and
thereadsawayfrom
thedatabase.
interviewer
I'd like to go deeper on the feed.
interviewer
How do you build the feed fast, for a hundred million users?
candidate
There are two classic ways. Let me compare them.
candidate
Option one, pull: when you open the app, fetch recent photos from everyone you follow, merge them by time, and return twenty. Simple and always fresh, but slow when you follow many people. Option two, push, also called fan-out: when someone posts, write the photo into each follower's ready-made feed, so reading is one lookup. Fast to read, but a celebrity's post means writing into fifty million feeds.
interviewer
Which one would you pick?
candidate
It depends on who's posting. Let me explain.
candidate
I'd start with pull, made fast with a cache. The typical user follows a few hundred accounts, and with each account's recent photos already in memory, merging a few hundred short lists takes milliseconds. It's simpler, it's always fresh, and I can add fan-out later for the heaviest users.
interviewer
Okay. Show me.
candidate
The feed service now reads a recent photos cache in Redis: for each user, the IDs of their last hundred photos. Building a feed is one batched lookup for everyone you follow, a merge by time, and twenty results with a cursor. The photos database is only touched on a miss, and for the details of the twenty photos we return.
interviewer
What happens on a cache miss?
candidate
The feed service reads that user's recent photos from the database, using the user and time index, and puts them back in the cache for next time.
interviewer
Someone follows two thousand accounts. Is pull still fast?
candidate
No. Two thousand lookups on every app open is too slow. For heavy followers, I'd cache their merged feed for a minute and refresh it in the background. And for the truly extreme cases, that's where fan-out comes in.
interviewer
How fresh is that cached feed?
candidate
Up to a minute old, which our requirements allow.

Deep dive: a celebrity posts

Deep dive: a celebrity posts
PULL WINS HERE
Acelebrity'spostcosts
onewrite,not50million:
followerspullitontheir
nextrefresh.
Three sizes per photo
->
Grid thumbnail: 150 px
->
Feed: 600 px
->
Full: 1,080 px, on tap
High-level design
Mobile
app
Load
balancer
Photo
service
Photos
DB
Object
storage
Resizer
background
worker
POST
/photos
1
save
metadata
2
upload photo
3
new file
4
3 sizes
5
Feed
service
CDN
GET
/feed
photos of
people I follow
load
images
only on a
miss
Recent
photos
Redis, per
user
last 100
photo IDs
50M views
hot key: replicas
Reading a feed
1
Who do I follow?
2
Their recent photos
3
Merge by time, keep 20
4
Image URLs point at the CDN
TWO GOALS
Keepthebytesaway
fromtheservers,and
thereadsawayfrom
thedatabase.
interviewer
Now a classic one.
interviewer
A celebrity with fifty million followers posts a photo. What happens?
candidate
Let me go layer by layer: the image first, then the data.
candidate
The image is the easy part. Millions of people load the same file, so each CDN edge fetches it once and serves everyone near it. Our storage barely notices. The data is harder. The celebrity's recent photos entry is read by fifty million feeds: a hot key. So it gets replicas, and each feed service keeps a five second local copy. One cache machine can't melt.
interviewer
How do you know a key is hot?
candidate
The cache counts reads per key. Anything above a threshold gets copied to more machines automatically.
interviewer
And how does the new post reach fifty million feeds?
candidate
With pull, it doesn't have to. Nothing is written into anyone's feed. Each follower's next refresh reads the celebrity's recent photos entry, the hot key we just protected, and the new photo is simply there.
interviewer
Doesn't every refresh then hit that one entry?
candidate
Yes. That's exactly why the replicas and the local copy matter.
candidate
That's the trade-off. With push, one celebrity post means fifty million feed writes, which could take many minutes. With pull, it's one write, and the cost moves to reads, where the cache is already doing the work.
interviewer
So would you ever use push?
candidate
Yes, for normal accounts with few followers. Big systems usually mix the two.
candidate
And since fifty million phones will load it, size matters. The grid thumbnail is about a hundred and fifty pixels, the feed size about six hundred, and the full image only loads on a tap. That cuts the CDN traffic, and the waiting, many times over.
interviewer
Who makes these sizes?
candidate
The resizer, right after the upload. The app asks for the size it needs in the image URL.
interviewer
What if they delete it a minute later?
candidate
I'd mark the photo deleted in the database, and remove it from the recent photos cache, so no new feed includes it. Feeds already on screen keep it until their next refresh. The CDN copies become unreachable and expire on their own. If it really must vanish everywhere at once, I'd purge the CDN too, which is slower.

Wrap-up

Wrap-up
Next steps
1
Photos DB: shard by user ID
2
Heavy followers: fan-out
3
Watch upload errors and CDN hit rate
4
More regions for global users
INTERVIEWER'S FEEDBACK
Strong:askedfirst,designedfor
reads,filesbehindaCDN,adapted
whenpushed.Nexttime:raisethe
celebrityproblemyourself.Verdict:hire.
interviewer
We have a few minutes left.
interviewer
What would you improve with more time?
candidate
Let me name the weak spots myself.
candidate
First, the photos database grows by ten million rows a day, so eventually I'd shard it by user ID. Second, heavy followers get fan-out. Third, I'd watch upload errors and the CDN hit rate, because those two warn you first. And fourth, for users around the world, more regions, closer to them.
interviewer
Which of these would you do first?
candidate
The watching. You can't fix what you can't see.
interviewer
Okay, let's stop there. Good job. You narrowed the problem before drawing, you saw it was read-heavy, you kept the photos in object storage behind a CDN, and when I pushed back, you adapted instead of defending. One thing: the celebrity problem is famous, so bring it up yourself next time, before I ask. I'd say a hire.
candidate
Thanks. That's fair.
Interviewer's feedback

Strong: asked first, designed for reads, files behind a CDN, adapted when pushed. Next time: raise the celebrity problem yourself. Verdict: hire.

Score yourself

Interviewers score these seven things. Give your own attempt a tick for each one you did.

  • Asks before drawing. Agrees what the system does, and how well: scale, speed, consistency.
  • Turns users into requests a second and bytes a day, and says what the numbers decide.
  • A small, clear contract, and a data model that fits how the data is read.
  • A working path end to end before any detail. Every box has a reason.
  • Picks the hard parts, compares two options, and chooses one with a trade-off said out loud.
  • What breaks, what happens then, and how users notice. Retries, duplicates, limits.
  • Thinks out loud, checks in with the interviewer, and takes a hint without losing the thread.

0 of 7

Your progress stays on this device.
New System Design videos at 6 pm

Lessons on weekdays, the week's revision on Saturday, a mock interview on Sunday.