# How to design Instagram

Source: https://systemdesignsim.com/system-design/instagram

System design · Media uploads, feeds, hot accounts

Upload photos straight to object storage, resize them asynchronously, serve them through a CDN, and precompute each user's feed. At 500 million daily users that is about 580 uploads a second, 115,000 feed reads a second and 1.2 million image requests a second, almost all from the CDN.

Updated October 25, 2026 · 5 min read

A teaching design of a system like Instagram, not Instagram's real architecture.

[Take the news feed challenge](https://systemdesignsim.com/challenges/news-feed)

![Instagram architecture diagram](https://systemdesignsim.com/diagrams/instagram-system-design-diagram.svg)

Originals go straight to S3 on a pre-signed URL. Resize workers write fixed sizes and hand ready posts to fan-out, which fills Redis feed lists. Images come from CloudFront.

## The short version

* Image bytes dwarf everything else. Clients upload them straight to S3 on a pre-signed URL; a CDN serves them.
* Resize asynchronously. The post stays pending, and is fanned out only once its variants are ready.
* Feed reads outnumber uploads about 200 to 1, so precompute feeds, but merge celebrity posts at read time.
* Likes are a write stream: record each like idempotently, count in Redis, flush in batches.

## Clarifying questions to ask first

* Which features? (Assume photo posts, follows, the home feed, likes and comments. Leave out stories, reels, direct messages and search.)
* How many users, and how often do they post? (Assume 500M daily users, with 1 in 10 posting a photo a day.)
* How fresh must the feed be, and what must never happen? (A new post can take a few seconds to reach feeds and likes can lag. An uploaded photo must never be lost.)
* Do some accounts have millions of followers? (Assume yes; that changes how the feed is built.)

## Numbers that shape the design

Assumptions, stated out loud. The order of magnitude decides the architecture.

| Quantity       | Assumption                                     | Result                                            |
| -------------- | ---------------------------------------------- | ------------------------------------------------- |
| Uploads        | 500M daily users, 1 in 10 posts a photo a day  | 50M a day ≈ 580/s average, ≈ 1,700/s at a 3× peak |
| Photo storage  | ≈ 2 MB original + ≈ 500 KB of resized variants | ≈ 125 TB a day ≈ 45 PB a year, before replicas    |
| Feed reads     | 20 feed loads per user per day                 | 10B a day ≈ 115,000/s average                     |
| Image requests | about 10 images per feed load                  | ≈ 1.2M images/s, almost all from the CDN          |
| Likes          | 10 likes per user per day                      | 5B a day ≈ 58,000/s average                       |

## API

```
POST /api/uploads            { "content_type": "image/jpeg", "size": 2048000 }
→ 200 { "upload_id": "up_81", "url": "https://media-bucket.s3.amazonaws.com/...signed" }

PUT  {signed url}             <photo bytes>   (client → S3 directly)

POST /api/posts               { "upload_id": "up_81", "caption": "..." }   → 201 { "id": "1850..." }
POST /api/follows             { "followee_id": 42 }                      → 204
POST /api/posts/{id}/likes                                               → 204
GET  /api/feed?cursor=…        → 200 { "posts": [...], "next_cursor": "…" }
```

The pre-signed URL is short-lived and scoped to one object key. A slow mobile connection ties up S3, not your servers.

## Data model

Metadata is small and structured; image bytes are large and immutable, so they live apart. Metadata fits DynamoDB, or PostgreSQL sharded by user.

```
posts
  post_id        bigint     time-ordered, e.g. Snowflake
  author_id      bigint     partition key for the profile grid
  media_key      text       S3 object key prefix
  caption        text
  status         text       pending | ready
  created_at     timestamp

follows
  follower_id    bigint     who I follow
  followee_id    bigint     plus a reverse index: who follows me

post_counters
  post_id        bigint
  like_count     bigint
  comment_count  bigint

likes
  post_id        bigint     partition key
  user_id        bigint     sort key, so a second like is a no-op
```

Store the S3 key, not a full URL. The CDN domain and variant are added when the response is built, so either can change with no rows rewritten.

## Why uploads can't go through the API

Each upload holds a connection for seconds on a slow phone, and resizing is CPU-heavy. A few hundred concurrent uploads exhaust the fleet, and feed reads time out with them. So take the bytes off the request path: pre-signed URLs for upload, a queue for resizing, a CDN for delivery. The new risk is a post whose images don't exist yet, which the pending status covers.

## High-level design

* The API issues a pre-signed S3 URL and creates the post as pending. The client uploads the original directly.
* An S3 event triggers resize workers (Lambda for bursty load, or EC2 workers on SQS for steady volume). They write fixed sizes, strip metadata such as GPS location, and mark the post ready.
* CloudFront fronts the bucket. Variants are immutable, so the edge caches them for a long time.
* A ready post goes to fan-out, which pushes its ID into followers' feed lists in ElastiCache (Redis). A feed read hydrates IDs from a post cache and adds CloudFront URLs.

## Home feed and the celebrity problem

This is the [Twitter timeline](https://systemdesignsim.com/system-design/twitter-timeline) problem. Fan out on write for normal accounts, so a feed read is one cached list. For accounts with millions of followers, skip the fan-out and merge their recent posts in at read time. Otherwise one celebrity post becomes millions of Redis writes and delays everyone else's.

## Likes, counters and caches

Never run UPDATE like_count = like_count + 1 per tap; a popular post becomes one hot row. Write the like to the likes table (idempotent on post_id and user_id), increment a Redis counter only if the row is new, and flush to post_counters every few seconds. Shard the counter for very hot posts. Nobody notices 10,402 versus 10,407.

Redis also holds feed ID lists and hot post metadata. Size the post cache for the working set, since recent posts get almost all views, and let old posts fall out by LRU.

## Common traps

* Storing original photo bytes in the post database. Metadata queries then compete with large binary reads; keep media in object storage and its key in the row.
* Publishing an image before stripping its location metadata. Do it in the processing workflow, before any variant is public.
* Overwriting an image at a long-cached URL. Edge copies keep the old bytes; publish a new immutable key instead.
* Sizing the metadata cache from the full photo archive. The recent-post working set and image bytes are separate budgets.

## Follow-up questions interviewers ask

* "What do followers see before the resized images exist?" Nothing. The post stays pending until the workers mark it ready.
* "How do you move to a new CDN domain?" Rows store the S3 key, so URLs are built per response and no rows change.

## Frequently asked questions

### Why use pre-signed URLs for photo uploads?+

The client uploads straight to S3 with a short-lived, single-object permission. Your servers never handle the bytes, so slow uploads and large files don't eat application capacity.

### How does the Instagram feed handle celebrities?+

Most posts are fanned out on write into followers' cached feeds. Posts from accounts with millions of followers are merged in when a follower loads the feed, which keeps both writes and reads bounded.

### How do you count likes at scale?+

Record each like idempotently, increment an in-memory counter, and write totals in batches, sharding the counter for very hot posts. The count is eventually consistent, which is fine for a number users glance at.

## More system design guides

[All 76 guides](https://systemdesignsim.com/system-design)

* [Design a Twitter TimelineFan-out and the celebrity problem](https://systemdesignsim.com/system-design/twitter-timeline)
* [Design a Chat SystemQueues, write scaling, delivery lag](https://systemdesignsim.com/system-design/chat-system)
* [Design a Short Video App like TikTokVideo upload, transcoding, feed retrieval and CDN playback](https://systemdesignsim.com/system-design/tiktok)
* [Design a YouTubeTranscoding pipeline, object storage, CDN](https://systemdesignsim.com/system-design/youtube)
* [Design a WhatsApp-style Messaging](https://systemdesignsim.com/system-design/whatsapp)
* [Database Sharding explainedShard keys, hot partitions, resharding](https://systemdesignsim.com/system-design/database-sharding)

## Now fix it yourself.

Run the design under real traffic and see what breaks first. No signup.

[Take the news feed challenge](https://systemdesignsim.com/challenges/news-feed)
