System design case study C07 · Media · CDN

Design a Photo-Sharing App (Instagram-style)

Upload photos, process them into many sizes, serve billions of image views a day through a CDN, and keep likes and comments snappy.

What you'll be able to explain
  • Build an upload pipeline that never blocks on processing
  • Store and serve image variants through a CDN
  • Model likes and comments at very high write rates
  • Count things at scale without hot rows
  • Design stories with expiry

Scope

Functional

  • Upload a photo with caption; view a post; like and comment.
  • Profile grid; home feed (reuse Case Study C6 of the book's feed design).
  • Stories that disappear after 24 hours.

Non-functional

  • Upload acknowledged in < 2 s; photo visible to followers within ~10 s.
  • Image load p99 < 300 ms worldwide; uploads never lost.
  • 500M DAU.

Size

  • 50M photo posts/day → ~600 uploads/s (peak ~2k).
  • Original 3 MB + variants (1080, 640, 320, thumbnail; WebP/AVIF) ~1 MB → 200 TB/day.
  • Views: 500M × 100 images/day = 50B/day ≈ 600k images/s; at ~100 KB each → 60 GB/s. CDN mandatory.
  • Likes: 4B/day ≈ 46k/s, very spiky on viral posts.

APIs

POST /v1/media/uploads              → {upload_id, presigned_url}
POST /v1/posts {upload_id, caption} → {post_id, status: PROCESSING}
GET  /v1/posts/{id}
POST /v1/posts/{id}/likes           (idempotent per user)
GET  /v1/posts/{id}/comments?cursor=

The architecture

CLIENTAppSERVICEPost APIOBJECT STORERaw bucketQUEUE / LOGMedia eventsWORKERImage processorresize, encode, scanOBJECT STOREVariants bucketNETWORKCDNDATABASEPost metadatasharded SQLQUEUE / LOGPostPublishedPUT (pre-signed)create postvariants ready→ feed fan-outGET imagemiss
Upload and serve paths: bytes never pass through app servers.
  1. The client uploads to the raw bucket via a pre-signed URL (resumable for poor networks).
  2. The post is created in PROCESSING state.
  3. Processors validate (type, size, malware, safety ML), generate variants and store them under content-addressed keys.
  4. The post flips to PUBLISHED; an event triggers feed fan-out.
  5. Clients request the variant that fits their screen from the CDN.

The 30-second summary

Say it in the interview

"Uploads go straight to object storage through pre-signed URLs; an async pipeline validates and produces immutable variants that are served through a CDN with an origin shield. Post metadata is sharded SQL; publishing emits an event that drives the feed. Likes are stored per user for idempotency, with counts in sharded counters to avoid hot rows. Stories use TTLs and lifecycle rules."

Follow-up questions the interviewer may ask

  1. How do you show a photo before processing finishes?
  2. How do you stop duplicate uploads from wasting storage?
  3. How do you serve the right image size to each device?
  4. How do you handle deletions and privacy?

Model answers to each of these are in the book.