SD-4 · Back to the write-up
Design a Photo Social Network
Upload once to object storage, resize in the background, serve from the edge; push post IDs into followers’ feeds and pull in huge accounts on read.
Follow a request
Post a photo
Fan a post out
Load the feed
Load an image
A worker crashes
Clients
Edge
Services
Data
Mobile appPhone
CDNImage copies
Load balancerAPI calls
App serversStateless
Image workersMake 3 sizes
Fan-out queuePost events
Fan-out workersPush post IDs
Object storagePhotos
Feed cacheIDs per user
Post DB8 shards
Follow graphFollowers
The numbers, at a glance
1 post ≈ 1,160/s60 feed loads ≈ 69,000/s
36.5 PBY1
73 PBY2
110 PBY3
146 PBY4
183 PBY5
7.5% feed copy2 MB original
A feed load, in order
The images come after, from the CDN, one request each.
Mobile app
Load balancer
App server
Feed cache
Post DB
CDN
1 GET /feed
2 route
3 top 30 IDs + big-account lists
4 post IDs
5 30 rows, one batch per shard
6 rows
7 200 + signed image URLs
8 feed page
9 GET m.jpg × 10
10 150 KB each
RequestResponseAsync, does not block
How a photo reaches phones
The decision that sets the bandwidth bill.
POST 2 MB
app server
2 MB to every phone
+ One request.− 7 GB/s through our servers; originals to phones.
PUT to storage
workers: s · m · l
CDN serves 150 KB
+ Small calls only; sizes ready before the post is live.− Two steps to post.
GET ?w=640
image proxy resizes
cache the result
+ Any size on demand.− CPU on every miss.
How it grows
Add a box only when a number forces you to. Highlighted boxes are new at each stage.
Mobile app
App server
Object storageSQL database
Mobile app
Load balancer
App × NFan-out queue + workers
Object storagePost DBFeed cacheFollow graph
Mobile app
CDNLoad balancer
App × NImage workersFan-out
Object storagePost DBFeed cacheFollow graph
Mobile app
CDNLoad balancer
App × NImage workersFan-out
Object storage8 post shardsFeed cacheFollow graphLike counters
Was this walkthrough useful?Your vote tells us what to improve next.