Social & feeds
Media feed - the feed serves URLs, the edge serves bytes
Why the feed serves URLs and the edge serves bytes, and who actually pays for the pixels.
The first act plays here. Owned once with credits, never a subscription.
What this board gets wrong on purpose
The tension
The post is published synchronously and the renditions are made asynchronously, so there is a window - usually two seconds, occasionally twenty minutes when the queue backs up - in which a post exists and its thumbnails do not. The client falls back to the 2.5 MB original over cellular, which is the worst possible outcome on the worst possible connection, and nothing on this board measures how often it happens. The second half is the CDN: renditions are immutable and cached for a year, so a deletion or a takedown propagates only as fast as a purge API nobody has load tested, and the signed URL expiry is the only real revocation - which means the honest takedown latency is the token lifetime, six hours, not the moment somebody pressed delete.
Practise this as an interview
Take Media feed - the feed serves URLs, the edge serves bytes as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.
Start here
Why this design
A photo feed looks like a ranking problem and is really a bytes problem: the post record is about 700 bytes and the picture is about 3,000,000. Interviewers use it to see whether you keep megabytes off the application entirely - on the way in and on the way out - and whether you can say who actually pays for the pixels. Any product that serves user photos at scale lives or dies on the same three moves: direct upload, a fixed rendition ladder, and an edge that does the real work.
What you will learn
- Why the upload is a pre-signed PUT straight to object storage, so 288 TB/day never passes through a service you deploy.
- Why renditions are a fixed ladder of four, made once, immutable and cached for a year - and why resizing per request defeats the cache.
- How the read path splits in two: the feed API serves 46,000 requests/s and ~0.4 GB/s of JSON; the edge serves 463,000 requests/s and ~55 GB/s of pixels.
- Why egress (~4.8 PB/day, ~$35M/year) is the bill, and why the original is 87% of storage and read almost never.
- Why publish does not wait for the transcode, and the honest window in which a post exists before its thumbnails do.
- Why a takedown really propagates at the signed-URL lifetime (six hours), not at the moment of delete.
How to read this board
- Press play once: the walkthrough follows one photo from the camera roll to a stranger's screen.
- UPLOAD · THE BYTES NEVER TOUCH THE API (top row): ask for a slot, then PUT the bytes around the service.
- PROCESS · ASYNC, AND THE POST DOES NOT WAIT (second row): one file becomes four, and publish runs beside it.
- DELIVER · JSON FROM US, BYTES FROM THE EDGE (third row): eight kilobytes of JSON, then the wire from the edge to the phone that touches nothing of ours.
- THE DATA MODEL · GENERATE SQL READS THESE: media, renditions, posts and the disposable feed index.
- Then pages 1 to 6 in order: requirements, capacity, storage, availability, how it works, deployment.
1 · Requirements
Clarifying questions to ask first
- Do we keep the original file forever, or only the renditions? This is the single biggest cost lever on the whole system and it is a product decision, not an engineering one.
- Are images public or access-controlled? Public means long-lived immutable URLs and a CDN that needs no identity. Controlled means signed URLs, which means an expiry, which means a cache key that churns.
- Which renditions does the client actually use, and who decides - server or device? A device that asks for arbitrary widths makes the cache useless.
- What is the acceptable publish-to-visible lag? If it must be zero, the transcode cannot be asynchronous and the whole board changes.
- Video too, or photos only? Video is a different pipeline with segmenting, multiple bitrates and a manifest. This board is photos.
- What is the egress budget? See the capacity page - it dominates every other cost by an order of magnitude.
Functional
- Upload a photo and publish a post referencing it.
- Read a feed: a page of recent posts from accounts you follow, each with a displayable image URL.
- Serve each image at the size the device needs, at the edge, worldwide.
- Delete a post; the image must stop being served.
Non-functional
- Feed API p99 under 150 ms. It returns a few kilobytes of JSON; there is no excuse for it to be slow.
- Image time-to-first-byte p95 under 100 ms from the edge, with a 95%+ CDN hit rate.
- Publish-to-renditions-ready p95 under 10 seconds.
- 99.99% durability target on originals, 99.9% availability on the read path.
- Upload must survive a flaky mobile connection: resumable, idempotent, retryable.
Explicitly out of scope
Ranking, stories, video, ads, comments, and the recommendation model. The feed order is drawn as one box.
The rest of this board
Available on Tier Slate
This page publishes the question. The answer — 5 more written pages, an 8-step narrated walkthrough and a 5-table schema — is the board itself, and it opens in Tierslate.
- 5written pages
- 8walkthrough steps
- 5tables28 columns
5 pages behind this one
- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan