Design Instagram: photo feed and stories

Learn how to design Instagram's photo feed and stories, tackling massive read-heavy workloads, hybrid feed generation, and ephemeral storage.

intermediate9 min readBy CureBugs EditorialUpdated 5 Nov 2026

Designing a platform like Instagram is a classic system design interview question. It tests your ability to handle massive scale, read-heavy workloads, and complex data pipelines. At its core, Instagram is a photo-sharing app, but features like the personalized feed and ephemeral stories introduce unique engineering challenges. In this guide, we will break down how to design the photo feed and stories features for millions of users, focusing on the trade-offs you will need to discuss with your interviewer.

Requirements (functional and non-functional)

Before jumping into architecture, we must define the scope. In an interview, always clarify what features to focus on.

Functional Requirements

  • Upload Media: Users can upload photos.
  • View Feed: Users can view a personalized timeline of photos from people they follow, sorted chronologically (or by an algorithm).
  • Post Stories: Users can post ephemeral photos/videos that disappear after 24 hours.
  • View Stories: Users can view active stories from people they follow.

Non-Functional Requirements

  • High Availability: The feed and stories must always load. Downtime is unacceptable.
  • Low Latency: The feed should load in under 200ms.
  • Eventual Consistency: It is acceptable if a user sees a new post a few seconds after it is uploaded.
  • Read-Heavy System: The read-to-write ratio is extremely high (e.g., 100:1).

Capacity estimates

Let us assume the platform has 500 million Daily Active Users (DAU).

Traffic Estimates:

  • Reads: If an average user views 100 photos/stories a day, that is 500M * 100 = 50 Billion read requests per day.
  • Writes (Photos): If an average user uploads 1 photo every 5 days, that is 100 Million photo uploads per day.
  • Writes (Stories): Stories are more frequent. Let's assume 200 Million stories are uploaded daily.

Storage Estimates:

  • Photos: Assuming an average photo size of 2MB. 100M photos * 2MB = 200 TB/day. Over 10 years, this is roughly 730 PB of storage.
  • Stories: Assuming an average story size of 3MB. 200M stories * 3MB = 600 TB/day. Since stories expire in 24 hours, active storage is small, but we may archive them for 30 days for legal compliance, requiring about 18 PB.

Bandwidth Estimates:

  • Outbound: 50 Billion reads * 2MB = 100 PB/day of outbound traffic. This massive bandwidth requirement immediately justifies the use of a Content Delivery Network (CDN).

API design

We will design RESTful APIs for our core features. Using cursor-based pagination is critical for feeds to prevent duplicate items when new posts are added.

  • POST /v1/media
    • Body: image_file, caption, location
    • Response: 201 Created with media_id
  • GET /v1/feed
    • Query Params: cursor (timestamp or ID), limit (default 20)
    • Response: 200 OK with a list of media objects and a next_cursor.
  • POST /v1/stories
    • Body: media_file, text_overlay
    • Response: 201 Created with story_id
  • GET /v1/stories
    • Response: 200 OK with a grouped list of active stories from followed users.

Data model

We need a polyglot persistence strategy because different features have different access patterns.

1. Relational Database (PostgreSQL / MySQL)

Used for structured, relational data that requires ACID properties.

  • Users Table: user_id (PK), username, email, created_at
  • Follows Table: follower_id (PK), followee_id (PK), created_at. (Needs indexes on both columns to quickly find "who follows X" and "who does X follow").

2. NoSQL Database (Cassandra / DynamoDB)

Used for the feed, which requires fast sequential reads and massive write scalability.

  • User Feed Table: user_id (Partition Key), timestamp (Clustering Key DESC), media_id. This allows us to quickly fetch the most recent posts for a specific user.

3. Key-Value Store (Redis)

Used for caching the feed and handling ephemeral story metadata.

  • Stories Cache: Key: story:{user_id}, Value: List of story_ids. We can set a native TTL (Time-To-Live) of 24 hours on these keys.

4. Object Storage (Amazon S3)

Used for storing the actual image and video files.

High-level architecture

Here is how the components interact when a user opens the app or uploads a photo.

Deep dives

1. Feed Generation (Push vs. Pull)

Generating a personalized feed is the hardest part of this system. When a user opens the app, we need to fetch the latest posts from everyone they follow, sort them, and return them in under 200ms.

There are three main approaches:

ApproachHow it worksProsCons
Pull (Fan-out on Read)When a user opens the app, query the DB for all followees' recent posts, merge, and sort.No write amplification. Simple to implement.Extremely slow reads. Fails if a user follows thousands of people.
Push (Fan-out on Write)When a user posts, push the media_id to the pre-computed feed cache of all their followers.O(1) read time. Feeds load instantly.The "Celebrity Problem". If a user with 100M followers posts, it triggers 100M cache writes.
Hybrid ApproachPush for normal users, Pull for celebrities.Balances fast reads with manageable writes.Complex to implement and maintain.

The Hybrid Solution: In a production system like Instagram, a Hybrid approach is used. We classify users with millions of followers as "celebrities".

  1. When a normal user posts, we use Push to update their followers' feeds in Redis.
  2. When a celebrity posts, we do not push to millions of caches.
  3. When a user opens their feed, the system fetches their pre-computed feed (from Redis) and merges it at runtime with the recent posts of any celebrities they follow (Pull).

Here is how you might implement the cursor-based feed retrieval logic:

def get_feed(user_id, cursor, limit=20):
    # Fetch from Redis cache (pre-computed feed)
    # zrevrangebyscore fetches items sorted by timestamp descending
    feed = redis.zrevrangebyscore(f"feed:{user_id}", max=cursor, min=0, start=0, num=limit)
    
    if not feed:
        # Fallback to Cassandra if cache miss
        feed = cassandra.execute(
            "SELECT media_id FROM user_feed WHERE user_id = ? AND timestamp < ? LIMIT ?",
            (user_id, cursor, limit)
        )
        
    return fetch_media_metadata(feed)

2. Handling Stories (Ephemeral Storage)

Stories introduce a unique challenge: data must reliably disappear after 24 hours. Deleting millions of rows continuously from a relational database causes heavy fragmentation and performance degradation.

Solution: We use a Key-Value store with native TTL (Time-To-Live) support.

  • Redis is excellent for storing the metadata of active stories. When a user uploads a story, we append the story_id to a Redis list story:{user_id} and set the TTL to 24 hours. Redis automatically evicts the key when time expires.
  • For the actual media files in S3, we can configure an S3 Lifecycle Rule to automatically transition files older than 24 hours to cheaper cold storage (like Glacier) or delete them entirely.
  • For CDN caching, we set the Cache-Control header's max-age so that the edge cache expires exactly when the 24-hour window ends.

3. Media Upload and Processing Pipeline

Uploading a 2MB image directly through our API Gateway ties up server connections and wastes compute resources.

Instead, we use Presigned URLs:

  1. The client requests an upload URL from the Media Service.
  2. The service generates an S3 Presigned URL and returns it.
  3. The client uploads the binary file directly to S3, bypassing our backend servers entirely.
  4. Once uploaded, S3 triggers an event to a Kafka queue.
  5. Asynchronous worker nodes consume the Kafka event to process the image (resize to multiple resolutions, compress, and apply watermarks) before updating the database.

Bottlenecks and trade-offs

  • Storage Costs vs. Performance: Storing 730 PB of data is incredibly expensive. We must trade off retrieval latency for older posts by implementing Tiered Storage. Recent photos (last 30 days) stay in Standard S3, while older photos are moved to S3 Infrequent Access or Glacier.
  • Cache Size vs. Hit Rate: We cannot pre-compute feeds for all 500M users. We trade off cache size by only pre-computing feeds for active users (e.g., users who have logged in within the last 7 days). If an inactive user logs in, their feed is generated on the fly via the Pull model.
  • Database Hotspots: The Follows table in PostgreSQL will become a bottleneck. We must shard this database. Sharding by follower_id optimizes the "fetch all people I follow" query, which is critical for feed generation.

Questions an interviewer will ask next

1. How would you handle video uploads? Videos are much larger than photos. I would implement chunked uploads (multipart upload) to S3 to handle network interruptions. The processing pipeline would need a transcoding service (like FFmpeg) to convert the video into adaptive bitrate streaming formats like HLS or DASH.

2. What happens if a user edits a post's caption? We update the caption in the primary database (PostgreSQL/MongoDB) and invalidate the specific media object in the cache. Since the feed cache only stores media_ids, we don't need to rebuild the entire feed; the client will fetch the updated metadata using the media_id.

3. How do you move from a chronological feed to an algorithmic feed? Instead of just sorting by timestamp, we would introduce a Ranking Service. The Feed Service would fetch the top 500 recent posts (using the Hybrid push/pull model), pass them to the Machine Learning Ranking Service, which scores them based on user affinity, engagement probability, and recency, before returning the top 20 to the user.

Mock interview

Now design it with an interviewer in the room

Reading a design is the easy part. In the round you have to drive it yourself: ask the right questions, sketch it, and defend each choice when the interviewer pushes back.

  • Starts from this exact problem, on a shared whiteboard
  • Follow-ups on scale, failure and trade-offs
  • A scored report that quotes your answers and says what to fix
Run this as a mock design round Voice or text. Pause whenever you need to.

Applying somewhere? Start with the company filled in

Go deeper elsewhere

The best material we've found on these topics.

Practise this

Reading builds understanding. Practice makes it stick.

Keep reading

All articles
Case studies•intermediate

Design YouTube: video upload and streaming

11 min read
Case studies•intermediate

Design Twitter's home timeline

11 min read
Case studies•intermediate

Design a URL shortener

11 min read
Case studies•intermediate

Design search autocomplete (typeahead)

10 min read