Question presented to candidate: "Design Instagram. Users upload photos with captions, follow other users, see a feed of photos from people they follow, and like and comment. Assume a hundred million uploads a day and a few hundred million daily viewers."
What a strong answer should cover:
- Capacity: uploads per second, storage per day and per year for several resized variants, and image views per second, which shows the system is a read-heavy media delivery problem
- The upload path: client uploads directly to object storage with a presigned URL, an event triggers asynchronous processing (resize into variants, strip metadata, moderation), and the post becomes visible when processing finishes
- Serving images through a CDN with immutable, content-addressed URLs, and keeping the origin out of the read path
- Metadata (users, posts, follows, likes) in a sharded relational store with logical shards mapped onto fewer physical servers, and IDs that embed time and shard (Instagram published a 41-bit time, 13-bit shard, 10-bit sequence layout)
- The feed built by fan-out as in the timeline design, like counters aggregated asynchronously, and what breaks at 10x (hot posts, celebrity accounts, storage cost)
Clarifying questions expected:
- Photos only, or video and stories too? (Stories add expiry; video is the YouTube problem.)
- Which features are in scope: feed, likes, comments, search, explore?
- What is the read to write ratio and latency target for the feed?
Code / implementation expected: Optional โ an ID generator that embeds time and logical shard, routing a post to its database from its id, and the effect of doubling the servers; the example does that and computes the capacity numbers.