Bird
Raised Fist0

CDN for Video Streaming - Adaptive Bitrate and HLS Segment Delivery

HLDmediumInterview freq: common
Choose your preparation mode4 modes available
🏗️
CDN for Video Streaming - Adaptive Bitrate and HLS Segment Delivery
Design a scalable CDN to deliver adaptive bitrate HLS video streams with low latency and high availability
mediumContent Delivery NetworkFreq: common
Prerequisites:DNSHTTP
⚙️
Functional Requirements
  • Serve HLS video segments with adaptive bitrate switching based on client bandwidth and device capabilities
  • Support live and on-demand video streaming with low startup latency (<3 seconds)
  • Cache and deliver video segments globally via edge CDN nodes to reduce origin load
  • Provide manifest (m3u8) file delivery that lists available bitrates and segment URLs
  • Handle seamless bitrate switching mid-stream without playback interruption
  • Support HTTP/HTTPS delivery with range requests for partial segment fetching
📊
Non-Functional Requirements
  • Support 2 billion daily active users globally
  • 99.99% availability for video segment delivery
  • P99 latency for segment delivery under 100ms at edge nodes
  • Handle peak write QPS of 1 million segment uploads per second from origin
  • Scale to deliver 10+ Tbps outbound bandwidth during peak hours
❓
Clarifying Questions to Ask
  • What is the expected average video segment size and duration?
  • Are we supporting live streaming, on-demand, or both?
  • What is the expected peak concurrency per region or edge node?
  • How frequently do manifests update and how are they cached?
  • What is the origin infrastructure for video segment storage?
  • Are there any specific CDN providers or technologies mandated?
Out of Scope
✗ Video encoding and transcoding pipeline
✗ Client-side player implementation and UI
✗ DRM and content protection mechanisms
✗ Analytics and user behavior tracking
📌
Assumptions
  • 2 billion DAU globally
  • Average 40 video segments requested per user per day
  • Average segment size 2 MB
  • Peak traffic concentrated in 4 hours daily (peak factor 4)
⚡
QPS Calculation
write qps2B users × 40 segments/day ÷ 86400 sec ≈ 925,926 writes/sec
peak write qps925,926 × 4 (peak factor) ≈ 3.7 million writes/sec
read qps2B users × 40 segments/day ÷ 3600 sec (peak 1hr) ≈ 22.2 million reads/sec
💾
Storage Estimate
daily storage gb2B × 40 × 2MB = 160,000,000,000 MB = 160,000 TB = 160 PB/day
retention days7
total storage with replication160 PB × 7 days × 2 (replication) = 2,240 PB
🖥️
Server Estimate
origin storage nodesAssuming 1 node handles 600 Mbps write bandwidth, need ~59 nodes for writes
edge cache nodesAssuming 10 Gbps outbound per edge node, need ~35,520 edge nodes globally (to handle 355 Tbps outbound)
🏗️
Architecture Diagram
Architecture Diagram
          +----------------+
          |   DNS Layer    |
          +-------+--------+
                  |
          +-------v--------+
          | Edge CDN Node  |
          +-------+--------+
                  |
          +-------v--------+
          | Origin Storage |
          +-------+--------+
                  |
          +-------v--------+
          |Transcoding Svc|
          +----------------+
🧩
Components
DNS Layer
Route client requests to nearest edge CDN node based on geo-location
Why thisRoute53 supports geo-DNS routing with low latency and high availability globally
Why notUsing static IPs or anycast alone lacks fine-grained geo routing and load balancing
Edge CDN Node (e.g. CloudFront, Akamai)
Cache and serve HLS manifests and video segments close to users to reduce latency
Why thisCloudFront supports HTTP/HTTPS, range requests, and cache invalidation with global PoPs
Why notGeneric HTTP caches like Squid lack global distribution and adaptive bitrate support
Origin Storage (e.g. Amazon S3, Google Cloud Storage)
Store master copies of video segments and manifests with high durability and scalability
Why thisS3 offers 99.999999999% durability and scales to trillions of objects with lifecycle policies
Why notTraditional block storage or databases do not scale to petabytes with high read throughput
Transcoding Service (e.g. AWS Elemental MediaConvert)
Generate multiple bitrate variants and HLS segments from source video files
Why thisMediaConvert supports adaptive bitrate output and integrates with storage and CDN
Why notSelf-managed FFmpeg clusters require complex scaling and monitoring at this scale
Manifest Generation Service
Create and update m3u8 playlists listing available bitrates and segment URLs
Why thisCustom microservice enables dynamic manifest updates and cache control for adaptive streaming
Why notStatic manifests cannot support live streaming or dynamic bitrate adaptation
Load Balancer (e.g. ELB, NGINX)
Distribute incoming requests among edge nodes and origin servers to balance load
Why thisELB provides auto-scaling and health checks with low latency routing
Why notDNS round robin lacks health checks and fine-grained load balancing
🔄
Data Flow
1
Client → DNS Layer
Client resolves video domain to nearest edge CDN IP
Geo-DNS routes to closest edge node to minimize latency
2
Client → Edge CDN Node
Client requests HLS manifest (m3u8) or video segment
Edge serves cached content if available, else fetches from origin
3
Edge CDN Node → Origin Storage
Fetch missing segments or manifests from origin storage
Origin serves master copies; edge caches for subsequent requests
4
Origin Storage → Transcoding Service
Transcoding service generates adaptive bitrate segments on upload
Segments stored back in origin storage for CDN distribution
5
Manifest Generation Service → Origin Storage
Update manifests with new segment URLs and bitrate variants
Manifests cached at edge for client adaptive bitrate switching
6
Client → Edge CDN Node
Client switches bitrate by requesting different segment URLs from manifest
Adaptive bitrate switching handled seamlessly by client player

Practice

(1/5)
1. A global CDN operator needs to prevent a misconfiguration from propagating incorrect BGP routes that could cause widespread internet outages. Which component is primarily responsible for detecting and containing such route leaks?
easy
A. Using a centralized DNS firewall to block suspicious IP prefixes
B. Implementing BGP route filters and prefix limits on edge routers
C. Relying on client-side validation of IP addresses before routing
D. Deploying a distributed cache to store valid routing tables

Solution

  1. Step 1: Identify BGP route filtering role

    BGP route filters and prefix limits on edge routers prevent invalid or excessive route announcements, containing route leaks.
  2. Step 2: Eliminate other options

    DNS firewalls (A) do not control BGP routing; client-side validation (C) is ineffective for routing control; distributed caches (D) do not enforce routing policies.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    BGP route filters contain route leaks at the network edge [check]
Hint: Edge routers enforce BGP filters to block bad routes [check]
Common Mistakes:
2. In the booking flow, at step 4 the Availability Service checks the calendar cache before confirming a booking. What happens if the cache entry for the requested dates is stale or missing at this step?
easy
A. The service immediately rejects the booking request without fallback
B. The service queries the persistent calendar database synchronously to verify availability
C. The service assumes availability and proceeds to reserve the booking optimistically
D. The service delays the booking confirmation until a cache refresh completes asynchronously

Solution

  1. Step 1: Trace Availability Service behavior at step 4

    The service uses cache for fast reads but must ensure correctness before booking confirmation.
  2. Step 2: Handle stale or missing cache entries

    Rejecting immediately (A) reduces UX; optimistic booking (C) risks double bookings; async delay (D) hurts latency. Synchronous DB query (B) ensures correctness.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Fallback to DB ensures accurate availability check on cache miss [check]
Hint: Cache miss triggers synchronous DB check for correctness [check]
Common Mistakes:
3. In a graph database request flow, at step 4 the query engine evaluates the traversal depth limit. What happens if the depth limit is reached before finding the target node?
easy
A. The traversal stops immediately and returns partial results up to that depth
B. The query engine throws an error and aborts the entire query
C. The query engine restarts traversal from the root node with a higher limit
D. The query engine continues traversing all remaining edges ignoring the limit

Solution

  1. Step 1: Understand traversal depth limit role

    The depth limit caps how far the traversal explores to avoid excessive computation.
  2. Step 2: Behavior at limit

    When the limit is reached, traversal stops and returns partial results found so far, not an error or restart.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Traversal depth limit stops traversal and returns partial results [check]
Hint: Traversal stops at depth limit, returns partial results [check]
Common Mistakes:
4. If the metrics aggregation service fails to update the error budget in real time, what is the most likely failure observed by the alerting system?
medium
A. Alerts trigger randomly due to inconsistent error count aggregation across nodes
B. Alerts never trigger because the error budget appears full and no burn rate is detected
C. Alerts trigger too frequently due to stale error budget values being reset to zero
D. Alerts show delayed notifications but eventually catch up after service recovery

Solution

  1. Step 1: Understand failure impact on error budget updates

    If aggregation service fails partially, inconsistent error counts across nodes cause alerting to behave erratically.
  2. Step 2: Eliminate other failure modes

    Resetting to zero (A) is unlikely without explicit reset; no alerts (B) implies total failure, not partial inconsistency; delayed alerts (D) imply buffering, not aggregation failure.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Aggregation failure -> inconsistent counts -> random alert triggers [check]
Hint: Aggregation failure causes inconsistent counts, leading to random alerts [OK]
Common Mistakes:
5. At 10x scale of concurrent users, which component in a typeahead autocomplete system using Elasticsearch and Trie is most likely to become the bottleneck first, and why?
hard
A. The Trie servers, because in-memory Tries are stateful and cannot be easily sharded or distributed across nodes
B. The client-side UI, because rendering large autocomplete result sets slows down user experience
C. The prefix hash map, because storing all prefixes for billions of entries exceeds memory limits quickly
D. The Elasticsearch cluster, because fuzzy queries require heavy CPU and memory, causing query latency spikes

Solution

  1. Step 1: Analyze statefulness and scalability

    Trie servers hold large in-memory state and are difficult to shard due to pointer-based node structures, limiting horizontal scaling.
  2. Step 2: Compare other components

    Elasticsearch scales horizontally with shards; prefix hash map can be partitioned or replaced; client UI is less likely the first bottleneck at backend scale.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Trie statefulness limits sharding -> bottleneck at scale [check]
Hint: Trie stateful, hard to shard -> first bottleneck at scale [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard