TOUGH TONGUE AI
  • Home
    LogoTOUGH TONGUE AI

    RESOURCES

    Loading...

    HomeLibrarySD Mock · Design YouTube / Netflix

    SD Mock · Design YouTube / Netflix

    SD Mock · Design YouTube / Netflix

    Overview

    Design a video platform like YouTube or Netflix on a live architecture board: drag components, wire them up, and defend your design to an expert interviewer who watches every move.

    Your Instructions

    Design YouTube / Netflix

    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):

    • Notepad. Shared notes. Requirements, capacity math, schema, and end-of-session feedback live here. You can type in it too.
    • Architecture board. Your design canvas. Drag typed components, wire them, label edges, mark scaled tiers as distributed. If it is not on the board, it is not in your design.

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

    Design choices interviewers probe

    Read this before you go in. These are the decisions, and why they matter.

    Where the bytes go

    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.

    The transcoding pipeline

    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.

    Adaptive bitrate streaming

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

    The CDN and the long tail

    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.

    Metadata: store, shard, cache

    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.

    Counting views at 46K per second

    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.

    Reference solution

    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.

    Requirements (lock these or take the defaults)

    • Upload a video (up to 1 GB, resumable), with title, description and tags; get notified when it is ready
    • Watch smoothly on phone, web and smart TV, with quality adapting to the network; resume on another device from the same point
    • Search by title; show views and likes; comments
    • Non-functional: never lose an upload; highly available with eventual consistency (a new video showing up seconds late is fine); no lag during playback; low infrastructure cost; international users
    • Out of scope unless asked: recommendations, live streaming, channels and subscriptions

    Capacity

    • Views: 800M DAU × 5 videos ÷ 86,400 s ≈ 46K views/s (Grokking); uploads at 1:200 ≈ 230 videos/s
    • Storage: 500 hours/min × 60 × 50 MB (all formats) = 1.5 TB per minute ≈ 25 GB/s ≈ 2.2 PB/day, before replication
    • Bandwidth: 500 hours/min × 60 × 10 MB = 300 GB/min ≈ 5 GB/s in; × 200 ≈ 1 TB/s out
    • Cross-check: 230 uploads/s ≈ 13,900 videos/min against 30,000 minutes of video/min → ~2.2-minute average video; 4B views/day × 2.2 min × 10 MB ≈ 1 TB/s. The book's numbers agree with each other.
    • Xu's alternative: 5M DAU, 10% upload a 300 MB video daily → 150 TB/day; CDN 5M × 5 × 0.3 GB × $0.02 = $150K/day. That assumes every view streams the whole file; Xu's own 30 minutes/day of watching gives about $30K/day.

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

    Components to put on the board

    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:

    • Web Client, Mobile Client. Creators split files into chunks and upload directly; viewers run the adaptive player that chooses bitrate per segment.
    • Load Balancer + API Service. Stateless: auth, metadata, pre-signed URLs, search, resume positions. Never carries video bytes. Scales horizontally.
    • Blob Store (Originals). Durable home of every upload. "Never lose an upload" lives here: once the last chunk is acknowledged, the video is safe even if every transcoder is down.
    • Queue (processing) + Scheduler + Worker (Transcoders). The asynchronous pipeline. The queue absorbs bursts and makes retries possible; the scheduler builds the DAG and hands tasks to free workers; workers encode GOP chunks in parallel.
    • Blob Store (Renditions). Segments, manifests and thumbnails for every rendition; the origin behind the CDN.
    • Queue (completion) + Worker (Completion handler). Turns "encoding finished" into metadata updates, cache refresh and the creator's notification, decoupled from the encoders.
    • MySQL (Video metadata) + Memcached. Sharded by video_id with primary–secondary replicas; hot rows cached with LRU. Brief replica lag is acceptable.
    • Elasticsearch. Title and tag search, so search never scatters across metadata shards.
    • CDN. Serves manifests, segments and thumbnails for popular and regionally popular videos. Misses fall back to origin.
    • Kafka + Worker (Counter aggregator). View and like events, aggregated and written in batches so viral videos do not hammer one row.

    Walk one video: Priya uploads a 10-minute recipe; Rahul in Mumbai plays it on a train

    1. Priya's Mobile Client calls the API with the title and file size; the API creates video v42 in MySQL with status UPLOADING and returns a pre-signed URL and a chunk size.
    2. The app uploads GOP-aligned chunks in parallel straight to the Blob Store (Originals). Signal drops at chunk 37; on reconnect it resumes at chunk 37.
    3. The last chunk lands; the storage event goes onto the processing Queue and v42 becomes PROCESSING.
    4. The Scheduler builds the DAG (inspect, split video/audio/metadata, encode 1080p/720p/480p/360p, thumbnails, package HLS/DASH). Transcoder Workers take chunks in parallel; a failed chunk is retried on another worker.
    5. Renditions and the manifest land in the Blob Store (Renditions). A completion event goes onto the completion Queue; the handler sets v42 to READY with its manifest URL, refreshes Memcached, and notifies Priya.
    6. Rahul taps the video. The API returns metadata from Memcached, including the manifest URL on the CDN.
    7. The player fetches the manifest and a low-bitrate first segment from the nearest CDN edge (a miss, so the edge pulls from origin and keeps a copy), steps up to 720p, then down to 360p in a tunnel instead of stalling. View and progress events go to Kafka.

    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.

    Schema

    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
    
    • Shard Video, VideoCounters and Comment by video_id (consistent hashing); VideosByUser by uploader_id
    • MySQL primary–secondary per shard; reads from replicas; promote a secondary if the primary dies
    • Hot videos cached in Memcached (LRU; roughly the 20% of videos that draw 80% of reads)

    Scaling and wrap-up

    • API and transcoders scale horizontally; MySQL by shard; the CDN carries the bytes
    • The CDN absorbs egress; Memcached absorbs metadata reads; the processing queue absorbs upload bursts
    • First metrics: time to first frame and rebuffering ratio, CDN hit ratio by region, upload-to-READY time at p99 and queue age
    • If time: live streaming (low-latency protocol, no slow retries), dedup (byte-level inline vs perceptual fingerprinting for copyright, async), takedowns (unpublish at once, purge CDN async), DRM and watermarking, thumbnails (tiny, hot: Grokking puts them in Bigtable)

    Equally defensible variants

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

    More in System Design Interview Prep: AI Coach Edition

    • SD Coach · Batch and Stream Pipelines
    • SD Coach · Real-Time Chat and Collaboration
    • SD Mock · Design Facebook Messenger
    • SD Mock · Design Uber Backend
    • SD Mock · Design Yelp / Nearby Friends
    • SD Coach · Media Streaming
    • SD Mock · Design Instagram
    • SD Coach · Agentic AI
    • SD Coach · Agentic AI Architectures (Slides)
    • SD Mock · Design ChatGPT
    • SD Mock · Design Claude Code
    • SD Mock · Design an AI Customer Support System
    View the full course (43 sessions) →