Photo Sharing
Design a photo-sharing service where people upload photos, follow each other, see a feed of posts and 24-hour Stories, and like and comment.
Overview
In this service, people post photos with a caption, follow other accounts, and scroll a feed of posts from the accounts they follow. Stories are photos or short videos that followers can see for 24 hours. People like and comment on posts.
The home feed looks like the Twitter problem, and the same push and pull trade-off applies (the Twitter / X topic covers fan-out in depth). What makes this problem different is the media: every post is a file of a few megabytes that must be stored durably, resized for every screen, and served quickly everywhere, while the database holds only small rows about it. The other interview favorite is how Instagram itself made IDs and sharded PostgreSQL, which its engineers wrote up in 2011.
Questions to ask first
- How many users and posts? — 500 million daily active users; 100 million new photo posts a day
- How much viewing? — About 100 image views per user a day
- Photos, video or both? — Photos in depth; video uses the same path with transcoding instead of resizing
- Chronological or ranked feed? — Ranked, built on the chronological candidate set
- How fresh must the feed be? — Seconds of delay are fine; the author sees their own post at once
- What happens after 24 hours to a Story? — Followers can no longer see it; the owner can keep it as a Highlight on their profile
What you will be able to do
- Design the upload path so photo bytes never pass through your application servers.
- Size image storage and CDN traffic, and explain why the CDN hit rate decides the origin's size.
- Explain Instagram's 64-bit IDs and logical shards, and write them in PostgreSQL.
- Build the feed and Stories on top of the fan-out ideas from the Twitter problem.
- Keep like counts correct and cheap on a post that goes viral.
Key concepts
- Direct-to-storage upload
- Image renditions
- CDN hit rate
- Time-sortable 64-bit IDs
- Logical shards
- Fan-out on write
- Ranked feed
- Stories with expiry
- Counter hot spots
Functional requirements
- Upload a photo post with a caption; it appears in followers' feeds
- Follow and unfollow accounts
- Read a ranked home feed in pages
- Post Stories that followers can see for 24 hours
- Like and comment; show counts on each post
- View a profile grid of a user's posts, newest first
Non-functional requirements
- A feed page loads in under 300 ms at p99, not counting image downloads (a target we chose)
- Images load from a nearby CDN edge; most requests never reach storage
- An uploaded photo is never lost once the post is confirmed
- Feeds may lag a few seconds; the author sees their own post at once
- Reads stay available during failures, even if counts are briefly stale
Interview questions
- Walk me through uploading a photo.
- How do you serve images fast everywhere, and how big is the origin?
- How did Instagram generate IDs across shards, and why not Snowflake?
- Why logical shards instead of one shard per server?
- How is the feed built?
- How do Stories expire after 24 hours?
- How do you handle likes on a post that goes viral?
- What happens when a user makes their account private?
Sign up free to read the full topic
More System Design topics
Start free on Cariara · Coding problems · System design studio