System design interview: design Instagram

Designing Instagram is mostly about media: getting photos from a phone into object storage without routing bytes through your servers, producing the few sizes each screen needs, and serving them from a CDN under URLs that never change. On top of that sit a follow graph, a home feed built with hybrid fan-out, like counts that cannot be a single row, and stories that must disappear after 24 hours.

By Published 9 min read

1. Clarify the requirements

A photo app has dozens of features. Pick a small, coherent slice and say what you are leaving out so the interviewer can redirect you if they had something else in mind.

  • Functional: post a photo with a caption; follow and unfollow accounts; see a home feed of posts from followed accounts; like a post and see its like count; post a story that disappears after 24 hours and view stories from followed accounts.
  • Non-functional: the feed opens fast on a phone network, images load quickly at the right size for the screen, a posted photo is never lost, and a new post can take a few seconds to reach followers.
  • Out of scope unless asked: video reels, direct messages, search and explore, ads, comments threads beyond a count.

2. Estimate the scale

Round, invented numbers, stated as assumptions. They matter because they tell you which part of the system is the expensive one.

Back-of-envelope estimate for a large photo sharing app (assumed figures)
QuantityAssumptionResult
Daily active users500 millionthe base for everything below
New photo posts100 million a dayabout 1,160 posts a second on average
Bytes per post2 MB original plus about 1 MB of derived sizesabout 300 TB a day, roughly 110 PB a year
Feed opens10 per user per day5 billion feed requests a day, about 58,000 a second
Image fetchesabout 10 images per feed openabout 50 billion image requests a day, nearly all from the CDN
Likes1 billion a dayabout 11,600 like writes a second, heavily skewed to popular posts
Back-of-envelope estimate for a large photo sharing app (assumed figures). Scroll sideways on a small screen.

Image bytes dominate both storage and bandwidth, so the media path gets the first deep dive. Feed reads outnumber posts by roughly 50 to 1, which argues for precomputing feeds. And like traffic concentrates on a small number of posts, which means hot keys.

3. Define the API

POST /v1/media/upload-url
  returns: { "mediaId": "m_51c", "uploadUrl": "https://uploads.example/...signed...", "expiresIn": 600 }

POST /v1/posts
  body:    { "mediaIds": ["m_51c"], "caption": "First snow on the ridge" }
  returns: 201 { "postId": "p_88f", "status": "processing" }

GET  /v1/feed?cursor=...&limit=20        returns posts with image URLs per size
POST /v1/posts/{postId}/like             idempotent per user
POST /v1/users/{userId}/follow
POST /v1/stories                         body: { "mediaId": "m_77d" }
GET  /v1/stories/tray                    accounts with unseen stories, in order
Posting is two steps: get somewhere to put the bytes, then create the post that points at them.

4. Sketch the data model

Each data set is stored where its main query is cheap
DataShapePartition key and store
Postpost_id, author_id, caption, media_keys, created_atpost_id in a wide-column or sharded SQL store; a secondary index by author_id and time for profile pages
Media objectmedia_id, content hash, sizes available, dimensionsMetadata next to the post; bytes in object storage under the content hash
Follow edge(follower_id, followee_id, created_at)Stored twice: by follower (who do I follow) and by followee (who follows me)
Feedper user: newest few hundred post_idsIn-memory store keyed by user_id, rebuilt from the graph if lost
Like(post_id, user_id) plus a count per postEdges keyed by post_id; counts in a sharded counter store
Storystory_id, author_id, media_key, expires_atStore with native TTL, keyed by author_id
Each data set is stored where its main query is cheap. Scroll sideways on a small screen.

5. The core decision: the media path

  1. Signed uploadThe app asks for an upload URL, then sends the photo directly to object storage. Your API servers never carry image bytes, so they stay small and cheap.
  2. Processing eventObject storage emits an event when the upload lands. A worker validates the file, strips location metadata if the user did not opt in, and writes a small set of derived sizes: a thumbnail for grids, a feed size and a full-screen size, in a modern compressed format with a fallback.
  3. Content-addressed namesEach output is stored under a hash of its bytes. The same bytes always get the same name, and a changed image gets a new name, so nothing ever has to be purged from caches.
  4. Mark readyThe worker records the available sizes on the media row, and the post becomes visible. If processing fails, the post stays in processing and the app can retry the upload.
  5. Serve from the edgeClients request the size that fits the screen from the CDN with long cache lifetimes. The origin sees a request only when an edge has never had that object or has evicted it.

Producing sizes at upload time costs storage for every photo, including those nobody opens. The alternative is resizing on the fly at the edge on first request and caching the result. With only three or four sizes, precomputing is simpler and keeps first loads fast; on-the-fly resizing earns its place when clients ask for many arbitrary sizes.

6. The architecture

  1. Clients
    • Mobile app
    • CDN for images
  2. Edge
    • API gateway
    • Signed upload endpoint
  3. Services
    • Post service
    • Feed service
    • Graph service
    • Like service
    • Story service
  4. Async
    • Upload events -> image workers
    • Post events -> fan-out workers
  5. Storage
    • Object storage (originals and sizes)
    • Post store + cache
    • Feed lists (in memory)
    • Counter store
    • Story TTL store
Media, post, feed, like and story paths for a photo sharing app. Phones talk to an API gateway for metadata and upload directly to object storage with signed URLs. An upload event triggers image workers that write derived sizes back to storage and mark the media ready. The post service writes posts and publishes a post-created event to a queue; fan-out workers read the follower list from the graph service and push post IDs into per-user feeds in an in-memory store. The feed service reads those lists, merges in posts from very large accounts at read time and hydrates them from a post cache. Likes go to a like service backed by an edge store and sharded counters. Stories go to a story service with a TTL store. All image bytes are served to phones through a CDN.

The feed path deserves one paragraph here and a full page elsewhere. When a post is created, workers copy its ID into the feed list of each follower (fan-out on write). That is cheap for an account with a few hundred followers and ruinous for one with tens of millions, so posts from very large accounts are left out of the push and merged into the feed when the reader opens it. The ranking, cursors and the exact cut-off are covered in design a news feed, and the celebrity problem is also discussed in design Twitter.

7. Scale it

Likes on a hot post

A post from a very popular account can draw thousands of likes a second. Store the like edge (who liked what) so a user cannot like twice and so the app can show "liked by people you follow". For the number, avoid one row that every like updates. Two common answers: split the counter into N shards and add a random shard on each like, summing them on read (with the sum cached for a second or two); or send like events to a stream and let an aggregator apply batched increments. Either way the displayed count is slightly behind, which you agreed in the requirements.

Stories that expire

Stories are a separate, small, short-lived data set. Write each one with an expires_at 24 hours ahead into a store with native TTL so it disappears without a cleanup job, and keep a per-author list of active story IDs. The tray at the top of the app is built at read time: take the accounts the viewer follows, keep those with active stories, and order them by recency and how often the viewer watches them. Track "seen" per viewer and story in a cache with the same 24-hour lifetime. If an archive feature is in scope, copy stories to a private archive before they expire.

  • Partition the graph twice. Follower lists drive fan-out; following lists drive the stories tray and profile pages. Keeping both directions avoids scatter-gather queries.
  • Cache hydrated posts. Feed lists hold only IDs; a post cache turns IDs into caption, author and image URLs in one batched lookup. See caching for TTL and invalidation choices.
  • Shard the post store by `post_id` and keep the author index separate, as in sharding, so a prolific account does not overload one partition.
  • Keep image processing elastic. Upload volume has daily peaks; the worker pool scales on the queue length.

8. What breaks, and what you do about it

Failure modes worth naming
FailureEffectMitigation
Upload succeeds, post call failsOrphan images in storageA cleanup job deletes media not attached to a post within a day
Image worker backlogPosts stay in processingAutoscale on queue depth; show the uploader a local preview meanwhile
Feed store loses a nodeSome users see empty feedsReplicas; on a miss, rebuild the feed from the following list and recent posts (pull) and repopulate
Celebrity postsFan-out job with tens of millions of writesSkip the push for accounts above a follower threshold and merge their posts at read time
Hot like counterWrite contention on one keySharded counters or batched increments; cache the summed value briefly
CDN region issueSlow or broken imagesFail over to another CDN region or provider; the immutable URLs work from any of them
Failure modes worth naming. Scroll sideways on a small screen.

9. Trade-offs to discuss

  • Precomputed sizes or resize on demand. Precomputing is predictable and fast for a few fixed sizes; on-demand resizing saves storage for rarely seen photos and handles many device sizes.
  • Push, pull or hybrid feeds. Push makes reads cheap and writes expensive; pull is the reverse. Hybrid by follower count is the usual answer, with the threshold set from measurements.
  • Exact or approximate like counts. Showing the exact number in real time costs contention for little benefit. A count that settles within seconds is almost always fine; the like edge itself must be exact so double likes are impossible.
  • Delete stories or hide them. A TTL store deletes them; a flag hides them. Deletion is simpler and better for privacy, unless an archive is part of the product.
  • One store or several. Separate stores for posts, graph, feeds, counters and stories each fit their query, at the cost of more systems to run and no cross-store transactions; the post-created event ties them together.

10. How to talk through it in the interview

Fictional example

Handling the hot-post follow-up
Interviewer
A famous account posts and gets fifty thousand likes in the first minute. What does your like path do?
Candidate
Each like writes an edge keyed by post and user, so a second tap is a no-op. The count is the problem: one key taking hundreds of writes a second. I would spread it across, say, 64 counter shards and sum them on read, caching the sum for a second. The number on screen lags slightly, which we agreed was acceptable.
Interviewer
And the fan-out of that post?
Candidate
That account is above the follower threshold, so its posts are not pushed. Followers' feed requests pull its recent posts and merge them in.

A sensible 45-minute plan: 5 minutes on scope and the freshness question, 5 on numbers (the image bytes and the 50-to-1 read ratio), 5 on the two-step posting API and the stores, 10 on the architecture, about 15 on the media path plus one of likes or stories, and the final 5 on failures and trade-offs. Mention the feed's hybrid fan-out briefly unless the interviewer wants to go deeper there.

  • Keep image bytes out of your API servers and say so explicitly.
  • Explain why immutable, content-addressed URLs make the CDN simple.
  • Treat stories as their own data set with a TTL rather than a flag on posts.

Practicing this design with Natively

Run this as a timed mock with a friend who plays the interviewer and keeps asking "and what if that account has 50 million followers?". Natively follows the conversation, transcribing your voice and theirs, and can put forward talking points when a question comes up, so you can check afterwards whether you skipped stories or never explained the like counter. If you sketch the media path, take a screenshot of the drawing and ask it to explain or critique the flow. The transcript and notes are kept for review once the call ends.

Questions people ask

What are the key parts of an Instagram system design answer?

The media path (direct uploads to object storage, a job that makes a few sizes, a CDN), a follow graph stored in both directions, a home feed of post IDs per user, like counts that avoid one hot row, and stories with a 24-hour TTL. Spend the deep dive on media, then one of likes or stories.

How should photos be uploaded in a photo sharing system design?

Have the app request a short-lived signed URL and upload straight to object storage, so API servers never carry image bytes. An upload event then triggers workers that validate the file and write thumbnail, feed and full-screen versions under content-addressed names the CDN can cache for a long time.

How do you handle like counts on a viral post?

Store each like as an edge keyed by post and user so double likes are impossible, but keep the count separate. Spread the count over several counter shards and sum them on read, or batch increments from an event stream. The displayed number may lag by a second or two, which is usually acceptable.

How do Instagram-style stories expire after 24 hours in a design?

Write each story with an expiry time into a store that supports TTLs so it is removed automatically, and keep a per-author list of active story IDs. Build the stories tray at read time from the accounts the viewer follows, and keep seen-state with the same 24-hour lifetime.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP