DowngradedOur downstream service providers are currently experiencing outages, and our engineering team is actively working on a resolution. Some services—including the Solver, Partner, and Tools—are temporarily degraded with higher latency and lower bandwidth. Rest assured, Intervipedia, Solutions, and the Question Bank features are not impacted and remain fully operational.DowngradedOur downstream service providers are currently experiencing outages, and our engineering team is actively working on a resolution. Some services—including the Solver, Partner, and Tools—are temporarily degraded with higher latency and lower bandwidth. Rest assured, Intervipedia, Solutions, and the Question Bank features are not impacted and remain fully operational.DowngradedOur downstream service providers are currently experiencing outages, and our engineering team is actively working on a resolution. Some services—including the Solver, Partner, and Tools—are temporarily degraded with higher latency and lower bandwidth. Rest assured, Intervipedia, Solutions, and the Question Bank features are not impacted and remain fully operational.DowngradedOur downstream service providers are currently experiencing outages, and our engineering team is actively working on a resolution. Some services—including the Solver, Partner, and Tools—are temporarily degraded with higher latency and lower bandwidth. Rest assured, Intervipedia, Solutions, and the Question Bank features are not impacted and remain fully operational.
DowngradedOur downstream service providers are currently experiencing outages, and our engineering team is actively working on a resolution. Some services—including the Solver, Partner, and Tools—are temporarily degraded with higher latency and lower bandwidth. Rest assured, Intervipedia, Solutions, and the Question Bank features are not impacted and remain fully operational.DowngradedOur downstream service providers are currently experiencing outages, and our engineering team is actively working on a resolution. Some services—including the Solver, Partner, and Tools—are temporarily degraded with higher latency and lower bandwidth. Rest assured, Intervipedia, Solutions, and the Question Bank features are not impacted and remain fully operational.DowngradedOur downstream service providers are currently experiencing outages, and our engineering team is actively working on a resolution. Some services—including the Solver, Partner, and Tools—are temporarily degraded with higher latency and lower bandwidth. Rest assured, Intervipedia, Solutions, and the Question Bank features are not impacted and remain fully operational.DowngradedOur downstream service providers are currently experiencing outages, and our engineering team is actively working on a resolution. Some services—including the Solver, Partner, and Tools—are temporarily degraded with higher latency and lower bandwidth. Rest assured, Intervipedia, Solutions, and the Question Bank features are not impacted and remain fully operational.
The Question
Design

Scalable Video Sharing and Streaming Platform

Design a global video platform similar to YouTube. The system must support high-volume video uploads (500 hrs/min), asynchronous multi-resolution transcoding, and low-latency global playback via Adaptive Bitrate Streaming (ABR). Discuss how you would handle massive storage requirements, optimize for diverse network conditions, and ensure high availability for metadata and video assets. Address the trade-offs between consistency and latency for features like view counts.
S3
Kafka
FFmpeg
HLS
DASH
CDN
Redis
PostgreSQL
Vitess
Kubernetes
gRPC
Questions & Insights

Clarifying Questions

What is the scale of the system? We assume 2 billion monthly active users (MAU), 500 hours of video uploaded every minute, and 5 billion video views per day.
What are the primary features for the MVP? We focus on video uploading, transcoding (multi-resolution support), video streaming (playback), and basic metadata search/retrieval.
What are the constraints on video latency and quality? We prioritize "low startup latency" for playback and "high durability" for uploads. Support for Adaptive Bitrate Streaming (ABR) is required.
Is this a global service? Yes, the system must serve users globally with minimal buffering, requiring a heavy reliance on Geo-distributed Content Delivery Networks (CDNs).
What is the average video size and format? We assume an average video size of 500MB (raw) and support for standard formats (MP4, MOV) to be converted into HLS/DASH.

Thinking Process

Core Bottleneck 1: Massive Ingress & Storage. How do we handle 500 hours of video every minute?
Solution: Resumable chunked uploads to Object Storage and an asynchronous transcoding pipeline.
Core Bottleneck 2: Global Playback Latency. How do we prevent buffering for a user in Tokyo watching a video uploaded in New York?
Solution: Heavy use of Edge CDNs and Adaptive Bitrate Streaming (HLS/DASH) to match user bandwidth.
Core Bottleneck 3: Metadata Scalability. How do we handle billions of rows of video metadata and view counts?
Solution: Sharded Relational Database for consistency of metadata and a specialized NoSQL or Distributed Counter for view counts.

Bonus Points

VPU (Video Processing Unit) Optimization: Discussion on using specialized hardware (ASICs) for transcoding to reduce cost and latency compared to general-purpose CPUs.
Edge Side Steering: Implementing a smart CDN selector (Multi-CDN strategy) that routes users based on real-time ISP performance data.
Quic/HTTP3 Adoption: Utilizing UDP-based protocols for video ingestion to reduce head-of-line blocking and improve upload speeds in lossy network conditions.
Cost-Optimized Tiered Storage: Moving older, "cold" videos from high-performance SSD-backed object stores to "Cold/Archive" storage (e.g., S3 Glacier) to optimize COGS.
Design Breakdown

Functional Requirements

Core Use Cases:
Users can upload videos.
Users can watch videos in various resolutions (360p, 720p, 1080p).
Users can search for videos by title.
View counts are tracked and displayed.
Scope Control:
In-scope: Upload, Transcoding, Streaming, Metadata management, Search.
Out-of-scope: Recommendations engine (AI/ML), Comments/Likes social graph, Subscriptions, Monetization/Ads.

Non-Functional Requirements

Scale: Support for 100M+ Daily Active Users (DAU).
Latency: Video playback start time < 200ms (at the edge).
Availability & Reliability: 99.99% availability; zero data loss for uploaded original videos.
Consistency: Eventual consistency for view counts; Strong consistency for video metadata (titles/descriptions).
Fault Tolerance: Automatic retry on transcoding failure; multi-region replication of metadata.

Estimation

Traffic Estimation:
Uploads: 500 hours/min * 60 min = 30,000 hours/day.
Views: 5 billion views/day \approx 60,000 QPS.
Peak QPS: ~120,000 QPS.
Storage Estimation:
30,000 hours/day * 1GB/hour (average compressed) = 30 TB/day.
5 years storage: 30 TB 365 5 \approx 55 PB.
Bandwidth Estimation:
Outgoing: 5B views * 500MB avg video \approx 2.5 Exabytes/day.
This necessitates a massive CDN footprint.

Blueprint

Concise Summary: A microservices-based architecture centered around an asynchronous video processing pipeline. It separates the write-heavy upload path from the read-heavy streaming path via Object Storage and CDNs.
Major Components:
Upload Service: Handles multipart resumable uploads and persists raw chunks to temporary storage.
Transcoding Engine: An asynchronous worker fleet that converts raw videos into multiple resolutions and manifests (HLS/DASH).
Metadata Service: Manages video info (title, tags) using a sharded SQL database.
Content Delivery Network (CDN): Geographically distributed edge servers that cache and serve video segments to end-users.
Simplicity Audit: This design avoids complex ML-based recommendation engines and real-time social features to focus strictly on the core video delivery lifecycle.
Architecture Decision Rationale:
Why this architecture?: Segregating processing from ingestion ensures that slow transcoding doesn't block the user's upload experience.
Functional Satisfaction: Meets all core flows from upload to playback.
Non-functional Satisfaction: Scalable via horizontal service scaling; Low latency via CDN; High durability via Object Storage replication.

High Level Architecture

Sub-system Deep Dive

Edge (Optional)

Content Delivery & Traffic Routing:
CDN: Uses a primary and secondary CDN (e.g., Cloudflare, Akamai) for global distribution. Static manifests and video segments (.ts or .m4s files) are cached at the edge.
DNS: Latency-based routing directs users to the nearest Edge POP.
Security & Perimeter:
API Gateway: Handles JWT-based authentication, rate limiting (100 uploads/day per user), and SSL termination.

Service

Topology & Scaling:
Stateless Services: All services (Upload, Metadata) are deployed in Kubernetes across multiple Availability Zones.
Scaling: Upload service scales on Connection Count; Transcoding workers scale based on Queue Depth.
API Schema Design:
POST /v1/uploads: Initiates a session. Returns upload_id.
PUT /v1/uploads/:id: Uploads a specific byte-range chunk.
GET /v1/videos/:id: Returns metadata and the HLS master playlist URL.
Resilience & Reliability:
Transcoding Retries: Exponential backoff for worker failures. If a specific video codec fails, it is moved to a Dead Letter Queue (DLQ).

Storage

Access Pattern:
High-volume sequential writes (Uploads).
High-volume random reads (Metadata).
Database Table Design:
Videos Table: video_id (PK), user_id, title, description, s3_url, status (processing/ready), created_at.
Video_Variants Table: variant_id, video_id (FK), resolution, bitrate, codec.
Technical Selection:
Metadata: PostgreSQL with Vitess for sharding. Chosen for ACID compliance on user video data.
Blobs: Amazon S3 or Google Cloud Storage. Chosen for 99.999999999% durability.
Distribution Logic: Shard metadata by video_id to ensure uniform distribution.

Cache

Purpose & Justification: Reduces Metadata DB load for "viral" videos.
Key-Value Schema:
Key: vid:{video_id}, Value: JSON-serialized metadata.
TTL: 1 hour for standard, dynamic for trending videos.
Technical Selection: Redis. Used for its high throughput and support for data structures like Sorted Sets (useful for trending lists).

Messaging

Purpose & Decoupling: Decouples the upload completion from the intensive transcoding process.
Event Schema: video_id, raw_s3_path, user_id, timestamp.
Technical Selection: Kafka. Chosen for its high throughput and ability to replay events if the Transcoding fleet needs to re-process a batch of videos.

Data Processing

Processing Model: Asynchronous Batch-oriented per video.
Processing DAG:
Pull from S3.
Split into 5-second chunks.
Transcode chunks in parallel (360p, 720p, 1080p).
Assemble segments and generate .m3u8 manifest.
Update Metadata DB to "Ready".
Technical Selection: Custom worker fleet using FFmpeg. FFmpeg is the industry standard for video manipulation.

Infrastructure (Optional)

Observability:
Prometheus for QPS and Error rates.
Jaeger for tracing a video's journey from upload to "Ready" status.
Distributed Coordination:
Zookeeper (via Kafka) for managing consumer group offsets in the transcoding pipeline.
Wrap Up

Advanced Topics

Trade-offs: We choose Availability over Consistency (AP) for view counts. It is acceptable if a user sees 1.1M views while another sees 1.11M.
Reliability: We use Multipart Uploads. If a 1GB upload fails at 900MB, the client only retries the last 10MB chunk.
Bottleneck Analysis:
Hot Shards: Viral videos create "hot" metadata rows. Mitigation: aggressive caching in Redis and CDN.
Transcoding Lag: Sudden spikes in uploads can lag the pipeline. Mitigation: Auto-scaling workers and priority queues (e.g., shorter videos transcode first).
Security: Videos are stored with Private ACLs in S3. The CDN uses Signed URLs/Cookies to ensure only authorized users can stream specific content.
Distinguishing Insights: For the MVP, we utilize VBR (Variable Bitrate) encoding to save storage while maintaining quality during low-motion scenes, significantly reducing S3 costs at scale.