MOBILE SYSTEM DESIGN · MODULE 05

YouTube & Reels Video Player

Adaptive bitrate switching, rolling segment buffers, zero-stall vertical pre-warming, and seamless PiP surface handover under real-world cellular volatility.

HLS / DASH ABR Rolling Buffer N+1 / N+2 Pre-Warm Zero-Drop PiP
Act I · Scope & Device Budget

Playback Requirements & Hardware Limits

Step 1 of 5
Functional & Non-Functional Scope
Core SLAs
  • Instant-Start Reels & Long-Form Streaming: Achieve < 100 ms swipe-to-first-frame in vertical short-form feeds and adaptive 360p–4K long-form playback.
  • Zero-Stutter ABR Ladder Switching: Seamlessly step quality rungs up or down at IDR keyframe boundaries across cellular bandwidth cliffs without dropping the current frame.
  • Bounded Hardware Decoder Pool: Mid-tier mobile chipsets expose only 2–4 hardware video decoders; strictly cap active codecs to prevent OS codec starvation crashes.
  • Seamless PiP & Background Audio Handover: Rebind the active decoder across surfaces or detach video on screen lock without re-buffering or tearing down the playback session.
Hard Device Budget Cards
4 Hard Caps
TTFF Budget
< 200ms / < 80ms

< 200 ms long-form startup; < 80 ms swipe-to-first-frame on pre-warmed Reels.

Rolling Buffer
15s min / 50s max

Evict played segments > 5s behind playhead to keep decoded RAM footprint flat.

HW Decoder Cap
Max 3 Active

1 Playing + 1 Warm Next (N+1) + 1 Recycled (N-1); strictly release N-2.

Rebuffer & Thermal
< 0.3% · 720p@30

Keep stall ratio < 0.3% and cap bitrate at 720p@30fps on OS thermal warning.

Act II · API, Manifest & Local Storage Contract

Adaptive Manifest Protocol & Local Segment Index

Step 2 of 5
Adaptive Manifest & Byte-Range Fetch (HLS/DASH)
2s Segments
Local Segment Index & Playback State (SQLite WAL)
LRU Indexed
Act III · Interactive 5-Node Architecture & Chaos Simulator

ABR Switching, Reels Pre-Warming & PiP Surface Handover

STREAM NOMINAL
Step 1 / 6
5-Node Topology · ABR Switching & Rolling Buffer
INIT STARTUP
picture_in_picture_alt Viewport & PiP Surface Overlay / Composited FULLSCREEN · 60FPS developer_board Decoder Pool & Warm Max 3 HW Codecs 1 / 3 ACTIVE hard_drive Byte-Range Disk Cache SQLite LRU · 2s Chunks CACHE WARM tune ABR & Buffer Controller EWMA 0.75x · 15–50s 720p · 2.4 Mbps cloud Edge CDN & Origin HLS / DASH Segments 16.4 Mbps · 200 OK
INIT STARTUP

Loading simulator...

Invariant active
Live Terminal Event Console
Live Telemetry HUD
Real-Time
Active Rung
720p · 2.4 Mbps
Conservative startup
Forward Buffer
18.0 s
Target 15s – 50s
TTFF / Swipe
145 ms
Within 200ms SLO
HW Decoder Pool
1 / 3 Active
Strict 3-codec cap
Chaos Engineering Switchboard
0 Active
Act IV · Zero-Dependency Kotlin Contracts & Platform Mapping

Library-Agnostic Media Core & Android / iOS Equivalents

Auto-Synced to Simulator
Platform Mapping Strip (Android & iOS Equivalents) 6 Agnostic Primitives
Agnostic Primitive Android Equivalent iOS Equivalent
Adaptive Media Engine Media3 / ExoPlayer AVPlayer / AVQueuePlayer
Hardware Video Decoder MediaCodec (Surface) VideoToolbox (VTDecompressionSession)
Byte-Range Disk Cache SimpleCache + CacheDataSource AVAssetResourceLoaderDelegate + FileManager
Picture-in-Picture (PiP) PictureInPictureParams AVPictureInPictureController
Background Audio & Controls MediaSessionService AVAudioSession + MPNowPlayingInfoCenter
Bandwidth & Thermal Signals BandwidthMeter + PowerManager.ThermalStatus AVPlayerItemAccessLog + ProcessInfo.thermalState
Act V · Architectural Tradeoffs & Production Observability SLOs

Design Tradeoffs & Streaming SLOs

Step 5 of 5
Tradeoff 01 Fast ABR

2s vs. 6s Segment Duration

2s Segments

Fast ABR step-down during sudden cellular cliffs and tiny ~180 KB first-chunk waste when users swipe away from Reels.

6s Segments

Higher compression efficiency and fewer HTTP requests, but slow ABR adaptation and 3x wasted prefetch bytes on short-form skips.

Defense: Use 2s chunks for Reels and mobile cellular ladders, paired with HTTP/2 or HTTP/3 multiplexing to amortize request overhead.

Tradeoff 02 Power vs FX

Hardware Overlay Surface vs. Composited Texture

HW Overlay Surface

Direct hardware compositor path cuts GPU power by 20–30% and supports secure hardware-backed DRM playback.

Composited Texture

Enables rounded corners, parallax transforms, and smooth alpha fades during vertical feed scrolling at higher GPU cost.

Defense: Use hardware overlays for full-screen long-form and DRM content; reserve composited textures for inline feed cards that require clipping or transforms.

Tradeoff 03 Codec Cap

Aggressive Pre-Warming vs. Data & Decoder Cap

Bounded 3-Codec Pool

Pre-decodes N+1 keyframe for < 80 ms swipe latency while releasing N-2 strictly before allocating a new codec.

Unbounded Pre-Decode

Spawning 5+ hardware decoders triggers immediate OS codec starvation crashes on mid-tier devices and burns cellular data.

Defense: Separate disk byte-range prefetch (cheap, N+1 & N+2) from hardware decoder allocation (scarce, strictly capped at 3 instances).

Tradeoff 04 Hybrid ABR

Client-Side EWMA ABR vs. Server-Driven Hints

Client EWMA + Hints

Client EWMA reacts immediately to local RF tunnel drops with zero extra RTT; server hints seed the initial rung before byte 0.

Server-Only ABR

Requires round-trip telemetry before reacting to sudden bandwidth cliffs, risking buffer depletion during elevator/subway drops.

Defense: Combine initial server throughput hints with client-side 0.75x EWMA safety factor and step-up hysteresis to prevent quality oscillation.

Production Observability SLOs
Streaming Reliability Targets
TTFF (P95) < 250 ms
Rebuffer Ratio < 0.30%
Reel Swipe Latency < 100 ms
Decoder OOM / Crash < 0.01%