Design the backend for a mobile photo sharing app. Users upload photos with a caption, follow other users and scroll a home feed of recent photos from the accounts they follow. The app has 50 million daily active users who upload 5 million photos a day and load their feed about 30 times a day each. Photos must show up in followers' feeds within a minute and load quickly on slow mobile networks anywhere in the world.
Functional requirements
Upload a photo with a caption; the app shows it in several sizes
Follow and unfollow other users
Scroll a home feed of recent photos from followed accounts, newest first
Like a photo and see like counts
Non-functional requirements
Feed pages load in under 300 ms at p95, excluding image download
Uploaded photos are never lost once the upload succeeds
A new photo appears in followers' feeds within 1 minute
Images load fast worldwide on mobile connections
Constraints and scale
50 million daily active users, peaking at about 30,000 feed requests per second
5 million uploads a day at 3 MB average, about 15 TB of originals per day
Median user follows 150 accounts; a few celebrities have over 10 million followers
You will practise
Separate large binary data (object storage and CDN) from metadata (database)
Generate image variants asynchronously with a queue and workers
Choose between fan-out on write and fan-out on read for feeds, including celebrity accounts
Show 2 hints
Should the upload request wait while the server produces three resized copies of the image?
Copying a celebrity's post into 10 million feeds takes a while. What could you do for those accounts instead?