Skip to content
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

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
1user → lb · GET /feedA user opens the app.1 / 7

The numbers, at a glance

For every post……there are about 60 feed loads
1 post ≈ 1,160/s60 feed loads ≈ 69,000/s
Photo storage grows fast100M photos a day × about 1 MB
The feed size is small150 KB feed copy vs a 2 MB original
So phones load images 13 times faster and the CDN carries 13 times less.

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.

Through app servers
Too heavy
POST 2 MB
app server
2 MB to every phone
+ One request.− 7 GB/s through our servers; originals to phones.
Signed upload + resize
Our pick
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.
Resize at the edge
Later
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.

Stage 1 · ≈ 1,000 feed loads/sMake it work
Mobile app
App server
Object storageSQL database
One server, one database, feed built by a query.
Stage 2 · ≈ 10,000 feed loads/sPrecompute feeds
Mobile app
Load balancer
App × NFan-out queue + workers
Object storagePost DBFeed cacheFollow graph
The feed query costs 20 reads; push post IDs into a cache instead.
Stage 3 · ≈ 50,000 feed loads/sServe the images
Mobile app
CDNLoad balancer
App × NImage workersFan-out
Object storagePost DBFeed cacheFollow graph
500,000 image loads a second: resize once, serve from the edge.
Stage 4 · ≈ 200,000 feed loads/sBig accounts
Mobile app
CDNLoad balancer
App × NImage workersFan-out
Object storage8 post shardsFeed cacheFollow graphLike counters
Shard posts, pull huge accounts on read, count likes in memory.
Was this walkthrough useful?Your vote tells us what to improve next.