System Design · Medium
Design an instagram photo sharing
Upload, process, and serve billions of photos with thumbnails, CDN, and metadata.
Requirements
What the system must do, and how well it must do it.
Functional
Upload photos (up to 50 MB) with captions, tags, and location.
Generate multiple resolutions (thumbnail, medium, full) automatically.
Serve photos via CDN with low latency worldwide.
Support likes, comments, and sharing.
Non-functional
Upload success rate > 99.9% under variable network conditions.
Photo visible to followers within 5 seconds of upload.
p99 read latency under 100 ms (CDN hit).
Store originals durably for 10+ years.
Estimation
Back of the envelope numbers that drive the design.
100M uploads/day, average 5 MB = 500 TB/day ingest.
3 resolutions + original = 4× storage. 500 TB × 4 = 2 PB/day new data.
CDN cache hit ratio > 95% for recent photos.
Metadata: 100M records/day × 500 bytes = 50 GB/day.
Architecture
Design decisions
Upload flow
The client requests a pre-signed URL from the media upload service, then PUTs directly to object storage (S3, GCS). This bypasses the API gateway for the large payload. On upload complete, the client notifies the API, which enqueues a media processing job.
Media processing
A worker pool (Kubernetes, Lambda, or dedicated fleet) picks up jobs from a queue. It downloads the original, generates thumbnails (150px, 640px, 1080px), extracts EXIF, runs content moderation, and writes outputs back to object storage. Metadata (dimensions, format, thumbnails URLs) is written to the metadata DB. Processing is async; the photo appears in the feed once the thumbnail is ready.
Read path and CDN
The CDN caches thumbnails and full-resolution images. The metadata DB (wide-column or document store) stores photo info: owner, caption, tags, location, thumbnail URLs, like count. The feed API queries the metadata DB for the user's followees, joins with photo metadata, and returns thumbnail URLs. The client fetches images directly from the CDN.
Storage tiering
Originals go to cold storage (S3 Glacier) after 30 days. Thumbnails stay in hot storage. A lifecycle policy moves data automatically. Deletes are soft (marked deleted, purged after 30 days) to support undo.
Questions and answers
Follow-ups an interviewer is likely to ask. Try answering before you open each one.
How do you handle a 50 MB upload on a flaky mobile connection?
Use resumable uploads (multipart with pre-signed URLs per part). The client retries failed parts. The upload service assembles parts and verifies checksums before enqueueing processing.
What if media processing is slow?
The photo appears in the feed with a low-res placeholder while processing completes. The client polls or uses WebSocket for the thumbnail-ready event.
How do you moderate content?
Run ML moderation (NSFW, violence, spam) in the media processor pipeline. Flagged photos are quarantined: not served, not in feeds. Human review queue for borderline cases. Appeals flow reinstates if overturned.