Loading...

A 20-minute mock system design interview. You drive the pace. Jump to the board when you are ready; skip capacity math if you want. The interviewer grades your thinking, not a template match.
This question looks like "store files, play files" and is not. It is dominated by bytes, not requests: petabytes a day in, about a terabyte a second out. The signal concentrates in three places: keeping video bytes off your API servers, turning one upload into a playable adaptive stream, and paying for bandwidth without going broke. "Put it in S3 and add a CDN" is where the design starts, not where it ends.
Two shared surfaces (only one is on screen at a time; use the panel arrow to switch):
Build incrementally while you talk. Trace one video end to end through your diagram, from the creator's upload to the first viewer pressing play. Argue the tradeoff, not "industry standard."
Read this before you go in. These are the decisions, and why they matter.
The first drawing most people make sends the upload through the API server and playback back out the same way. At YouTube scale that is about 5 GB/s in and 1 TB/s out through servers built for small JSON requests. Split metadata from bytes.
Upload: the client asks the API for a pre-signed URL (Xu's design; S3 calls it that, Azure calls it a shared access signature), then uploads chunks directly to the Blob Store, in parallel and resumable. The API never holds the file. Grokking's uploadVideo API carries video_contents in the call; say why you would not. Playback: the API returns metadata and a manifest URL; the player pulls segments from the CDN. The API tier never sees a video byte.
One upload in whatever format the phone produced must become many renditions (1080p, 720p, 480p, 360p; H.264, VP9 or newer), thumbnails and a manifest. Doing that inside the upload request makes uploads slow and a single failure loses everything.
The sound default is asynchronous: upload-complete event → Queue → transcoding Workers → transcoded Blob Store → completion Queue → a handler updates metadata and notifies the creator ("ready to watch"). Xu goes further with a DAG: split the original into video, audio and metadata, split video by GOP (independently playable chunks of a few seconds), fan out encodes per resolution plus thumbnails and watermark in parallel, then package. A Scheduler (DAG scheduler and resource manager) matches tasks to workers by priority. Chunk-level encoding means a two-hour video is ready in minutes because dozens of workers share it; a dead worker costs one chunk, not the whole job.
One file per video either stalls on a train or wastes a fibre connection. Each rendition is cut into segments (2–10 s), listed in a manifest (HLS or MPEG-DASH, both plain HTTP). The player picks the rendition for the next segment from measured throughput and buffer level: start low for a fast first frame, step up, step down before the buffer empties. The server stays simple; the intelligence is in the client, and small immutable segments cache perfectly on a CDN. You do not need protocol internals; you need "segmented HLS/DASH, bitrate ladder, player chooses."
Egress is the bill. Xu prices a small service at $150K a day of CDN. Both books agree on the lever: views follow a long tail. Push popular videos (Grokking: the 20% that draw 80% of views) and regionally popular ones to the CDN; serve the tail (1–20 views a day) from origin video servers; encode fewer renditions for unpopular videos, or encode on demand. Netflix takes it to the extreme with Open Connect: its own cache appliances inside ISPs, filled off-peak with what it predicts people will watch. That works because Netflix's catalogue is small and predictable; YouTube's tail is not, so it mixes push for hits with pull-through caching. Either is defensible if you can say why.
Video metadata is small, structured and read-heavy (200 views per upload): Grokking uses MySQL with primary–secondary replication, accepting that a new video appears on replicas a moment late. Shard by UserID and your biggest creator is a hot shard, and title search scatters to every shard. Shard by VideoID and load spreads, but a viral video is hot and "videos by user" scatters. The sound default: VideoID, a cache (Memcached, LRU) in front for hot videos, a secondary table for videos-by-user, and title search in a search index (Elasticsearch), not a scatter-gather.
UPDATE videos SET views = views + 1 per view is a write storm, and a viral video puts it all on one row. Send view events to Kafka, aggregate per video per minute in a Worker, write batched increments, shard a hot video's counter, and show a count that lags by seconds. Billing-grade counts (ads, creator payouts) are reconciled offline after fraud filtering.
One complete design you can study, then rebuild in your own words. Do not recite it. In the interview, draw your graph and defend the choices.
Rough numbers are fine; the method is what gets graded. The win is using them: "requests are ordinary, bytes are enormous, so bytes go to blob storage and the CDN, and cost follows popularity."
How the graph works: two flows. Upload: the client gets a pre-signed URL from the API and sends chunks straight to the Blob Store; an event starts an asynchronous transcoding pipeline whose output lands in a second blob store and, for popular videos, on the CDN; a completion handler flips the video to READY. Playback: the client gets metadata and a manifest URL from the API (served from cache), then pulls segments from the CDN, which falls back to origin for the long tail. View events flow to Kafka and are counted in batches.
Web Client, Mobile Client (creator and viewer)
→ Load Balancer → Service "API" (stateless; mark distributed)
↔ Memcached (hot metadata) ↔ MySQL "Video metadata" (sharded by video_id; mark distributed)
→ Elasticsearch (title search)
→ pre-signed upload URL back to the client
Client → Blob Store "Originals" (chunked, resumable upload)
→ Queue "processing" → Scheduler (DAG) → Worker "Transcoders" (mark distributed)
→ Blob Store "Renditions" (segments, manifests, thumbnails)
→ Queue "completion" → Worker "Completion handler" → MySQL + Memcached (status READY)
Client → CDN (manifest + segments) → Blob Store "Renditions" on a miss (long tail)
Client → Kafka "view events" → Worker "Counter aggregator" → MySQL counters
Components:
v42 in MySQL with status UPLOADING and returns a pre-signed URL and a chunk size.v42 becomes PROCESSING.v42 to READY with its manifest URL, refreshes Memcached, and notifies Priya.A transcoder dies mid-encode: the chunk's task never completes, the scheduler reassigns it, and the preprocessor's cached GOPs mean no re-download. Jobs are keyed by video_id and rendition, so a duplicate event does not produce duplicate work or a second "ready" notification.
The video goes viral: the CDN absorbs the bytes; Memcached absorbs the metadata reads; the view counter is sharded and batched from Kafka so one row is not hammered.
Rahul resumes on his TV: the API reads his saved offset; the TV requests the manifest for its own codec and resolution (Grokking's offset, codec, resolution) and starts at the segment for 6 min 10 s.
Video(video_id, uploader_id, title, description, status [UPLOADING|PROCESSING|READY|REMOVED], duration_s, manifest_url, created_at)
VideoCounters(video_id, shard, views, likes) — batched from the view-event stream
VideosByUser(uploader_id, created_at, video_id) — secondary table for "videos by user"
Comment(comment_id, video_id, user_id, text, created_at)
User(user_id, name, email, ...)
UploadSession(video_id, chunk_size, chunks_received) — for resumable uploads
WatchProgress(user_id, video_id) → offset_s, device — key-value
Blob Store: originals/{video_id}, renditions/{video_id}/{height}p/seg_{n}, manifest, thumbnails
Video, VideoCounters and Comment by video_id (consistent hashing); VideosByUser by uploader_idUploading through an upload service that streams to blob storage (as long as it is not the general API tier). One transcoding job per rendition instead of a full DAG. Cassandra or DynamoDB for metadata with a search index beside it. Sharding by UserID with consistent hashing and a cache for hot creators. A commercial CDN only, or Netflix-style appliances in ISPs. What matters is that you can argue the tradeoff.