Interview prep notes

linkjobai revised this gist 5 days ago · a2b30a0

1 file changed, 40 insertions

videostream.md (file created)
@@ -0,0 +1,40 @@
1 + # System Design Interview: Designing a Video Streaming Service (YouTube-style)
2 +
3 + This question is mostly about the upload pipeline and efficient delivery, not the database.
4 +
5 + ## Requirements
6 +
7 + - Users upload videos; others watch them on phones, laptops and TVs with smooth playback.
8 + - Playback adapts to network speed.
9 + - Example scale: 5M daily viewers, 500k uploads a day, average video 300 MB before processing.
10 +
11 + ## Upload path
12 +
13 + 1. The client asks the API for an upload URL and gets a **pre-signed URL** to object storage, so large files bypass your app servers.
14 + 2. Large files use **resumable / multipart uploads** so a dropped connection doesn't restart from zero.
15 + 3. When the upload completes, storage emits an event onto a queue.
16 +
17 + ## Processing pipeline
18 +
19 + Workers pull jobs and **transcode** the original into several resolutions and bitrates (for example 240p to 1080p) and codecs. Each rendition is split into short **segments** (2-6 seconds) with a manifest file (HLS `.m3u8` or DASH `.mpd`).
20 +
21 + Model it as a DAG: split into chunks, transcode chunks in parallel, generate thumbnails, run content checks, then merge and publish. Parallel chunk transcoding is what keeps a 1-hour video from taking hours.
22 +
23 + ## Playback path
24 +
25 + - Segments and manifests are served from a **CDN**, which absorbs nearly all read traffic.
26 + - The player uses **adaptive bitrate streaming**: it measures throughput and switches renditions between segments.
27 + - Popular videos stay hot in the CDN; long-tail videos may be fetched from origin storage on demand.
28 +
29 + ## Metadata
30 +
31 + A relational or wide-column store holds video records (owner, title, status, renditions). View counts are high-write, so buffer them (stream into a counter service and flush in batches) rather than updating a row per view.
32 +
33 + ## Trade-offs to mention
34 +
35 + - Transcoding every upload to every resolution costs compute and storage; you can transcode rare resolutions lazily.
36 + - CDN cost is the largest bill; regional caching and good cache keys matter.
37 + - Copyright and safety checks add latency before a video goes public.
38 +
39 + ---
40 + *Disclosure: I help build [Linkjob AI](https://www.linkjob.ai/), a tool for live interview support.*