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
| Metric | Calculation | Result |
|---|---|---|
| Upload QPS | 100M / 86,400 | ~1.2K/sec avg; ~5K peak |
| Feed reads/day | 500M × 3 | 1.5B/day → ~17K/sec |
| Storage/day | 100M × 200 KB | 20 TB/day new blobs |
| CDN egress | 17K feed × 20 thumbs × 50 KB | ~17 GB/sec peak (CDN absorbs) |
API Design
| Endpoint | Description |
|---|---|
| POST /v1/media/upload | Init 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}/like | Idempotent like |
Data Model
| Entity | Storage |
|---|---|
| posts | post_id, user_id, media_id, caption, ts — SQL/Cassandra |
| media | media_id, user_id, s3_keys{thumb,medium,full}, status — SQL |
| follows | follower_id, followee_id — graph store |
| feed_timeline | user_id → post_ids — Redis (same pattern as news feed) |
High-level Design
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
- Client uploads to S3 via pre-signed URL (direct, no API bandwidth)
- S3 event triggers Lambda/worker: generate 150px thumb, 640px medium, 1080p full
- Store WebP + JPEG fallback; mark media status = ready
- 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
| SLO | Target |
|---|---|
| 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.
Related practice topics