Skip to content
SD-45 · Back to the write-up

Design a Photo Library

Phones hash each photo and upload only new ones, straight to object storage; workers make thumbnails off the upload path, and a CDN serves the timeline.

Follow a request

Devices
Edge
Services
Data
Phone appBackup + browse
Other deviceTablet or web
CDNThumbnails
Library APIStateless
QueueJob per photo
Object storageOriginals + thumbs
Metadata DB16 shards by user
Image workersThumbnails, EXIF
1phone → api · POST /v1/uploadsA new photo appears in the camera roll. On Wi-Fi, the app hashes it and sends the SHA-256, size and date.1 / 7

The numbers, at a glance

Upload attempts that are duplicatesout of every 10 attempts
3 skipped by hash7 uploaded
Originals stored200M photos a day × 3 MB
Thumbnails are small3 sizes per 3 MB original
So thumbnails stay hot and cached, and originals move to colder tiers.

A backup, in order

A duplicate stops after step 3. Thumbnails are made after the 201, off the upload path.

Phone
Library API
Metadata DB
Object storage
Queue
Image worker
1 POST /v1/uploads { sha256 }
2 hash exists?
3 no
4 201 + part URLs
5 PUT part
6 200 etag
7 POST /complete
8 check hash
9 row + change
10 process job
11 201 backed up
12 pull job
13 read, write thumbs
RequestResponseAsync, does not block

How the bytes get to storage

The decision this question is really about.

POST via app servers
Too heavy
POST 3 MB
app server streamsresize inline
drop = start over
+ Server sees every byte.− 480 Gbit/s through servers.
Single signed PUT
Fragile
signed URL
PUT whole file
50 MB RAW drops at 90%
+ Bytes skip our servers.− No resume, no dedupe.
Hash, then multipart
Our pick
SHA-256 check
8 MB signed partscommit checks hash
queue → thumbnails
+ Skips duplicates; resumes parts.− Three calls per photo.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 50 uploads/sMake it work
Phone
App server
Object storageDatabase
One server takes the bytes, resizes, and writes a row.
Stage 2 · ≈ 2,000 uploads/sUpload direct
Phone
Load balancerLibrary API
Object storageMetadata DB
Hash first; signed parts straight to storage; servers behind a balancer.
Stage 3 · ≈ 7,000 uploads/sProcess in background
Phone
Load balancerLibrary APIQueue
Object storageShards by userImage workers
A queue and image workers; 16 shards by user.
Stage 4 · ≈ 20,000 uploads/sServe the timeline
PhoneOther devices
CDNLibrary APISync notifier
Object storageShards by userImage workersSearch
CDN for thumbnails, a search index, and pushes to other devices.
Was this walkthrough useful?Your vote tells us what to improve next.