Design Instagram the way a senior interview expects: uploads processed in the background, posts fanned out into precomputed timelines (with celebrities pulled at read time), a ranked feed with a fallback, stories that expire, hot counters, and media through a CDN.
Unlock it once for 25 credits; everything inside it is free (runs, changes, Submit, results, hints). Sign in with Google to start; new accounts get free credits.
What it must do
Post a photo or video with a caption: the media goes to object storage, and is resized or transcoded into several renditions in the background.
Load the home feed: recent posts from the accounts you follow, read from a precomputed timeline, ranked for you, a page at a time.
Fetch photos and videos through a CDN, in the size the device needs.
Like, comment and follow: the action is saved at once; counts may lag by a few seconds.
Open a profile: name, bio, follower counts and a grid of the account’s posts.
Stories: posts that disappear after 24 hours, shown in a tray at the top of the feed.
Private accounts: only approved followers see their posts and stories.
Scale
Assume 500 million daily active users who open the feed about 10 times a day: about 58,000 feed loads a second on average, twice that at the evening peak.
About 100 million new photos and videos a day (about 1,200 a second). An average account has about 200 followers; a few have more than 100 million.
Each photo is kept as the original plus about 4 resized versions, about 2.5 MB in all. The CDN serves about 90% of media fetches.
The simulator runs a scaled-down slice: 2,500 requests a second: 1,000 media fetches, 625 feed loads, 300 stories-tray loads, 300 likes, comments and follows, 200 profile views and 75 new posts. Writes are over-represented so every path is exercised.
Scrapers harvesting public profiles arrive in bursts of thousands of requests a second from rotating addresses.
Request types to route: media (40%, read), feed (25%, read), stories (12%, read), engage (12%, write), profile (8%, read), post (3%, write). Budget: $26,000 a month.
Estimate first
Feed loads a second, on average (req/s)
Feed loads a second at the evening peak (2× the average) (req/s)
New posts a second (posts/s)
New photo storage a day, before replication (TB)
Timeline writes a second from fan-out on write (writes/s)
Memory to cache every daily user’s timeline (500 post IDs each) (GB)
Average media bandwidth out of the CDN for photos (Gbps)
Monthly cloud cost of your design (the simulated slice) (USD)
The test cases
You start from an empty canvas. When you run the tests, each one simulates your design with its own traffic and failures:
Test
What it does
Passes when
Normal day
The normal day: the traffic in the brief, nothing broken.
Success ≥ 99.9%; p99 latency ≤ 250 ms (feed); p99 latency ≤ 200 ms (media); Success ≥ 99.8% (post)
A celebrity posts
At 5 s an account with over 100 million followers posts. For 8 s traffic triples: followers refresh their feeds, open the profile and like the post, so one like counter takes a large share of every like.
At 5 s the first application cache on the request path (the timeline cache) is emptied, as after a bad deploy or a cluster restart: every feed load misses until it warms up.
Success ≥ 99%; p99 latency ≤ 400 ms (feed)
Media CDN purged
At 5 s the media CDN is purged (a bad cache-key change, or a new edge region coming up cold): every photo and video fetch goes to the origin until the CDN warms up.
At 5 s the feed ranking model answers 10× slower for 8 s, as after a bad model push or lost inference hosts.
Success ≥ 99% (feed); p99 latency ≤ 450 ms (feed)
A server dies
At 4 s one server of the first app service on the request path dies for 10 s.
Success ≥ 99%; p99 latency ≤ 400 ms (feed)
Scrapers
At 5 s 6,000 requests a second of scraping traffic arrive for 10 s, alongside real users.
Attack blocked ≥ 90%; Success ≥ 99%
Fan-out stream crashes
At 5 s the stream that carries new posts to the fan-out workers crashes and takes 10 s to restart. Posts made meanwhile must still reach their followers’ feeds.
No lost events; Success ≥ 99% (post)
Budget: $26,000/month
The normal day's design must cost at most $26,000 a month.
Cost ≤ $26,000/month
Must include
A CDN for media. Photos and videos are almost all of the bytes and most of the requests; the edge must serve the popular ones.
Object storage for photos and videos. Billions of immutable blobs, written once and read through the CDN: object storage is the CDN’s origin.
Media processing. Every upload is resized (photos) or transcoded (videos) into the renditions the apps request; it is slow, so it runs behind a queue.
A fan-out pipeline. Writing a post into 200 followers’ timelines must happen off the request path: a stream or queue and workers.
A durable timeline store. Precomputed timelines (a list of post IDs per user) live in a wide-column store, so a flushed cache does not lose them.
A feed ranking model. The feed is ordered by predicted interest, scored for the viewer on every load.
A time-ordered ID generator. Post IDs must be unique across shards and sort by time, so timelines and pagination cursors can use them directly.