Video Streaming: Deep Dives and Curveballs
Two things have been waiting by name since Scaling It, the graph and the player's choice, and at minute thirty you go back for them. The rest of the round goes to what this problem is known for and few candidates reach, what all of it costs per hour someone actually watches, and then to four curveballs.
The Task Graph and Workers That Run Twice
You left the graph as one box. Three shapes could sit in it. One job per video is the simplest, and it retries a whole encode when a piece fails. A fixed chain of stages fits while every video takes the same path. A graph per video reruns only the failed task, and lets a 4K source add a rung or a check add a gate.
Choose the graph while videos differ, at the price of a task store. If this ever becomes one kind of input with one kind of output, the chain is enough and the task store can go.
A second run is harmless, as you said. A task that keeps failing is another matter, because a corrupt source fails every time. A worker tells the task store when it takes a task, so the store counts the tries, crashes included. Assume five. After that the task goes aside, the treatment Chapter 6's Delivery Semantics at Scale gives a poison message. The video's status says failed, so the creator sees it and nobody waits on a graph that cannot end.
One step must take effect exactly once: marking the video ready. It is a conditional write, from encoding to ready and from nothing else, the store's own tool in Chapter 5's Leases, Locks and Fencing. So a duplicate last task, arriving after a takedown, finds the status has moved and cannot republish the video.
Chapter 9's offline pipeline looks similar, and it is not. It rebuilds one index on a schedule. This one runs heavy jobs per item that fail one at a time.
The Player's Choice
Here is the choice you parked, and segment length is the trade inside it. At 2 seconds, a million viewers make 500,000 requests a second and a player reacts within 2 seconds. At 4, it is 250,000. At 10, it is 100,000, and a viewer on a falling network has 10 seconds of the wrong rung to get through. Shorter segments also need more keyframes, which costs picture for the same bytes. The choice is 4 seconds, and the trigger for shorter is live.
The player chooses from throughput, the buffer it holds, or both. Throughput alone chases every dip. Buffer alone climbs slowly. So use both, starting low so that the first frame is quick, and then climbing.
The Cost Curve
Prices are not on the sheet, so this one runs in bytes and machine-hours. A year of watching at 36 PB a day is about 13 exabytes, against 310 PB stored, about forty times more. A stored byte is paid for every month and a delivered one only once, so that compares bytes and not money. In bytes, egress leads for the platform, and the hits carry it. That average hides what a tail video costs.
Take two one-hour videos. Assume a hit of a million viewer-hours: 3 PB out, and at 99 percent edge hits, 30 TB from the origin. Assume a tail video, watched for 10 hours in its life: 30 GB out, nearly all of it edge misses. Both cost the same 3 machine-hours and 8.6 GB in the store.
Per hour watched, the tail takes 100 times the origin bytes and 100,000 times the encoding. So encode the full ladder only once a video earns it, which the box below prices. A newer, slower codec follows the same logic: it pays where each byte saved is multiplied by views, so it runs on hits only.
Encoding up front spends three machine-hours and stores 8.6 GB, source included, on each hour of video before anyone has watched it, and every viewer gets every rung from the first play. Use it when most uploads get watched.
Encoding on demand stores the source and one 3-megabit rung, about 5 GB and one machine-hour, and encodes the rest once a video crosses an assumed 100 hours watched. Use it when most uploads are tail, and accept early viewers on a lesser picture and a burst of work when a tail video takes off. Viewers below 3 megabits stall until the low rung exists, which for a video that never crosses the line means for good, against the 1-megabit floor agreed in Scope.
Name the ceiling on that saving before the interviewer does. If almost every upload stayed in the tail, the fleet would fall by two thirds, from 12,500 towards about 4,200, and stored bytes by about two fifths. The 13 exabytes hardly move, since hits carry them. A rung added later reaches the next player to start, through the manifest's short expiry.
Curveballs
"Make it live instead of uploaded." Name what disappears: the graph's time. One encoder per rung runs in real time, and a segment goes out as soon as it is finished. The manifest now changes every segment, so its expiry drops to about a segment. Latency is segment length times what the player holds. Assume 4 seconds and three segments, about 12 seconds. At 2 seconds, it is about 6, for twice the requests. A lost encoder cannot wait for a lease, so a second one runs beside it, at twice the encoders.
"The long tail now costs more than the hits." Do the sum per hour watched. Then move the tail to encoding on demand and a colder storage class, one cheaper to hold and slower to read, and warm only known launches. A first viewer then waits for a retrieval and gets a lesser rung. A team that only negotiates the CDN price has not touched the encoding or the storage.
"A copyrighted upload must be blocked before it is published." Add a fingerprint task to the graph and make the ready step depend on it, with the matching itself as a box. A match moves the status to blocked. Decide the failure policy out loud: "While the matcher is down, uploads wait, because publishing unchecked is the costlier mistake." Waiting uploads stay in encoding, and those tries do not count towards the five. The alarm on the oldest task's age rings until the matcher returns and the backlog drains.
A match after publishing is a takedown. Move the status to taken down and delete the renditions, so that a miss cannot refill the edge. Purge for speed, with the manifest's expiry as the bound, the treatment in Chapter 2's lesson on the edge. A player still holding a manifest can fetch segments until the purge reaches its location, and copies already in a browser cannot be recalled.
"A CDN region goes down." The CDN's routing moves its viewers to the next location, whose cache is colder for them, and the player steps down a rung. Assume a fifth of the audience, 1.4 of the 7 terabits, moves at once. The shield and the origin see the rise until that location has warmed.
If the whole CDN goes, the origin cannot carry 7 terabits, so the answer is a second CDN, at the price of a vendor to integrate and pay, the first of the two moves in Chapter 2's lesson. The second is a manifest capped at 3 megabits, which turns 7 terabits into 3 and costs every viewer the picture. Three terabits is still thirty links, so the cap shrinks the load on a second CDN and does not replace one. The playback URL is where a switch happens: the app servers hand it out, and a player that loses the edge asks them directly.
How Each Level Answers
A mid-level answer puts the object store and the CDN in the right places, knows video needs several bitrates, and fixes the failed upload when it is raised. It reaches the task graph with a hint, and treats a worker as something that finishes or fails until the interviewer asks about the lease.
A senior answer opens on 7 terabits and draws the edge in the first design because of it. It prices the upload drop before and after, raises the second run of a task unprompted and says what it writes, and gives the origin's load in links at a stated hit rate. It picks a segment length and says what the other two would cost.
A staff answer asks what the platform is paid for before settling the ladder, because a service that sells quality and one that sells reach want different encoding and different tails. It proposes the cost curve as the deep dive and works it per hour watched. It hands the takedown and the CDN outage to the product as decisions: who waits, who sees a worse picture, and which failure costs more.
- Quoting the playlist format when the question was who chooses the rung. Nobody asked for tags, and the deep dive runs out before the cost curve.
- Answering the cost curveball with "use a cheaper CDN", which leaves the tail's encoding and storage where they were.
- Answering live with "the same pipeline, faster". The interviewer hears that the graph's missing time went unnoticed.
- The cost worked per hour watched, so that a hit and a tail video can be compared at all.
- A segment length stated with the request rate and the reaction time that go with it.
- Which step in the graph must happen exactly once, and how, said without a hint.
Knowledge Check
"Make it live instead of uploaded." What is the best first move?
- Keep the same pipeline, and add workers until it finishes in time
- Say the graph's time has gone, and run one real-time encoder per rung
- Keep 4-second segments, and hand each player the manifest only once
- Send viewers the source as it arrives, as there is no time to encode
A copyright check must run before publishing, and the matcher goes down. What does the design do?
- Publish with the check skipped, then run it once the matcher returns
- Check only the videos that draw a complaint, once they have gone public
- Make ready depend on a fingerprint task, and hold uploads until it returns
- Refuse new uploads at the first call, as no check can run on them today
The whole CDN goes down at the peak. What is the origin's role?
- It takes all the traffic, as it was sized for a cold edge from the start
- It carries everyone on a 3-megabit cap, as that fits the links it has
- It cannot be the fallback, so name a second CDN and a cap, and each cost
- It serves only from the shield, as the shield still holds the hot segments
Most of your uploads are watched for a few hours and never again. Which encoding fits, and at what price?
- Every rung up front, and accept the fleet as the price of a clean picture
- Nothing at all until a viewer asks, and that first viewer waits for it
- Every rung up front, then deleting the lot after a year with no viewers
- The source and one 3-megabit rung, with the rest once 100 hours are watched
You got correct