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

Metric Value
Total users 2B
Daily Active Users (DAU) 500M
Photos uploaded / day 100M
Average photo size (original) 3 MB
Average photo size (after processing) 500 KB (multiple sizes)
Average followers per user 200
Average following per user 200
Celebrity/influencer followers 1M - 500M

Storage

Metric Value
Raw photo storage / day 100M 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 / day 100M x 1 KB = 100 GB/day

Traffic

Metric Value
Feed requests / day 500M DAU x 10 opens/day = 5B
Feed requests / sec ~58K RPS
Peak feed requests / sec ~175K RPS
Photo views / day 5B feeds x 10 photos/feed = 50B
Photo uploads / sec 100M / 86400 = ~1,160/sec

Bandwidth

Metric Value
Feed image egress 50B views x 200 KB = ~10 PB/day
Upload ingress 300 TB/day
CDN offloads 95%+ of egress Origin serves < 500 TB/day
03

Layered architecture

High-Level Architecture

High-Level ArchitectureExcalidraw diagram · editable shapes · reveal step by stepExplore

Detailed Architecture

Detailed ArchitectureExcalidraw diagram · editable shapes · reveal step by stepExplore
04

API & contracts

Workshop note · added for the website’s common reading format

For Photo Sharing, define contracts around the boundary components: Mobile client, API gateway, Post service. Specify authentication, request identity, versioning, pagination or streaming semantics, timeouts, and retry behavior. Name which operations are idempotent and how callers discover an uncertain outcome.

The source discusses these contracts within its subsystem walkthroughs rather than as a standalone endpoint catalog. The examples in this article are design exercises, not published service APIs.

05

Data model

Data Model

Posts Table (MySQL / Vitess)

Posts Table (MySQL / Vitess)Excalidraw diagram · editable shapes · reveal step by stepExplore

Social Graph (Follows)

Social Graph (Follows)Excalidraw diagram · editable shapes · reveal step by stepExplore

Likes & Comments

Likes & CommentsExcalidraw diagram · editable shapes · reveal step by stepExplore
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-ReadExcalidraw diagram · editable shapes · reveal step by stepExplore
Fanout-on-Write vs Fanout-on-ReadExcalidraw diagram · editable shapes · reveal step by stepExplore

Hybrid Approach (Instagram's Actual Design)

Hybrid Approach (Instagram's Actual Design)Excalidraw diagram · editable shapes · reveal step by stepExplore
07

Request flows

Photo Upload & Processing Flow

Photo Upload & Processing FlowExcalidraw diagram · editable shapes · reveal step by stepExplore

Image Processing Pipeline

Image Processing PipelineExcalidraw diagram · editable shapes · reveal step by stepExplore

Feed Generation Flow (Detailed)

Feed Generation Flow (Detailed)Excalidraw diagram · editable shapes · reveal step by stepExplore

Feed Pagination (Cursor-Based)

Feed Pagination (Cursor-Based)Excalidraw diagram · editable shapes · reveal step by stepExplore
08

Performance & caching

Feed Cache Design (Redis)

Feed Cache Design (Redis)Excalidraw diagram · editable shapes · reveal step by stepExplore

Feed Ranking (Beyond Reverse Chronological)

Feed Ranking (Beyond Reverse Chronological)Excalidraw diagram · editable shapes · reveal step by stepExplore
09

Advanced design

Blob Storage & CDN

Blob Storage & CDNExcalidraw diagram · editable shapes · reveal step by stepExplore

Fanout Service Detail

Fanout Service DetailExcalidraw diagram · editable shapes · reveal step by stepExplore

Explore / Discover Page

Explore / Discover PageExcalidraw diagram · editable shapes · reveal step by stepExplore

Stories (24-Hour Ephemeral Content)

Stories (24-Hour Ephemeral Content)Excalidraw diagram · editable shapes · reveal step by stepExplore

Search

SearchExcalidraw diagram · editable shapes · reveal step by stepExplore
10

Edge cases

Workshop note · added for the website’s common reading format

Walk through three failure moments in Photo Sharing: a request times out before its result is known; a dependency becomes slow rather than unavailable; and a process restarts after committing state but before acknowledging it.

For each case, name the authoritative record, define a safe retry, cap resource usage, and describe what the caller sees. Telemetry should help detect and contain the problem: Watch processing backlog, feed staleness, and image delivery failures separately.

11

Tradeoffs

Tradeoffs & Design Decisions Summary

Decision Option A Option B Chosen Why
Feed strategy Fanout-on-write Fanout-on-read Hybrid Push for normal users (fast reads), pull for celebrities (avoid 100M writes)
Feed cache Database Redis sorted sets Redis O(1) reads, sorted by score, TTL for inactive users
Feed order Chronological ML-ranked ML-ranked Increases engagement 40%+; chronological misses relevant posts
Image storage Own HDFS S3 S3 Managed, infinite scale, cheap, 11 nines durability
Image upload Through API server Direct to S3 (presigned) Direct S3 API servers don't handle multi-MB uploads; offload to S3
Image sizes One size 5 sizes (thumb to original) 5 sizes Serve appropriate size per context; saves bandwidth
Social graph Graph DB (Neo4j) MySQL + cache (TAO) MySQL + TAO Simpler operations, TAO cache gives graph-like perf, battle-tested at Facebook scale
Pagination Offset-based Cursor-based Cursor Stable under insertions/deletions; no deep-scan cost
Like counts Sync DB update Async (Kafka -> Redis -> DB) Async Can't do 100K writes/sec to single row; batch aggregation
Post metadata DB NoSQL MySQL (Vitess) MySQL/Vitess Need joins (user+post), Vitess scales MySQL horizontally
CDN Single-tier Multi-tier (edge + regional + origin shield) Multi-tier 95%+ cache hit at edge; origin shield collapses duplicate origin fetches
Stories storage Same as posts Separate with TTL Separate + TTL Auto-expire after 24h; different access patterns from permanent posts
12

Reliability & fault tolerance

Workshop note · added for the website’s common reading format

Watch processing backlog, feed staleness, and image delivery failures separately.

Set service-level objectives for the user-visible path, then map its dependencies. Define bounded retries with jitter, deadlines, and backpressure. Keep a degraded mode that protects authoritative state, and test recovery instead of treating replication as a backup.

For Photo Sharing, pay special attention to Blob store + CDN, Feed cache, Social graph when deciding failure domains and recovery procedures.

13

Production architecture

Production Architecture

Production ArchitectureExcalidraw diagram · editable shapes · reveal step by stepExplore
14

Further exploration

Workshop note · added for the website’s common reading format

Rebuild Photo Sharing from memory, then change one assumption: ten times more traffic, a new region, or a stricter consistency requirement. Which component must change first—and which does not?

Compare Post service with the same boundary in a related design. Write down one alternative you rejected, what it would simplify, and when you would choose it instead. Follow the source link at the end of this article to explore the original document.

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.