Bird
Raised Fist0
HLDsystem_design~25 mins

Transcoding and adaptive bitrate in HLD - System Design Exercise

Choose your learning style9 modes available
Design: Video Streaming with Transcoding and Adaptive Bitrate
Design covers video ingestion, transcoding, storage, and adaptive bitrate delivery. Out of scope: DRM, user authentication, content recommendation.
Functional Requirements
FR1: Ingest live or on-demand video content from users or content providers
FR2: Transcode videos into multiple quality levels (bitrates and resolutions)
FR3: Store transcoded videos for on-demand playback
FR4: Deliver video streams to users with adaptive bitrate streaming based on their network conditions
FR5: Support at least 100,000 concurrent viewers
FR6: Ensure video startup latency under 3 seconds
FR7: Provide 99.9% availability for streaming service
Non-Functional Requirements
NFR1: Handle peak traffic of 100,000 concurrent viewers
NFR2: Latency for live streaming end-to-end should be under 10 seconds
NFR3: Storage must support petabytes of video data
NFR4: System should be scalable horizontally
NFR5: Use industry standard streaming protocols (HLS, DASH)
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
❓ Question 6
❓ Question 7
Key Components
Video ingestion service
Transcoding cluster
Storage system for original and transcoded videos
Content Delivery Network (CDN)
Streaming server or origin server
Client player with adaptive bitrate logic
Monitoring and alerting system
Design Patterns
Microservices architecture for modular components
Message queues for transcoding job management
Cache and CDN for low latency delivery
Adaptive bitrate streaming protocols (HLS, DASH)
Horizontal scaling of transcoding workers
Health checks and retries for fault tolerance
Reference Architecture
  +----------------+       +-------------------+       +----------------+
  | Video Ingestion| ----> | Transcoding Queue | ----> | Transcoding    |
  | Service       |       | (Message Queue)    |       | Workers        |
  +----------------+       +-------------------+       +----------------+
          |                                                        |
          v                                                        v
  +----------------+                                      +----------------+
  | Original Video |                                      | Transcoded     |
  | Storage        |                                      | Video Storage  |
  +----------------+                                      +----------------+
          |                                                        |
          v                                                        v
  +---------------------------------------------------------------+
  |                      Streaming Origin Server                  |
  +---------------------------------------------------------------+
                                  |
                                  v
                          +----------------+
                          | CDN (Edge Nodes)|
                          +----------------+
                                  |
                                  v
                          +----------------+
                          | Client Player  |
                          | (Adaptive Bitrate Logic) |
                          +----------------+
Components
Video Ingestion Service
HTTP/RTMP servers
Receive live or on-demand video uploads from content providers
Transcoding Queue
Message Queue (e.g., Kafka, RabbitMQ)
Manage and distribute transcoding jobs to workers asynchronously
Transcoding Workers
FFmpeg or cloud transcoding services
Convert original videos into multiple bitrates and resolutions
Original Video Storage
Object Storage (e.g., Amazon S3, MinIO)
Store raw uploaded videos reliably
Transcoded Video Storage
Object Storage with CDN integration
Store multiple quality versions of videos for streaming
Streaming Origin Server
HTTP server supporting HLS/DASH
Serve video manifests and segments to CDN
Content Delivery Network (CDN)
Commercial CDN or self-hosted edge caches
Deliver video content with low latency and high availability
Client Player
HTML5 video player with adaptive bitrate logic
Select appropriate video quality based on network conditions
Request Flow
1. 1. Content provider uploads video to Video Ingestion Service.
2. 2. Video Ingestion Service stores original video in Original Video Storage.
3. 3. Video Ingestion Service sends transcoding job message to Transcoding Queue.
4. 4. Transcoding Workers consume jobs, transcode video into multiple bitrates/resolutions.
5. 5. Transcoded videos are stored in Transcoded Video Storage.
6. 6. Streaming Origin Server generates manifests (HLS/DASH) referencing transcoded segments.
7. 7. CDN caches video manifests and segments from Streaming Origin Server.
8. 8. Client Player requests video manifest from CDN and starts playback.
9. 9. Client Player monitors network conditions and switches between bitrates adaptively.
Database Schema
Entities: - Video: id (PK), title, description, upload_time, uploader_id - TranscodingJob: id (PK), video_id (FK), status, created_at, completed_at - VideoSegment: id (PK), video_id (FK), bitrate, resolution, segment_url Relationships: - One Video has many TranscodingJobs - One Video has many VideoSegments representing different qualities
Scaling Discussion
Bottlenecks
Transcoding workers overwhelmed by high upload volume
Storage I/O bottleneck due to large video files
Streaming origin server unable to handle many manifest requests
CDN edge nodes overloaded during traffic spikes
Client network variability causing poor playback experience
Solutions
Scale transcoding workers horizontally; use autoscaling based on queue length
Use distributed object storage with high throughput and parallel access
Deploy multiple streaming origin servers behind load balancers
Leverage global commercial CDN with auto-scaling edge capacity
Implement robust adaptive bitrate algorithms and buffer management on client
Interview Tips
Time: Spend 10 minutes clarifying requirements and constraints, 20 minutes designing architecture and data flow, 10 minutes discussing scaling and trade-offs, 5 minutes summarizing.
Explain how transcoding enables multiple quality levels for diverse devices and networks
Describe asynchronous job processing for scalability and fault tolerance
Highlight use of CDN to reduce latency and improve availability
Discuss adaptive bitrate streaming benefits and client logic
Address scaling challenges and solutions realistically
Mention monitoring and failure handling strategies