01

Requirements & scope

Problem Statement & Requirements

Functional Requirements

  • Upload photos -- users upload images with caption, tags, location, and filters
  • News feed -- see a personalized feed of photos from followed users
  • Follow/unfollow -- follow other users to see their content
  • Like & comment -- interact with posts
  • Explore / discover -- browse trending and recommended content
  • Stories -- ephemeral 24-hour photo/video content (brief mention)
  • User profiles -- view user's posts grid, follower/following counts, bio
  • Search -- search by username, hashtag, or location
  • Notifications -- new followers, likes, comments, mentions

Non-Functional Requirements

  • High availability -- 99.99% uptime
  • Low latency -- feed loads in < 500 ms, image loads in < 200 ms
  • Consistency -- eventual consistency acceptable for feed; strong for follow/unfollow
  • Read-heavy -- read:write ratio ~100:1
  • Scalability -- 500M+ DAU, 100M+ photos uploaded/day
  • Durability -- uploaded photos never lost

Out of Scope

  • Reels / short-form video (covered in video streaming design)
  • Messaging / DMs (covered in chat system design)
  • Ads / monetization platform
  • Shopping / e-commerce integration
02

Scale estimations

Scale Estimations

Users & Content

MetricValue
Total users2B
Daily Active Users (DAU)500M
Photos uploaded / day100M
Average photo size (original)3 MB
Average photo size (after processing)500 KB (multiple sizes)
Average followers per user200
Average following per user200
Celebrity/influencer followers1M - 500M

Storage

MetricValue
Raw photo storage / day100M x 3 MB = 300 TB/day
Processed photos / day (4 sizes)100M x 4 x 200 KB = 80 TB/day
Total photo storage / year~140 PB/year
Metadata per photo~1 KB
Metadata storage / day100M x 1 KB = 100 GB/day

Traffic

MetricValue
Feed requests / day500M DAU x 10 opens/day = 5B
Feed requests / sec~58K RPS
Peak feed requests / sec~175K RPS
Photo views / day5B feeds x 10 photos/feed = 50B
Photo uploads / sec100M / 86400 = ~1,160/sec

Bandwidth

MetricValue
Feed image egress50B views x 200 KB = ~10 PB/day
Upload ingress300 TB/day
CDN offloads 95%+ of egressOrigin serves < 500 TB/day
03

Layered architecture

Phase 1 of 4 · Client & edge

Start with the entry points

First, define who uses the system and where requests enter. This is the boundary of the design, not yet a complete request path.

Mobile client
Separate upload progress from publishing a post that other people can view.
API gateway
Authenticate users and route media operations separately from feed reads.
Architecture after phase 1. Includes Mobile client, API gateway. Mobile client connects to API gateway.
Phase 1 — Start with Mobile client, API gateway.SVGSVGEditable diagramEditable diagram

This first layer defines the system boundary. The next chapters add application logic and data dependencies. After examining the request paths and tradeoffs, we will add operational safeguards and bring the complete architecture together.

04

API & contracts

Phase 2 of 4 · Application & compute

Add the application logic

Keep the entry points and add the services that do the work. Give each service a clear responsibility before defining its contracts. Storage and background dependencies come next.

Post service
Create the post record and coordinate the asynchronous image-processing lifecycle.
Image workers
Generate thumbnails and variants, and validate content before publishing it widely.
Fanout service
Push to ordinary followers and pull celebrity content at read time to limit write amplification.
Architecture after phase 2. Includes Mobile client, API gateway, Post service, Image workers, Fanout service. Mobile client connects to API gateway. API gateway connects to Post service. Post service connects to Image workers. API gateway connects to Fanout service.
Phase 2 — Added Post service, Image workers, Fanout service. Earlier layers remain in place.SVGSVGEditable diagramEditable diagram

An upload session should identify the owner, expected content constraints, and upload state. Publishing a post references completed media rather than accepting an arbitrary storage URL from a client. Keep the media-processing status explicit so the app can show a pending image without accidentally publishing an inaccessible or unvalidated object.

05

Data model

Phase 3 of 4 · Data & async work

Connect data and background work

The services now need their dependencies: durable state, fast lookups, or work that continues outside a request. Separate these responsibilities rather than treating every component as a database.

Blob store + CDN
Store image bytes in object storage and deliver immutable variants through the CDN.
Feed cache
Cache ordered post IDs rather than duplicating large media payloads into every feed.
Social graph
Find intended recipients and enforce visibility rules when generating or reading feeds.
Architecture after phase 3. Includes Mobile client, API gateway, Post service, Image workers, Blob store + CDN, Feed cache, Social graph, Fanout service. Mobile client connects to API gateway. API gateway connects to Post service. Post service connects to Image workers. Image workers connects to Blob store + CDN. API gateway connects to Fanout service. Fanout service connects to Feed cache. Fanout service connects to Social graph.
Phase 3 — Added Blob store + CDN, Feed cache, Social graph. Earlier layers remain in place.SVGSVGEditable diagramEditable diagram

Data Model

Posts Table (MySQL / Vitess)

Posts Table (MySQL / Vitess)
Posts Table (MySQL / Vitess)SVGSVGEditable diagramEditable diagram

Social Graph (Follows)

Social Graph (Follows)
Social Graph (Follows)SVGSVGEditable diagramEditable diagram

Likes & Comments

Likes & Comments
Likes & CommentsSVGSVGEditable diagramEditable diagram
06

Core design decisions

News Feed -- The Core Design Challenge

Fanout-on-Write vs Fanout-on-Read

This is THE critical design decision for Instagram/Twitter-like systems.

Fanout-on-Write vs Fanout-on-Read
Fanout-on-Write vs Fanout-on-ReadSVGSVGEditable diagramEditable diagram
Fanout-on-Write vs Fanout-on-Read
Fanout-on-Write vs Fanout-on-ReadSVGSVGEditable diagramEditable diagram

Hybrid Approach (Instagram's Actual Design)

Hybrid Approach (Instagram's Actual Design)
Hybrid Approach (Instagram's Actual Design)SVGSVGEditable diagramEditable diagram
07

Request flows

Photo Upload & Processing Flow

Photo Upload & Processing Flow
Photo Upload & Processing FlowWide diagram — scroll horizontally.SVGSVGEditable diagramEditable diagram

Image Processing Pipeline

Image Processing Pipeline
Image Processing PipelineSVGSVGEditable diagramEditable diagram

Feed Generation Flow (Detailed)

Feed Generation Flow (Detailed)
Feed Generation Flow (Detailed)Wide diagram — scroll horizontally.SVGSVGEditable diagramEditable diagram

Feed Pagination (Cursor-Based)

Feed Pagination (Cursor-Based)
Feed Pagination (Cursor-Based)SVGSVGEditable diagramEditable diagram
08

Performance & caching

Feed Cache Design (Redis)

Feed Cache Design (Redis)
Feed Cache Design (Redis)SVGSVGEditable diagramEditable diagram

Feed Ranking (Beyond Reverse Chronological)

Feed Ranking (Beyond Reverse Chronological)
Feed Ranking (Beyond Reverse Chronological)SVGSVGEditable diagramEditable diagram
09

Advanced design

Blob Storage & CDN

Blob Storage & CDN
Blob Storage & CDNSVGSVGEditable diagramEditable diagram

Fanout Service Detail

Fanout Service Detail
Fanout Service DetailSVGSVGEditable diagramEditable diagram

Explore / Discover Page

Explore / Discover Page
Explore / Discover PageSVGSVGEditable diagramEditable diagram

Stories (24-Hour Ephemeral Content)

Stories (24-Hour Ephemeral Content)
Stories (24-Hour Ephemeral Content)SVGSVGEditable diagramEditable diagram

Search

Search
SearchSVGSVGEditable diagramEditable diagram
10

Edge cases

The image upload can finish while post creation fails. Keep enough upload-session state to retry linking the media, and clean up abandoned objects after a safe retention window. Privacy changes need to reach derived image URLs and feed caches, not just the row storing the caption.

11

Tradeoffs

Tradeoffs & Design Decisions Summary

DecisionOption AOption BChosenWhy
Feed strategyFanout-on-writeFanout-on-readHybridPush for normal users (fast reads), pull for celebrities (avoid 100M writes)
Feed cacheDatabaseRedis sorted setsRedisO(1) reads, sorted by score, TTL for inactive users
Feed orderChronologicalML-rankedML-rankedIncreases engagement 40%+; chronological misses relevant posts
Image storageOwn HDFSS3S3Managed, infinite scale, cheap, 11 nines durability
Image uploadThrough API serverDirect to S3 (presigned)Direct S3API servers don't handle multi-MB uploads; offload to S3
Image sizesOne size5 sizes (thumb to original)5 sizesServe appropriate size per context; saves bandwidth
Social graphGraph DB (Neo4j)MySQL + cache (TAO)MySQL + TAOSimpler operations, TAO cache gives graph-like perf, battle-tested at Facebook scale
PaginationOffset-basedCursor-basedCursorStable under insertions/deletions; no deep-scan cost
Like countsSync DB updateAsync (Kafka -> Redis -> DB)AsyncCan't do 100K writes/sec to single row; batch aggregation
Post metadata DBNoSQLMySQL (Vitess)MySQL/VitessNeed joins (user+post), Vitess scales MySQL horizontally
CDNSingle-tierMulti-tier (edge + regional + origin shield)Multi-tier95%+ cache hit at edge; origin shield collapses duplicate origin fetches
Stories storageSame as postsSeparate with TTLSeparate + TTLAuto-expire after 24h; different access patterns from permanent posts
12

Reliability & fault tolerance

Phase 4 of 4 · Operations & resilience

Add operational safeguards

With the request paths and tradeoffs established, add the controls that help detect trouble and keep the system operating. The final diagram retains every layer introduced so far.

Telemetry
Watch processing backlog, feed staleness, and image delivery failures separately.
Architecture after phase 4. Includes Mobile client, API gateway, Post service, Image workers, Blob store + CDN, Feed cache, Social graph, Fanout service, Telemetry. Mobile client connects to API gateway. API gateway connects to Post service. Post service connects to Image workers. Image workers connects to Blob store + CDN. API gateway connects to Fanout service. Fanout service connects to Feed cache. Fanout service connects to Social graph. Image workers connects to Telemetry.
Phase 4 — Added Telemetry. Earlier layers remain in place.SVGSVGEditable diagramEditable diagram

Store accepted originals durably and make derivative generation retryable. A failed thumbnail worker should leave a recoverable job, not a permanently broken post. Track processing failures separately from upload failures, and ensure deleting a post eventually removes its derivatives without racing an in-progress resize job.

13

Production architecture

High-Level Architecture

High-Level Architecture
High-Level ArchitectureSVGSVGEditable diagramEditable diagram

Detailed Architecture

Detailed Architecture
Detailed ArchitectureWide diagram — scroll horizontally.SVGSVGEditable diagramEditable diagram

Production Architecture

Production Architecture
Production ArchitectureWide diagram — scroll horizontally.SVGSVGEditable diagramEditable diagram
14

Further exploration

Change one assumption: a photo can move from public to private after it has gone viral. Trace every copy and pointer—object storage, signed URLs, CDN entries, feeds, and notifications. Decide which guarantees are achievable immediately and which require a clearly bounded expiry window.

15

Interview playbook

Interview Tips

  1. Start with the feed -- "The core challenge of Instagram is generating a personalized feed for 500M daily users. Let me design the feed system first." This shows you know what matters.

  2. Fanout-on-write vs fanout-on-read is THE question -- Draw both approaches. Explain the celebrity problem. Show the hybrid solution. This is what interviewers want to hear.

  3. Feed cache numbers -- "500M users x 500 posts x 30 bytes = 7.5 TB in Redis. With eviction of inactive users, ~2 TB. That's ~30-40 Redis nodes." Shows you can do the math.

  4. Image processing is important but brief -- "Upload directly to S3 via presigned URL. Process async: resize to 5 versions. Store all in S3. Serve via CDN." That's 3 sentences and covers it.

  5. Don't forget the social graph -- "The follows table has 100B rows. We shard by follower_id for 'who do I follow' queries and maintain a reverse index for 'who follows me' for fanout."

  6. CDN is critical -- "50B image views/day at 200 KB each = 10 PB/day. That's CDN territory. 95%+ cache hit rate because images are immutable."

  7. Cursor pagination, not offset -- If feed pagination comes up, explain why cursor-based pagination is stable under concurrent writes. This is a detail that shows real system experience.

  8. Ranked feed shows ML awareness -- "Instagram's feed isn't chronological. We rank by interest, recency, relationship, and engagement velocity. Two-stage pipeline: 500 candidates from cache, then ML ranking."

  9. Scale numbers anchor the design -- "100M uploads/day = 1,160/sec. 5B feed reads/day = 58K RPS. Read:write is 50:1. This is a read-heavy system, which is why we pre-compute feeds."

  10. Stories are a nice add-on -- "Stories are ephemeral posts with a 24-hour TTL. Redis with auto-expire. Separate from the main feed. Show as horizontal tray sorted by recency." Quick, clean, shows breadth.