System designby Learnastra

System-design interview · Core interviews

Design a video streaming service

By Anup Rai

Design resumable uploads, durable encoding jobs and atomic media publication; derive adaptive playback and CDN capacity from watched duration, bitrate and segment traffic.

You will learn to

  • Explain why one upload becomes several playable renditions.
  • Calculate starts, concurrent viewers, storage, and network egress separately.
  • Publish a complete playable asset safely despite worker retries and failures.

Practice in this chapter

8 interview questions with model answers and follow-ups.

Go to interview practice

Useful foundations: Message queues, event logs, delivery guarantees, and backpressure · Proxies: forward proxy, reverse proxy and API gateway · Replication and durability

Workload and timing examples are interview assumptions.

01Problem and scope

A video streaming service ingests media, prepares playable representations, and delivers them efficiently as viewer bandwidth changes. A codec defines how media is encoded and decoded; a rendition is one prepared quality and bitrate; a segment is a short playable piece; a manifest lists renditions and segment locations. For example, a two-minute video can offer aligned segments at several bitrates so a player moving from Wi-Fi to a slower mobile link can request a lower-quality next segment without downloading the original again.

Bitrate is the amount of encoded media data needed per second of playback. The player downloads ahead into a buffer so brief network slowdowns need not interrupt viewing. If that buffer empties, playback pauses to refill it; this is rebuffering. Preparing several bitrates lets the player trade picture quality for a download rate its connection can sustain.

This design covers user uploads and on-demand playback with search and basic interactions; live streaming and recommendation ranking are outside the core. A completed original upload returns durable processing status, while READY requires a verified playable output set. A licensed subscription catalog adds licensing windows, regional entitlement and often digital rights management (DRM), including a service that releases decryption keys to authorized players. Those are additional authorization requirements, not synonyms for the upload product.

Support resumable uploads, status, title search, thumbnails, comments, likes/dislikes, view statistics, sharing, seeking and cross-device resume. Exclude subscriptions, recommendation ranking, watch-later collections and live low-latency broadcasting. Include encoding, storage, thumbnails, deduplication and delivery. Derive each capacity estimate from the same upload and viewing assumptions so the totals describe one coherent workload.

02Functional requirements

  1. Resume upload: Retry missing parts without resending verified completed parts.
  2. Complete original: Durable original plus recoverable processing job.
  3. Publish: Every required object in the selected manifest exists and matches its version.
  4. Play/seek: Compatible rendition and segment near the requested media timestamp.
  5. Resume on another device: Stored progress is advisory; new device selects its own codec/quality.
  6. Search/comment/rate: Visible video identity; interactions have independent pagination and retry behavior.
  7. Delete: Stop new authorized playback, then reclaim retained outputs safely.

Upload lifecycle and status delivery

An upload has states UPLOADING, PROCESSING, READY, FAILED and DELETED. UPLOADING means incomplete bytes; PROCESSING means the original is durable but variants are not published; READY means the required manifest, segments and thumbnail are verified. The UI shows each distinction. A notification may announce READY through the app or an optional email integration; status polling remains available if that notification is missed.

Publication scope and retained media

We require a minimum playable rendition set rather than waiting forever for every optional high-resolution encode. Upgrading later publishes a new immutable manifest version. View counts are approximate and asynchronously deduplicated under a defined counting policy. A byte-identical upload may be reusable, but similarity is not proof of ownership or permission. Already downloaded media cannot be recalled by deleting its database row.

03Non-functional requirements

Playback authorization decides whether the viewer may receive a video. A short-lived delivery grant carries that permission to the media-serving layer. A content delivery network (CDN) caches the permitted media near viewers, while the origin is the backing service or store used when a cache misses. These separate roles explain why authorization latency, startup delay and stored-original durability have different targets.

  1. Playback authorization: p95 below 150 ms.
  2. Startup latency: Start-to-first-frame p95 below two seconds on a stated adequate test network.
  3. Availability: 99.9% eligible playback-start availability.
  4. Rebuffering: Below 1% of watched time in the measured network cohort; report this separately from startup latency.
  5. Upload processing: 95% of ordinary two-minute videos become READY within five minutes at planned load. Extremely complex or invalid media may fail with a reason instead of remaining indefinitely in processing.
  6. Durability: Acknowledged originals and publication metadata survive one storage-node or availability-zone failure. Regenerating derivatives costs time and compute.
  7. Regional recovery: Initially replicate originals/metadata asynchronously with a tested recovery point and restore time. A CDN does not imply absolute zero loss.
  8. Private-media revocation: New playback authorization checks current ownership/entitlement. Delivery grants last up to five minutes in this exercise, making the stale-access interval explicit.

Publication and outage boundaries

Rule Consequence
Complete READY generation READY points to a complete immutable manifest, never a directory still being written.
Fenced encoder A stale encoder cannot replace the accepted generation.
Encoder outage Delivery can continue serving cached authorized objects because playback and processing have separate dependencies.
Authority loss Cached bytes cannot authorize new private sessions. Statistics/search may lag; permissions may not be guessed.

Immediate revocation is a different contract

04Capacity estimates

Workload assumptions and arithmetic

Assume 800 million daily viewers watching five videos/day: four billion starts/day, or 46,296 starts/s. One upload per 200 views gives twenty million uploads/day, or 231/s. Use a two-minute original at 10 MB/minute: 20 MB/upload produces 400 TB/day of original ingress, about 4.63 GB/s. All derived renditions together at 50 MB/minute produce another 2 PB/day. These figures imply about 463 uploaded hours/minute. Rounding that to 500 uploaded hours/minute is reasonable for an initial estimate, but downstream calculations must identify which figure they use.

Assume a view watches sixty seconds at a mean 5 Mb/s. Concurrent playback is 46,296 starts/s × 60 s ≈ 2.78M viewers. Egress is 2.78M × 5 Mb/s ≈ 13.9 Tb/s, or 1.74 TB/s. This depends on watch duration and selected bitrate, not just the upload:view ratio. A threefold traffic peak would triple concurrency and delivery demand unless user behavior changes.

Worked estimates

Resource Calculation Consequence
Four-second media segment 5 Mb/s × 4 / 8 = 2.5 MB Cache and transfer unit
Average segment requests 2.78M / 4 ≈ 694,444/s Media requests per second greatly exceed playback starts per second
Five 5 KB thumbnails/upload 20M × 25 KB = 500 GB/day Small-object serving also needs a plan
One month original retention 400 TB × 30 = 12 PB Retention is a first-order cost
95% media byte-hit ratio 1.74 TB/s × 0.05 ≈ 87 GB/s origin Origin remains substantial after caching

Capacity implications and limits

Encoding capacity must be benchmarked for the chosen codec, resolution ladder and hardware. A measured twelve worker-seconds per assumed clip would require 231 × 12 ≈ 2,772 busy worker slots on average, before peak and failure reserve. This is an illustrative measurement input, not a portable encoder performance claim.

05APIs and contracts

Request and response example

The uploader calls POST /v1/video-uploads with request key upload-v42 and {"title":"Bicycle brake adjustment","bytes":20000000,"language":"en","visibility":"public"}. The service returns videoId:v42, uploadId:up42, permitted part targets and expiry. Optional description, tags, category and recording location are metadata fields; collect location only when the product needs it. Completion verifies the original and returns 202 PROCESSING plus a queryable status URL.

Interface contracts

API Contract
PUT /uploads/up42/parts/3 Retry one scoped part with integrity metadata
POST /uploads/up42/complete Assemble/verify original, durably schedule encoding
GET /videos/v42/status Owner processing state and useful failure reason
POST /videos/v42/playback with device capabilities/offset Authorized manifest version and short-lived delivery grant
PUT /me/progress/v42 Session sequence and media offset; idempotent progress update
GET /videos/search?q=brake&cursor=...&limit=20 Title matches, thumbnail, creation time and delayed counts
POST /videos/v42/comments / PUT .../reaction Idempotent interaction with independent pagination

Validation and response semantics

Resume position is a media timestamp, not a requirement to reuse the TV's exact codec on a phone. The phone advertises its capabilities and chooses a compatible rendition. A repeated upload key with different metadata/content identity returns 409; malformed formats, oversized bytes and exhausted quotas have explicit errors. A timed-out completion checks the same upload session rather than uploading a second v42. Search continuation tokens are opaque and scoped to the query/version policy.

06Data model and access patterns

Track byte transfer, encoding and publication separately because success in one stage does not complete the others. Upload records the original's transfer; EncodeJob tracks attempts to prepare playable media; Manifest identifies the accepted output set; Video names the version viewers may use. The outbox durably records the next stage's work alongside the metadata change that requires it.

Record and fields Responsibility / constraint
Video(videoId,ownerId,createdAt,title,description,language,visibility,state,originalKey,originalVersionId,sourceGeneration,manifestVersion,deletedAt) Owns publication.
Upload(uploadId,requestKey,expectedBytes,checksum,parts,leaseUntil) Owns transfer progress.
EncodeJob(videoId,sourceGeneration,attemptToken,leaseUntil,state) Owns processing attempts.
Manifest(videoId,version,objectKey,checksum,requiredRenditions) Identifies published outputs; each rendition names immutable segment objects.
Outbox Stores encode/publish/delete intentions in the metadata transaction.

Users, reactions, comments and progress are separate records. Comments index (videoId,createdAt,commentId) for bounded pages; reactions have a unique user/video identity. Counts are derived, so one popular video's views do not serialize every playback on a metadata row. Progress updates use a session generation and monotonically increasing event sequence; a late old event must not overwrite a newer seek/pause choice merely because its numeric playback offset is larger.

Partition primary metadata by video ID with an owner/time index for the uploader's library and a title-search index for discovery. User-based placement offers gallery locality but can create hot publishers; video-based hashing still leaves viral v42 hot. Replicated caches and CDN copies address that repeated key. Original and derived objects live in private durable storage; metadata decides whether they are published and authorized. Thumbnail objects may use object storage with caching or a packed small-object store; choose from measured operation cost and latency, not an assumption that every image requires a separate disk seek.

Define cross-device progress ordering explicitly. In this version the service allocates an increasing playback-session generation for each user/video when a new resumable session starts; progress accepts only that generation and an increasing event sequence within it. The latest session controls the shared resume point, while older simultaneous sessions may continue playing but cannot overwrite it. This is a product policy, not a claim that wall clocks order devices; separate per-device progress is an alternative.

07Basic working design

Durable original and background encoder

Begin with one application, a SQL metadata database, durable original storage and one background encoder. The uploader uploads a complete file, the API verifies it and transactionally stores PROCESSING plus an encoding intention. The worker creates one broadly compatible rendition and thumbnail under an isolated output prefix. After checking them, it publishes READY metadata with the immutable manifest pointer. The viewer obtains that manifest and fetches media from the local origin server.

One database can schedule work

Even at small scale the encoder should not occupy an HTTP request for minutes. An outbox or job table inside the metadata database is enough for durable scheduling; a separate queue product is not mandatory. If the app crashes after committing the job but before responding, upload-v42 returns the existing v42 state. A worker crash can retry its attempt without making partial outputs visible.

Baseline playback and bottlenecks

This baseline can serve a small training-video library and supports pause, seek and resume with ordinary prepared files/segments. Its limitations are one encoding queue, one origin's egress, a single quality choice and limited failure isolation. Backups retain originals plus publication state; derived bytes can be rebuilt but rebuilding is a recovery delay. These are the limits that motivate separate encoding capacity, more playback qualities and delivery caches.

architecture · baselineOne encoder and a verified publication pointer

The original and job survive the API request; READY points only to the worker’s complete verified output set.

One encoder and a verified publication pointerThe original and job survive the API request; READY points only to the worker’s complete verified output set. client to api: 1. Upload / request playback; api to objects: 2. Store verified original; api to meta: 3. Commit PROCESSING job; meta to encoder: 4. Claim pending encoding; encoder to objects: 5. Write verified rendition; encoder to meta: 6. Publish READY manifest; client to objects: 7. Fetch authorized media1. Upload / request playback2. Store verified original3. Commit PROCESSING job4. Claim pending encoding5. Write verified rendition6. Publish READY manifest7. Fetch authorized mediaACTORUploader and playerclientsSERVICEVideo controlapplicationSTORESQL video metadataand jobsWORKERBackground encoderSTOREDurable original andoutput storagesyncasync
Read each connection in order
  1. sync1. Upload / request playbackUploader and player clients → Video control application
  2. sync2. Store verified originalVideo control application → Durable original and output storage
  3. sync3. Commit PROCESSING jobVideo control application → SQL video metadata and jobs
  4. async4. Claim pending encodingSQL video metadata and jobs → Background encoder
  5. sync5. Write verified renditionBackground encoder → Durable original and output storage
  6. sync6. Publish READY manifestBackground encoder → SQL video metadata and jobs
  7. sync7. Fetch authorized mediaUploader and player clients → Durable original and output storage

08Find the baseline flaws

Bottleneck / counterexample Evidence and design consequence
Origin egress At the assumed average, the origin would need about 1.74 TB/s to serve every viewer directly. Adding application CPU does not solve that network requirement. Even a much smaller launch experiences a hot-video skew: one popular clip can exhaust one origin while many cold files receive almost no traffic. Hashing video IDs does not spread concurrent requests for the same v42 across sufficient delivery capacity.
Insufficient playback bitrate choice A single 5 Mb/s rendition also fails the viewer's mobile transition. On a 2 Mb/s link, downloading one four-second 2.5 MB segment takes about ten seconds, so buffer drains faster than it fills. A lower rendition near 1 Mb/s would need about two seconds for four seconds of content under the same idealized link. Multiple prepared renditions and a player adaptation policy address this; asking the metadata API to transcode on each quality switch would be wasteful and slow.
Partially written or stale manifests The correctness counterexample is publishing a playlist while its encoder still writes segments. The viewer successfully fetches the manifest but receives 404 halfway through playback. A second encoder can also wake after lease expiry and replace the manifest with an incomplete old attempt. The final design must atomically choose a verified immutable output generation and fence stale publication, while ensuring stale workers cannot overwrite accepted object names.

09Improve the design, step by step

  1. Use resumable direct uploads with isolated control capacity. Large-file network interruption triggers part-based upload sessions. Clients retry missing parts to private storage; the API verifies completion and commits the processing job. This saves retransmission and protects playback APIs from slow upload sockets. Costs are session metadata, abandoned parts and scoped-token expiry. Single PUT remains simpler for small clips; multipart is selected by size/reliability needs, not because every object requires it.

  2. Scale a leased encoding pipeline and publish manifests atomically. When jobs wait too long or require several formats, add workers. Each attempt writes separate immutable outputs; the database checks its attempt token before publishing READY. This increases processing throughput and makes retries recoverable. Costs are encoder compute, rendition storage and duplicate abandoned attempts. Waiting for every optional rendition is rejected; publish a defined minimum set and add a new manifest later if optional outputs complete.

  3. Add adaptive segmented playback. The viewer's bandwidth change triggers aligned rendition segment timelines and device-compatible manifests. The player can switch future requests without restarting the whole video, improving rebuffer behavior. Costs include more output bytes, encoding and player logic. A single progressive file is simpler for short controlled-network content, and live streaming requires a different moving-manifest/latency design.

  4. Place delivery caches near viewers and partition metadata services. Origin egress and global latency trigger CDN caches, origin shielding and replicated metadata/read caches. Hot segments are reused across viewers while uploads/encoders remain isolated. Costs include cache misses, authorization distribution, purge complexity and delivery charges measured in bytes. Keeping rarely watched content at origin can be sensible; blindly pushing every rendition everywhere wastes storage and transfer.

Concept in focusChange quality without jumping on the timeline

Each column covers the same media interval in every rendition. Green markers sit inside selected segments; vertical steps at 4 and 6 seconds mark rendition switches.

Change quality without jumping on the timelineEach column covers the same media interval in every rendition. Green markers sit inside selected segments; vertical steps at 4 and 6 seconds mark rendition switches. Follow four segment requests across two quality levels. The player chooses 720p for 0–2 and 2–4 seconds, 1080p for 4–6, then 720p for 6–8. These aligned examples assume the codec and rendition compatibility required for switching.Aligned segments let a player change quality at a boundary360p0-2 s2-4 s4-6 s6-8 s720p0-2 s2-4 s4-6 s6-8 s1080p0-2 s2-4 s4-6 s6-8 sGreen path: request 720p, 720p, 1080p, then 720p.The media timeline continues even when selected quality changes.

Remember: Switch renditions at compatible segment boundaries.

Read the diagram
  1. Follow four segment requests across two quality levels.
  2. The player chooses 720p for 0–2 and 2–4 seconds, 1080p for 4–6, then 720p for 6–8.
  3. These aligned examples assume the codec and rendition compatibility required for switching.
Try from memoryDoes choosing 1080p for 4–6 seconds require replaying the earlier segments?

No. With compatible renditions and aligned segment boundaries, the next segment continues the media timeline.

An origin shield is a shared cache between many delivery-edge caches and the origin. If several edges miss the same popular segment, the shield can reuse a single cached copy and coalesce concurrent fills instead of sending every miss to origin storage. It protects the origin from repeated work but adds another cache and request hop.

Search, comments and counters become independent derived/read services only when their load warrants it. They cannot be allowed to delay already authorized segment delivery or redefine whether an encoding generation is ready.

10Detailed architecture

Control APIs and publication authority

The control edge routes upload management, metadata, search and playback authorization to stateless APIs. The storage leader for each video’s metadata partition commits upload states, job/outbox rows, manifest pointers and visibility through its replica group. This leader is the metadata owner referred to in the publication protocol. A title index, comments and reaction/progress stores support product queries with their own keys. A read replica with lag may serve discovery but cannot mint new private playback grants if it cannot establish the required current permission state.

Encoding and manifest publication

The processing path consumes durable encoding jobs, reads the original and writes attempt-specific variants and thumbnails. A publisher checks the required objects, then asks the metadata database to publish the manifest only if its attempt is still current. The original store has separate durability and retention from caches; losing a worker does not lose the source video. The final diagram combines encoder and thumbnail work in one worker tier because they share the source and job lifecycle, while allowing separate queues if measured resource needs differ.

Adaptive media delivery

The media path runs from the viewer's player to an authorized delivery edge, then regional/origin caches and immutable object storage on a miss. The API does not proxy every segment. Tokens/cookies may authorize a family of segment URLs for one session, which avoids a central database round trip for each of roughly 694,000 average segment requests/s. That choice explicitly bounds revocation by grant lifetime. Telemetry is asynchronous and never blocks a segment because a view counter is slow.

Partition ownership and hot keys

When a partition moves or a leader fails, routing directs requests to the new owner and storage rejects writes from the old owner. Consistent hashing can reduce cache-key movement, but it neither creates durable replicas nor cures a viral segment's skew by itself.

Concrete implementation choices

HTTP Live Streaming (HLS) is one format family for describing available renditions and serving their segments over HTTP. It supplies the player's media request structure; the surrounding application must still decide when those outputs are complete and who may fetch them.

A concrete implementation can begin with PostgreSQL metadata/job transactions, a managed durable object store, a file-based encoder such as MediaConvert or sandboxed encoder workers, and HLS manifests behind a CDN. The encoder product prepares media; the application still owns request deduplication, required-output validation, publication fencing, authorization and cleanup. Add a separate queue when independent worker throughput or operational isolation justifies it; a database job table remains a valid small baseline.

architecture · finalDurable processing separate from adaptive delivery

Control APIs publish an immutable manifest generation. Players request segments through an authorized CDN, independent of upload/encoding workers.

Durable processing separate from adaptive deliveryControl APIs publish an immutable manifest generation. Players request segments through an authorized CDN, independent of upload/encoding workers. client to edge: 1. Upload session / playback request; edge to api: 2. Route authenticated control; api to meta: 3. Reserve / authorize manifest; meta to replicas: 4. Replicate authoritative state; client to objects: 5. Upload scoped original parts; meta to queue: 6. Relay committed encode job; queue to encoder: 7. Claim current attempt; encoder to objects: 8. Read original / write variants; encoder to meta: 9. Guarded READY publication; meta to index: 10. Index committed publication; api to index: 11. Search / comments / progress; api to client: 12. Manifest and delivery grant; client to cdn: 13. Request adaptive segments; cdn to shield: 14. Cache miss; shield to objects: 15. Fetch immutable origin; client to telemetry: 16. Report startup and stalls; telemetry to stats: 17. Aggregate QoE and views1. Upload session / playbackrequest2. Route authenticated control3. Reserve / authorize manifest4. Replicate authoritative state5. Upload scoped original parts6. Relay committed encode job7. Claim current attempt8. Read original / write variants9. Guarded READY publication10. Index committedpublication11. Search / comments /progress12. Manifest and delivery grant13. Request adaptive segments14. Cache miss15. Fetch immutable origin16. Report startup and stalls17. Aggregate QoE and viewsACTORUpload clients andvideo playersSERVICEControl API routingG1SERVICEUpload, metadataand playback APIG1STOREVideo authority andoutboxG1STOREMetadata replicasG1QUEUEEncoding work queueG2WORKEREncoder andthumbnail workersG2STOREPrivate originals andvariant storageG2STORESearch andinteraction storesG1CACHEAuthorized mediaedge / CDNG3CACHEOrigin shield andcacheG3QUEUEPlayback telemetrypipelineG4STOREQuality andapproximate countsG4syncreplicationasyncG1 Metadata and authorizationG2 Durable processing and mediaG3 Authorized byte deliveryG4 Asynchronous observation
Read each connection in order
  1. sync1. Upload session / playback requestUpload clients and video players → Control API routing
  2. sync2. Route authenticated controlControl API routing → Upload, metadata and playback API
  3. sync3. Reserve / authorize manifestUpload, metadata and playback API → Video authority and outbox
  4. replication4. Replicate authoritative stateVideo authority and outbox → Metadata replicas
  5. sync5. Upload scoped original partsUpload clients and video players → Private originals and variant storage
  6. async6. Relay committed encode jobVideo authority and outbox → Encoding work queue
  7. async7. Claim current attemptEncoding work queue → Encoder and thumbnail workers
  8. sync8. Read original / write variantsEncoder and thumbnail workers → Private originals and variant storage
  9. sync9. Guarded READY publicationEncoder and thumbnail workers → Video authority and outbox
  10. async10. Index committed publicationVideo authority and outbox → Search and interaction stores
  11. sync11. Search / comments / progressUpload, metadata and playback API → Search and interaction stores
  12. sync12. Manifest and delivery grantUpload, metadata and playback API → Upload clients and video players
  13. sync13. Request adaptive segmentsUpload clients and video players → Authorized media edge / CDN
  14. sync14. Cache missAuthorized media edge / CDN → Origin shield and cache
  15. sync15. Fetch immutable originOrigin shield and cache → Private originals and variant storage
  16. async16. Report startup and stallsUpload clients and video players → Playback telemetry pipeline
  17. async17. Aggregate QoE and viewsPlayback telemetry pipeline → Quality and approximate counts

11Write path and acknowledgement

Media publication commits an immutable verified output generation rather than exposing a directory still being encoded. The trace uses video v42, upload up42 and source generation g1.

  1. The uploader authenticates and reserves up42/v42 with expected length, checksum and source generation g1. The API returns constrained part-upload authorization.
  2. The upload client uploads parts, records completed part identities locally and retries missing parts after a network break. The trusted completion path finalizes the approved part list and verifies the resulting object, not merely the existence of a few uploaded parts. It pins the returned immutable object version and checksum to g1; encoders read that exact version. Reusable upload authorization must not let a later write silently change the source being encoded.
  3. The completion API checks ownership and session validity, then commits PROCESSING and outbox job encode-v42-1. The uploader receives 202 and can poll status. If the response is lost, retry returns this same job identity.
  4. Worker W1 claims attempt token 41, reads the durable original and generates required renditions/thumbnail under v42/g1/attempt41/.... Resource limits bound decoding time, memory and output size.
  5. A validator checks segment presence, declared durations, codec compatibility and the complete required manifest. Optional outputs may remain absent under the minimum-set policy.
  6. The metadata owner atomically requires the current token and source generation, no deletion, and PROCESSING state before setting READY with manifest version 1 and a publication outbox event.
  7. Search indexing and user notification consume the committed publication event. If the worker crashes after step 6, repeating publication returns the accepted manifest instead of creating a second version. Abandoned attempts remain invisible and are reclaimed only after their publication rights expire or are superseded.

Changing the uploader's original requires a new source generation. No retry may write different bytes under the accepted immutable object identity.

12Read and delivery path

Playback separates authorization from repeated media transfer. This trace uses manifest version 1 for video v42, then shows segment selection, adaptation, seeking and ordered progress updates.

  1. The viewer requests playback for v42 with device codec capabilities and optional resume offset. The API verifies current visibility/entitlement and READY state, then returns manifest version 1 and a five-minute scoped media grant.
  2. The player requests the manifest through the delivery edge. The edge validates the grant before serving cached bytes or fetching the private origin. Manifest version 1 always names the same accepted segment set.
  3. The viewer's player chooses a compatible starting rendition, fetches enough initial media to begin playback and measures transfer speed plus buffer depth. Startup is reported separately from steady-state throughput.
  4. It fetches successive four-second segments. When bandwidth drops, it requests subsequent aligned segments from a lower-bitrate rendition. Previously buffered segments remain useful; the metadata database is not involved in each switch.
  5. Seeking to 75 seconds selects the appropriate media-time segment/keyframe boundary according to the format, then decodes to the requested position. Byte offsets and media timestamps are not interchangeable.
  6. The player periodically saves progress with a playback-session sequence. The viewer's phone later loads that advisory offset but chooses its own rendition/codec. Out-of-order old progress events cannot replace a newer deliberate seek.
  7. Quality-of-experience (QoE) events report startup delay, playback stalls and selected bitrate asynchronously. A stats outage should not pause the film. A token nearing expiry refreshes through authorization; if permission has been revoked, new grants stop even if segment bytes remain cached.

Repeated cache redirections add requests and startup latency. Prefer deliberate edge routing and bounded origin fallback rather than bouncing a viewer through an unbounded chain of increasingly distant caches.

13Correctness deep dive

Lease and token responsibilities

A job lease permits a worker to attempt processing for a bounded time; an increasing attempt token identifies the currently authorized publisher. The metadata owner enforces that token atomically at publication. The object store cannot be assumed to understand the metadata lease, so output names must isolate attempts.

Transition Required metadata guard Durable result
Claim W1 PROCESSING, no valid current claim token 41 with deadline
Reclaim W2 token 41 expired, still unready token 42 supersedes 41
Publish W2 token 42 current, objects verified, not deleted READY manifest B and one publication event
Late publish W1 token 41 does not match Reject without changing B
Repeat successful publish Same accepted generation/manifest Return existing READY result

A stale encoder resumes

W1 writes ten 720p segments, pauses and loses its lease. W2 claims 42, encodes a complete required set and publishes manifest B. W1 wakes and writes more attempt41 segments. Those cannot replace B's objects because B names attempt42 paths. W1's metadata update fails the token check. Thus both the pointer and its bytes are protected. A “fencing token” that is checked only by a worker's own code would not prove this outcome; the authoritative metadata write must enforce it.

Deletion and retained sessions

Deletion is serialized at the same video owner. If DELETED commits first, neither worker may publish; if READY commits first, deletion removes new authorization and schedules cleanup. Reclamation must account for active playback-token lifetime and retained manifest versions before deleting their segments. A garbage collector first proves an attempt is no longer publishable; an elapsed wall-clock guess alone is insufficient if a worker can renew or publish afterward.

Define the minimum playable set

The minimum playable set must be concrete, such as one compatible audio/video rendition and thumbnail. “Most files exist” is not a publication criterion. Validation failures remain PROCESSING/FAILED and do not leak a half-complete playlist to viewers.

Prevent rewrites of published objects

Collection must revoke publication rights

sequence · encoder-raceThe replacement publishes; the old attempt is rejected

Output names isolate attempts, while metadata atomically enforces the currently authorized publisher.

The replacement publishes; the old attempt is rejectedOutput names isolate attempts, while metadata atomically enforces the currently authorized publisher. w1 to meta: Claim token 41; w1 to obj: Write partial attempt41 outputs; w2 to meta: After expiry: claim token 42; w2 to obj: Write and verify complete attempt42; w2 to meta: Publish manifest B under token 42; meta to w2: READY version 1 committed; w1 to obj: Late writes remain under attempt41; w1 to meta: Try publish with token 41; meta to w1: Reject obsolete publicationPARTICIPANTEncoder W1PARTICIPANTVideo authorityPARTICIPANTEncoder W2PARTICIPANTObject store1. Claim token 412. Write partial attempt41 outputs3. After expiry: claim token424. Write and verify completeattempt425. Publish manifest B undertoken 426. READY version 1committed7. Late writes remain under attempt418. Try publish with token 419. Reject obsolete publicationsyncreturn
Read each connection in order
  1. syncClaim token 41Encoder W1 → Video authority
  2. syncWrite partial attempt41 outputsEncoder W1 → Object store
  3. syncAfter expiry: claim token 42Encoder W2 → Video authority
  4. syncWrite and verify complete attempt42Encoder W2 → Object store
  5. syncPublish manifest B under token 42Encoder W2 → Video authority
  6. returnREADY version 1 committedVideo authority → Encoder W2
  7. syncLate writes remain under attempt41Encoder W1 → Object store
  8. syncTry publish with token 41Encoder W1 → Video authority
  9. returnReject obsolete publicationVideo authority → Encoder W1

14Failure and recovery

Failure / trigger User outcome, surviving state and recovery
Encoder crash Original g1 and job state remain durable. The uploader sees delayed processing. A replacement claims a newer token and generates missing outputs in its own attempt path, then publishes if still authorized. Poison media receives a bounded retry count and durable failed reason; repeatedly retrying a decoder crash can waste the whole fleet.
Metadata partition or zone loss A surviving majority may authorize publication/playback; a minority cannot. Existing media grants and cached immutable segments may continue until their explicit expiry. A full-region loss has a separate recovery procedure and possible asynchronous loss window. A CDN cache is not a durable archive of the uploader's original, and replica lag has no automatically guaranteed “few milliseconds” bound.
Origin outage during a viral view spike Cache hits continue if grants remain valid. Misses retry with bounded budgets or use another valid origin replica; they must not cascade through unlimited redirects. Prewarm only selected hot segments and throttle fills to avoid overwhelming a recovering origin. The player may downshift quality when useful, but missing every rendition cannot be fixed by adaptation.
Upload/encoding overload Apply account byte quotas and queue admission before accepting an unbounded processing obligation. Expose queued status and estimated backlog honestly. Prioritize small normal jobs or use fair queues without permanently starving long uploads. Preserve playback resources separately. Comments, search and telemetry may degrade independently, while the core media path continues where its real dependencies permit.

15Operations, security, and cost

Upload and playback quality signals

Operational metrics include completed uploads, abandoned multipart bytes, oldest encoding job, attempts per video, whether every READY manifest names existing, verified segments, first-frame delay, rebuffer ratio, playback errors by device/codec and CDN origin egress. A 200 response for a manifest is not proof of successful playback. Sample synthetic players should fetch and decode real segments from representative regions and devices, while privacy-conscious client telemetry measures real user outcomes.

Codec, rendition and delivery economics

Codec/ladder choices trade storage and compute against delivery bytes. Saving 1 Mb/s for the assumed 2.78 million concurrent viewers reduces network throughput by about 2.78 Tb/s, or 347 GB/s, if perceptual quality remains acceptable. That potential must be balanced against additional encoder-seconds, device compatibility and retained rendition bytes, not guessed cloud prices. Long-tail videos with one or two views may not justify every expensive rendition in advance; an explicitly delayed optional encode can be more economical.

Sandboxing and private grants

Sandbox parsers/decoders, impose CPU, memory, duration and dimension limits, validate actual format rather than filename, and restrict workers' object permissions. Protect private media grants and avoid logging them. Title search, comments and reactions need abuse/rate controls distinct from byte-upload quotas. Retain only necessary location and viewer analytics.

Encoder rollout and failure drills

Test interrupted uploads, expired tokens, W1/W2 publication races, missing required segments, delete during playback, origin failure and codec rollout rollback. Test a new encoder/manifest version by encoding alongside the current version, comparing integrity and quality, then serving a small trial audience before switching publication. Keep prior accepted outputs through a rollback/token-expiry window rather than deleting them when a new job merely starts.

16Decision ledger and limitations

Choice Benefit Cost / limit Change trigger
Encode before READY Predictable compatible playback Upload-to-ready delay Controlled tiny clips may use simpler processing
Multiple aligned renditions Adapts to bandwidth/device variation Encoding and storage multiplier Constrained audience supports fewer outputs
CDN media path Reuses bytes near viewers Misses, grants and purge complexity Very small/private audience may prefer direct origin
Immutable manifest pointer Atomic publication and rollback Old-version lifecycle management Strongly transactional media platform simplifies it
Separate control and byte paths Playback unaffected by upload CPU/bandwidth More operational boundaries Small baseline may combine services

Exact byte deduplication can use hashes as candidate identifiers with collision/integrity handling and retained references. Inline checks may save upload/encoding/storage earlier but add latency and privacy risks. Background deduplication simplifies ingestion while temporarily consuming duplicate resources. Perceptual matching can flag differently encoded clips, borders, overlays or excerpts; block matching and phase correlation are examples of similarity techniques, not proof that outputs are interchangeable or the uploader owns rights. Reusing media must preserve permissions and quality requirements.

The similarity techniques above compare visual structure rather than exact file bytes. Block matching searches for corresponding image patches; phase correlation estimates how far matching image content has shifted between frames. Their role is to find possible matches for further policy checks, not to establish a right to reuse another upload.

For thumbnails, object storage plus CDN may be sufficient; packed small-object storage can reduce per-object operation overhead at scale but adds retrieval/lifecycle complexity. Metadata caches using least-recently-used (LRU) eviction need estimates of distinct hot objects and actual memory overhead, not a percentage of repeated daily views. Cold original retention, higher-resolution variants and global replication are policy choices with visible cost. No cache distribution algorithm alone supplies fault tolerance or balances every viral key.

17Interview closing

“I designed resumable user uploads and on-demand playback, with title search, thumbnails and basic interactions. The uploader's original becomes durable before a recoverable encoding job runs. READY is a guarded pointer to a complete immutable manifest; an obsolete worker cannot publish or overwrite the accepted attempt's objects. The viewer obtains authorization once for a bounded media session, then the player fetches compatible segments through delivery caches and adjusts future quality as bandwidth changes.

“The assumptions produce about 46,000 starts per second and 2.78 million concurrent viewers, so delivery bytes dominate the API path. Segment traffic is much higher than startup QPS. I separate upload, processing, metadata and media-serving resources, accepting encoding/storage cost for smooth compatible playback. Short-lived grants make the revocation limitation explicit.

“My next measurements are first-frame/rebuffer performance by network cohort, origin demand after cache loss, and encoder cost per useful watched minute.”

If the interviewer changes the product to a licensed subscription catalog, add current entitlement and regional/time-window checks before session grants, a DRM/key-service design where required, and rights-aware takedown behavior. The same segment delivery machinery helps, but it does not supply those business authorization guarantees automatically.

Practise the interview questions

Say your answer aloud before opening the model answer. Then answer the follow-up and compare the reasoning.

Foundation · Question 1

Explain adaptive bitrate streaming without product names.

Reveal a model answer

I prepare the same timeline at several qualities and split each into aligned segments. The player reads a manifest and chooses future segments according to network speed and buffer. It can lower quality before playback stalls.

What the answer must demonstrate: Explain segments and the player decision before saying CDN.

Applied · Question 2

An encoder has produced half a video. Can it become ready?

Reveal a model answer

For this on-demand design, only a complete validated minimum rendition set can be published. Output goes to versioned paths, then one metadata pointer selects the complete manifest.

What the answer must demonstrate: The ready contract must identify required outputs.

Applied · Question 3

Why is start-request QPS not enough to size the service?

Reveal a model answer

A playback start creates sustained traffic. At about 46,000 starts per second and 60 seconds watched, we have 2.78 million concurrent viewers. At 5 Mb/s each, network demand is about 13.9 Tb/s.

What the answer must demonstrate: Keep bits, bytes, duration, and concurrency explicit.

Follow-up · Question 4

Two workers encode the same upload after a timeout. What prevents corruption?

Reveal a model answer

They use an identified asset version and isolated attempts, verify outputs, and publish through a conditional job/version update. A late stale worker cannot replace the accepted manifest. Output keys are create-only or the manifest pins object versions, so a duplicate execution cannot mutate already-published bytes.

What the answer must demonstrate: Identify the publication race.

Foundation · Question 5

How would a subscription movie catalog differ from public uploads?

Reveal a model answer

The playback pipeline is similar, but authorization also checks subscription, region, and licensing windows, and may issue DRM licenses. Ingestion is controlled rather than accepting arbitrary user uploads.

What the answer must demonstrate: Do not collapse distinct products into one box diagram.

Follow-up · Question 6

Can we keep only the highest-quality version of visually similar videos?

Reveal a model answer

Visual similarity is not proof that clips are identical or interchangeable. They can differ in edits, audio, ownership, or rights. I would use similarity for review and exact verified identity for safe storage deduplication.

What the answer must demonstrate: Perceptual matching is not an authorization decision.

Applied · Question 7

How do you convert video starts into delivery capacity?

Reveal a model answer

I need watched duration and bitrate. About 46,296 starts per second times sixty watched seconds gives 2.78 million concurrent viewers. At 5 Mb/s, that is about 1.74 TB/s. Four-second segments imply roughly 694,000 segment requests per second before audio/manifest details. Upload-to-view ratio alone does not determine egress.

What the answer must demonstrate: Use units and distinguish starts, segments, concurrency and bytes.

Follow-up · Question 8

A viewer seeks backward, then an earlier playback-progress event arrives late. Should the service persist the maximum playback offset?

Reveal a model answer

No. The larger position may be an old event; maximum offset would undo a deliberate backward seek. I use a playback-session generation and increasing event sequence to order updates, then store the offset from the latest accepted event under that policy. In this design the server allocates the user/video session generation; the latest session controls the shared resume point and older sessions cannot overwrite it.

What the answer must demonstrate: Media progress ordering and maximum viewed position are different product fields.

Blank-page exercise · 45 minutes

Build the answer yourself

Design resumable video upload and adaptive on-demand playback. Define the READY contract, derive encoding and delivery capacity, then recover an encoder that crashes halfway through processing while preserving immutable published media.

  • Define a minimum ready asset and publication boundary.
  • Compute original bytes, derived bytes, concurrency, and egress.
  • Trace resumable upload through CDN playback.
  • Explain a bandwidth drop and an encoder retry.
  • Separate user-upload and licensed-catalog requirements.

Check that each component and design decision follows from your requirements and workload.

Recall the key ideas

Answer from memory before opening each card. Explain why the choice works and what it costs. Revisit missed cards tomorrow.

Design a video streaming serviceWhy keep a manifest?Recall first, then reveal

It maps a playable video version to compatible renditions and their ordered segments.

Manifest is the playback map.

Return to lesson
Design a video streaming serviceWhen may an on-demand video become READY?Recall first, then reveal

After required outputs validate and one publication pointer makes the complete asset visible.

Prepare files; publish pointer.

Return to lesson
Design a video streaming serviceWhat sizes video egress?Recall first, then reveal

Starts per second × watched seconds × average delivered bits per second.

Starts × time × bitrate.

Return to lesson

Final revision

Summary and interview notes

On-demand streaming saves the original, prepares and checks playable outputs, then publishes READY. An authorized player fetches segments through caches and changes quality as its connection changes. Uploads, encoding and analytics do not handle each segment request.

Remember these points

  • A manifest is a playback map, and READY must name a complete required rendition set.
  • Pin the exact original and protect published outputs with create-only keys or explicit versions; attempt names alone are insufficient.
  • The same metadata transaction rules must decide whether an attempt may publish or be reclaimed, so a manifest cannot select objects that cleanup is deleting.
  • Starts multiplied by watched duration gives concurrency; concurrency and delivered bitrate determine egress.
  • Adaptive switching uses compatible segment boundaries and buffer measurements, not arbitrary byte offsets.

Interview tips

  • Show one encoder replacement race and identify who rejects the stale publisher.
  • Estimate startup QPS, segment QPS, encoding slots and edge/origin bytes separately.
  • State minimum playable quality and the media-grant revocation deadline before optimizing publication latency.

Important qualifications

  • Five-minute delivery grants allow that explicit stale-access window; purge alone cannot promise immediate revocation.
  • Session generation defines which device may update shared resume progress; maximum playback offset would undo backward seeks.
  • Managed encoders do not automatically supply the surrounding application publication and authorization guarantees.

Technical references

Practice marks stay in this browser.