High-Level Design Tutorial 0/42 lessons ~6 min read Lesson 38

    Video Streaming Platform

    Design a video streaming platform like YouTube or Netflix — upload, transcode, store, and deliver video globally with adaptive bitrate playback.

    Course progress0%
    Focus
    10 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Design a video streaming platform like YouTube or Netflix — upload, transcode, store, and deliver video globally with adaptive bitrate playback. HLD emphasizes blob storage, CDN egress, encoding pipeline, and metadata catalog separate from bytes.

    Upload bandwidth, transcoding CPU farm, and CDN cost dominate. Assume millions of videos, popular 1% driving 80% views, multiple resolutions (360p–4K).

    Understanding the topic

    Key concepts

    • Upload: multipart to S3 presigned URL; metadata row CREATED.
    • Transcode: worker pulls raw, outputs HLS/DASH segments multiple bitrates.
    • Storage: S3 for objects; CDN caches segments at edge.
    • Playback: client requests manifest (.m3u8) then adaptive segment fetches.
    • Catalog: PostgreSQL/Elasticsearch title search separate from video blobs.
    • DRM optional Widevine for premium content.
    text
    flowchart TB
    Upload --> Transcode
    Transcode --> S3
    CDN --> Player
    Player --> Auth

    Internal architecture

    Architecture overview

    text
    flowchart TB
    Upload --> Transcode
    Transcode --> S3
    CDN --> Player
    Player --> Auth

    Step-by-step explanation

    1. POST /videos/init → presigned S3 URL + videoId.
    2. S3 event → Kafka → Transcode workers (FFmpeg) → output bucket /videoId/{bitrate}/seg.ts.
    3. Catalog service marks READY; invalidate CDN manifest cache.
    4. GET /watch/{id} → auth check → return manifest URL (CDN signed).
    5. Player ABR switches bitrate by bandwidth estimate.
    6. Popular videos pre-warm CDN; cold content origin fetch on first view.

    Informative example

    Initiate upload and transcode job enqueue on S3 complete event:

    java
    @RestController
    @RequestMapping("/api/v1/videos")
    public class VideoController {
    private final VideoService videos;
    public VideoController(VideoService videos) { this.videos = videos; }
    @PostMapping("/init")
    public UploadInitResponse init(@RequestBody UploadInitRequest req, @AuthenticationPrincipal Jwt jwt) {
    return videos.initUpload(jwt.getSubject(), req.title(), req.contentType());
    }
    }
    @Service
    public class VideoService {
    public UploadInitResponse initUpload(String userId, String title, String contentType) {
    String videoId = UUID.randomUUID().toString();
    db.insertPending(videoId, userId, title);
    URL presigned = s3.presignPut("raw/" + videoId, contentType, Duration.ofHours(1));
    return new UploadInitResponse(videoId, presigned.toString());
    }
    @KafkaListener(topics = "s3.upload.completed")
    public void onUploadComplete(UploadEvent event) {
    kafka.send("transcode.jobs", event.videoId(), new TranscodeJob(event.videoId(), List.of("360p","720p","1080p")));
    }
    }

    Transcode is async CPU farm — auto-scale on Kafka lag. CDN serves 95%+ bytes.

    Real-world use

    Real-world use cases

    • OTT subscription Netflix model.
    • User-generated YouTube ad-supported model.
    • Enterprise training video LMS.
    • Live sports low-latency HLS variant.

    Best practices

    • Never serve video through app servers — S3 + CDN only.
    • Chunk upload resume for mobile flaky networks.
    • Store multiple bitrates for ABR.
    • Signed URLs/time-limited cookies for premium.
    • Monitor CDN hit ratio and origin egress cost.
    • Content moderation ML pipeline async on upload complete.

    Common mistakes

    • Single bitrate — poor mobile experience.
    • Transcode synchronous in upload request — timeout.
    • No CDN — origin bandwidth bankruptcy.
    • Metadata and blob tight coupling — search scaling blocked.
    • Ignoring copyright ID scan before publish.

    Advanced interview questions

    Q1BeginnerWhy CDN for video?
    Video files huge; edge caching reduces latency and origin egress cost.
    Q2BeginnerWhat is adaptive bitrate streaming?
    Player switches quality segments based on network speed — HLS/DASH manifests list variants.
    Q3IntermediateUpload vs watch path difference?
    Upload write-heavy to S3 + async transcode; watch read-heavy CDN segment delivery.
    Q4IntermediateTranscode bottleneck handling?
    Kafka job queue, horizontal worker pool auto-scaled on lag, priority queue popular creators optional.
    Q5AdvancedDesign YouTube scale 1B hours/day viewed.
    Multi-region S3, transcoding fleet spot instances, multi-CDN, metadata Cassandra, search ES, view counts Kafka aggregate, cold storage Glacier tier, popular cache proactive.

    Summary

    Video HLD separates upload/transcode pipeline from CDN delivery. S3 object storage + CDN edge serves adaptive HLS/DASH. Async transcode workers scale on queue depth. Catalog metadata in SQL/ES independent of blobs. Signed URLs protect premium streams. Ride booking adds real-time matching similar to food dispatch.

    Ready to mark this lesson complete?Track your journey across the entire course.