Sub topic 4
The end-to-end architecture
This chapter assumes you know basic web architecture (clients, APIs, databases), how HTTP caching works, and what object storage and message queues do. It maps the whole platform so that later chapters can zoom into each part.
Two paths, one catalog
A video platform has two separate paths that share storage and metadata.
- The write path takes a source file from a creator and turns it into playable streams. It is slow, asynchronous and compute-heavy.
- The read path serves those streams to viewers. It is latency-sensitive, read-heavy and mostly handled by a CDN (content delivery network).
Keeping the paths apart lets you scale them independently. Uploads and transcoding are measured in jobs per hour. Playback is measured in requests per second and terabits of egress.
Components and their jobs
| Component | Role | Scales with |
|---|---|---|
| Upload service | Accepts source files, usually through resumable or direct-to-storage uploads | Concurrent uploads |
| Source storage | Keeps the original file untouched | Total uploaded hours |
| Job queue | Decouples upload from processing and absorbs bursts | Upload rate |
| Transcoding workers | Produce renditions and segments from the source | Video minutes to process |
| Origin storage | Holds segments and playlists as the CDN's source of truth | Catalog size times renditions |
| Metadata DB | Stores titles, status, rendition lists and permissions | Catalog size, API traffic |
| API service | Returns video details and the manifest URL | Viewer sessions |
| CDN | Caches segments close to viewers | Egress bandwidth |
| Player | Chooses renditions and fetches segments | Not applicable (runs on the client) |
Following one video through the system
- The creator uploads a file. The upload service writes it to source storage and creates a metadata record with status
uploaded. - An event puts a job on the queue. A worker picks it up and sets the status to
processing. - The worker transcodes the file into several renditions, cuts each into segments and writes playlists.
- The worker writes the output to origin storage, records the renditions in the metadata DB and sets the status to
ready. - A viewer opens the video page. The API reads the record and returns the master playlist URL.
- The player fetches the playlist from the CDN, then fetches segments one at a time. The first request for a segment misses the cache and pulls from origin. Later requests are served from the edge.
Design decisions to settle early
- Asynchronous processing. Transcoding can take longer than the video itself, so uploads must not block on it. Use a queue and make jobs idempotent, so a retry after a worker crash produces the same output.
- Immutable media objects. Write segments once under unique paths. Immutable objects can be cached for a long time and never need invalidation.
- Status as a state machine. Track
uploaded,processing,readyandfailedexplicitly. Hide videos that are notreadyand give failed jobs a retry path. - Origin protection. Without a CDN, a popular video could send every viewer to origin storage. Route all playback through the CDN and consider a mid-tier cache to cut origin reads.
Exercise
A viewer reports that a newly uploaded video loads its page but the player returns 404 errors for segments. Using the architecture above, name one likely cause and one fix.
Show answer
A likely cause is that the metadata record was set to ready before the workers finished writing all segments and playlists to origin storage. The fix is to update the status to ready only after every output object has been written, and to have the API hide videos in any other state.