Video Streaming: First Design
The edge is settled, so the question for minutes ten to twenty is what stands behind it, and the answer is very little. A creator sends a file, the file lands in an object store, and a viewer plays it through the CDN. Real people could watch video on that board today, which is why you draw it before anything cleverer.
Walk one upload and one view across it, the miss included, say who could run on it as it stands, and stop at what it cannot do. The interviewer's four pushes follow as the quiz, so try each before you read the options.
One File, One Store, One Edge
A creator's client sends the file through a load balancer to a tier of stateless app servers. A server streams the bytes through to the object store and keeps nothing on its own disk, the rule from Chapter 2's Stateless Services, Many Copies. Then it writes one row to a videos table: ID, owner, title, status, object key.
A viewer asks an app server for the video and gets a playback URL that points at the CDN. The CDN answers a hit, and on a miss it fetches the file from the object store, which is the origin in this design. The edge is on the board because of Scope's sum, and you say so as you draw it.
One Upload, One View
The upload first. The client calls POST with a title and a size, and gets back a video ID and an address on the app tier. It sends the whole file in one request. The server passes the bytes to the object store as they arrive. When the store confirms the last of them, the server writes the row, with the status ready, and answers. From that moment the file is durable. Until then there is no row, and the creator's own running request is the only status there is.
Now the view. The player calls GET on the video, and the server reads the row and returns the playback URL. The player asks the nearest edge location for the file. On a hit, the bytes come from there. On a miss, that location fetches the whole file from the object store, keeps a copy and answers, so the next viewer nearby gets a hit. The file goes out exactly as it was uploaded, and the player reads it from the start.
A Library for One Company
Creators upload and viewers watch. A video uploaded on a good connection plays for anyone whose network beats the file: a 1080p source at about 8 megabits a second plays on an assumed 25-megabit home link, for as many viewers as the edge will carry. The file is durable the moment the object store holds it. An internal video library for one company's offices needs no more than this, and you tell the interviewer so before any limit comes up.
The Price of One File
Four limits come next, named and left alone. The upload is one long request that has to finish on one connection. There is one file at one bitrate for every viewer. Nothing transforms the source, so a 4K upload goes out at about 40 megabits a second. And every edge location misses on the whole file on its own.
The first one you volunteer, in about ten seconds: "An upload has to finish in one connection here, and a viewer's network has to beat the file. A 4-gigabyte file at 5 megabits up is nearly two hours in one request, and I'd see finished uploads fall away as files get longer. So the upload comes first."
- Leaving the edge out of the first design to have something to add later. Scope's sum already said it belongs, and the interviewer hears a candidate who ignored their own estimate.
- Drawing a transcoding pipeline before anything has asked for one. The interviewer cannot match any box to a requirement, and the first design never gets walked.
- Proxying the bytes and also writing them to the server's disk, which breaks the stateless tier the same diagram relies on.
- Finishing without the limit, so the interviewer has to find the failed upload for you.
- One upload and one view traced through, the miss at the edge included.
- The network speed the design assumes, stated while the design is still being defended.
- Nearly two hours for 4 GB, raised unprompted, with finished uploads falling away as the sign.
Knowledge Check
"A creator on a phone connection is 90 percent through a 4 GB upload when the connection drops. What happens to that upload now?"
- "Retry the whole upload automatically until one attempt gets all the way through."
- "Compress the file on the phone first, so that the upload ends before it can fail."
- "Split the file into parts the server records, and resend only the missing parts."
- "Keep the partial file on the app server's disk, and resume it from there later."
"A viewer on a slow network presses play, and what comes down the wire is the 4K file. What do you do about that?"
- "Have the CDN compress each file on the fly to match that viewer's connection."
- "Ask the viewer to choose a quality from a menu before the video starts playing."
- "Serve one mid-quality encoding to everybody, so no viewer gets a 40 Mbps file."
- "Encode several bitrates, cut them into short pieces, and let the player switch."
"Encoding one hour of video takes this machine three hours, and the creator is waiting. How do you get under that?"
- "Run each video's whole encode on one worker, and add workers as uploads grow."
- "Split the source at keyframes, and fan the pieces out to a fleet through a queue."
- "Buy the fastest machine on offer, and run each encode on it from start to finish."
- "Encode nothing on upload, and wait to do the work until a viewer asks to watch."
"A million viewers start the same video in the same minute. What does your origin see?"
- "Nothing much, since the CDN holds the video and answers all of the million viewers."
- "Seventy links' worth of traffic, so size the origin to carry all of the 7 terabits."
- "One fetch per segment per shield, if misses collapse at every layer on the way."
- "Push every new video to every edge location before it is allowed to go public."
You got correct