Video platform: upload to play
You run a video site with 25,000 req/s at the evening peak. Most of it is people watching, a few are searching, and some are uploading, liking and commenting. Right now every request, video included, goes through your app servers to one database.
Play this levelPart of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
Big systems are several small systems sharing a front door. Start by splitting the traffic by kind: here that's watching, searching and writing. Each kind gets the path that suits it.
Watching is 85% of requests, and a video chunk never changes. So it belongs on a CDN, backed by object storage. Your servers should never touch a video file.
An upload is one big file that must be made into versions for every screen. A Video Encoder does that before anyone watches, so a viewer never waits for it.
Searching for a title means looking for words inside text, so it gets a search index. And likes, comments and view counts are writes that don't need an instant answer: put them in a queue, and let workers save them. Each write costs the database about 10 reads, so the primary needs a bigger machine too.
What you have to achieve
25,000 requests a second at the busiest hour, 2% of them writes and 85% static files.
- No broken or illegal connections
- Use a CDN
- Use an Object Storage
- Use a Video Encoder
- Use a Search Index
- Use a Queue
- No component is overloaded
- Workers clear the queue within the day
- Fewer than 0.1% of requests fail
- p99 response time under 300 ms
What you learn
Look at where the 25,000 req/s went: most of it never reached your servers. Each path does one job, and you can grow each one alone. That's how real video sites cope: not with a giant server, but by sending each kind of request somewhere cheap.
Check yourself
What's the first step in designing a system this big?
- Pick the biggest servers
- Split the traffic by kind and give each kind its own path
- Add a cache in front of everything
Show the answer
Split the traffic by kind and give each kind its own path. Watching, searching and writing have different needs. Once they're split, each path can be sized on its own.
Why does the video encoder never slow a viewer down?
- It runs once per upload, before anyone presses play
- It's on a very fast machine
- The CDN does the encoding
Show the answer
It runs once per upload, before anyone presses play. Encoding happens ahead of time. Viewers only ever fetch the finished files from the CDN.
Why did the Primary DB need a bigger machine even with a cache?
- Video files are stored in it
- Searches still scan it
- Every write costs it about 10 reads
Show the answer
Every write costs it about 10 reads. Likes, comments and views are writes. The queue smooths them out, but the database still has to save each one.