Bugpit

Lessons › Big architectures

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 level

Part 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.

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?

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?

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?

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.

Try it yourself

More in Big architectures

← Stripe: the order that never shipped Chat app: 6 million online →