SimuVedaSystem Design Lab Open in the lab

Design interviews / Intermediate / 5 min

Design Instagram: photos through a CDN

Popular photos served from edge caches in each city. Turn the CDN off or send 4 MB originals and watch load time and origin traffic.

Start the simulation → Change the load, break a part, watch what happens. Free, no sign-up.

In short

What it is
Instagram stores each upload once in object storage, makes resized copies, and serves them to phones through a CDN with edges in every region.
Why it matters
Photos are most of the bytes in a feed and a few posts get huge view counts, so serving them from one place would be slow and costly.
The trade-off
Bigger edge caches raise the hit rate but cost money; very new or rare photos still miss and go to the origin.
Say it in an interview
"Upload to S3 via a pre-signed URL, async resize workers make several sizes, CDN in front with long cache headers, and the feed API returns only URLs."

Check yourself

Why does a small CDN cache still serve most photo requests?

Answer: A few popular photos get most of the views, and those stay in the cache. Views follow a long-tail (Zipf) pattern, so the top few percent of photos cover most requests.

What is the main win from resizing photos at upload?

Answer: Phones download about 150 KB instead of 4 MB, so photos load far faster. Transfer time on a phone network dominates; small feed-sized copies cut it by an order of magnitude.

With the CDN off, what happens to the photo store?

Answer: Every view becomes a request to the origin, so its load grows with total views. Edges absorb repeat reads; without them the origin must serve every request, from far away.

See it happen in the simulation →

instagramcdnedge cachelruimage resizingobject storage

More in design interviews