Skip to main content
HS
HiSETSuccess
LeetCode Prep

System Design

Interview framework, chapters, case studies, depth guides, and adaptive quizzes.

Case study

Design Instagram Photo Feed

Upload, store, and deliver photos in a social feed to 500M users with global CDN delivery.

CDNfeedobject storage

Requirements

  • Functional: upload photo + caption; follow users; home feed and explore
  • Like, comment; view full-resolution and thumbnail variants
  • Non-functional: feed load p99 < 1s; upload < 5s for 5 MB image
  • Scale: 500M DAU; 100M photos/day; avg 200 KB stored per photo (multi-res)

Back-of-envelope Estimation

MetricCalculationResult
Upload QPS100M / 86,400~1.2K/sec avg; ~5K peak
Feed reads/day500M × 31.5B/day → ~17K/sec
Storage/day100M × 200 KB20 TB/day new blobs
CDN egress17K feed × 20 thumbs × 50 KB~17 GB/sec peak (CDN absorbs)

API Design

EndpointDescription
POST /v1/media/uploadInit multipart upload → pre-signed URLs per part
POST /v1/posts{ mediaId, caption } → postId
GET /v1/feed?cursor=Posts with CDN URLs for thumb + full
POST /v1/posts/{id}/likeIdempotent like

Data Model

EntityStorage
postspost_id, user_id, media_id, caption, ts — SQL/Cassandra
mediamedia_id, user_id, s3_keys{thumb,medium,full}, status — SQL
followsfollower_id, followee_id — graph store
feed_timelineuser_id → post_ids — Redis (same pattern as news feed)

High-level Design

Upload & serve
Upload: Client ──► pre-signed S3 ──► S3 raw
              └──► Post Service ──► async resize workers ──► S3 variants ──► CDN purge

Feed: Client ──► Feed Service ──► timeline IDs ──► CDN URLs (no blob through API)

Deep Dive: Image Processing Pipeline

  1. Client uploads to S3 via pre-signed URL (direct, no API bandwidth)
  2. S3 event triggers Lambda/worker: generate 150px thumb, 640px medium, 1080p full
  3. Store WebP + JPEG fallback; mark media status = ready
  4. Fan-out post to followers (reuse news feed hybrid model)

Bottlenecks at Scale

  • 20 TB/day storage cost — lifecycle to cold tier after 90 days for old media
  • Resize worker backlog during peak — autoscale on queue depth
  • Celebrity feed fan-out — hybrid merge on read
  • CDN cache miss on new viral post — origin shield layer

Failure Modes & Monitoring

SLOTarget
Feed p99< 1 sec
Upload success> 99.5%
Media processing lag< 60 sec p99

Alert on resize queue depth, CDN 5xx, incomplete uploads orphaned > 24h. Track storage cost per DAU.