Katkat

Design a Video Sharing Platform

TeslaSoftware Engineer · Onsite

Last updated

Design a resilient, large-scale video sharing and streaming platform that handles multi-gigabyte uploads, asynchronous transcoding, and low-latency global delivery. This question tests your ability to design chunked upload protocols, idempotent processing pipelines, and CDN-backed adaptive streaming architectures.

Scenario

Design the core architecture for an enterprise-grade video sharing platform capable of handling user-generated video uploads, asynchronous processing, and smooth global playback across diverse client devices and network conditions.

Requirements

Functional Requirements

  1. Resumable Uploads: Users can upload large video files (up to 10 GB) with support for pause, resume, and automatic recovery on network failure.
  2. Idempotent Transcoding Pipeline: The system must transcode uploaded raw video into multiple bitrates and resolutions (HLS/DASH formats: 1080p, 720p, 480p, 360p) with guaranteed deduplication and idempotency in case of worker retries.
  3. Content Moderation & Hooks: Automatically route video frames and audio tracks to moderation pipelines (e.g., safety classification, copyright scanning) before making the video publicly accessible.
  4. Adaptive Bitrate Streaming (ABR): Deliver optimized video segments to end users based on available client bandwidth.
  5. Access Control: Support public, unlisted, and private/time-limited access tokens for video playback.

Non-Functional Requirements

  • Scale: 50,000 video uploads per day (~100 TB raw ingest/day); 10 million daily active viewers streaming an aggregate of 50 million video hours daily.
  • Availability: 99.99% availability for playback; 99.9% for upload ingest.
  • Low Playback Latency: Time to First Frame (TTFF) should be under 1.5 seconds globally.
  • Durability: Uploaded source media and processed segments must have 99.999999999% (11 9s) durability.

What to Cover

  1. Upload Protocol & Storage Architecture: Describe the chunked, resumable upload flow (e.g., tus protocol or S3 multipart upload) and state tracking.
  2. Transcoding & Workflow Engine: Detail the task queue, worker scheduling, video chunk splitting, and how idempotency is guaranteed across worker failures.
  3. Data Model: Schema for video metadata, upload sessions, transcode jobs, and access policies.
  4. Delivery & CDN Strategy: Edge caching strategies for manifests (.m3u8 / .mpd) versus video segments (.ts / .m4s), cache invalidation, and signed URLs/cookies for access control.
  5. Moderation Integration: How moderation fits into the state machine without blocking non-violating processing paths.

Hints

Hint 1

Separate metadata state tracking from the actual binary payload transfer by using pre-signed upload URLs and direct object-storage uploads.

Hint 2

For idempotent transcoding, partition long videos into short time-slice chunks, use content-hash keys for each chunk's transcode output, and track job state using a distributed state machine or orchestrator with CAS (compare-and-swap) operations.

Hint 3

Treat manifest files and media segment chunks differently in your CDN caching tier: manifests change during live/processing workflows and need short TTLs, whereas media segments are immutable and should have long TTLs.

Follow-up questions

  • How would you handle a scenario where a user replaces or updates an existing video without changing its URL, ensuring CDN edge caches do not serve stale segments?
  • If a transcoding worker crashes when it is 90% done with a 2-hour video, how does your architecture avoid repeating the full transcode from scratch?
  • How would you implement thumbnail generation and dynamic video preview scrubs efficiently without reading entire multi-gigabyte source files?