Sub topic 3
Delivering Media Through a CDN
Assume you know HTTP caching, object storage, and basic client–server architecture. A content delivery network (CDN) caches files at edge locations near users. Your origin remains object storage, while the CDN handles most reads.
Immutable, Cacheable URLs
Use a content hash or version in each public URL, such as /media/9b1c4e/w800.webp. When the file changes, publish a new URL. The old URL never changes, so caches can safely keep it for a long time.
GET /media/9b1c4e/w800.webp HTTP/1.1
Host: cdn.example.com
HTTP/1.1 200 OK
Content-Type: image/webp
Cache-Control: public, max-age=31536000, immutable
ETag: "9b1c4e"immutable tells clients that revalidation is unnecessary during the cache lifetime. Use shorter lifetimes for URLs whose content can change.
Range and Conditional Requests
A range request asks for part of a file with the Range header. The server responds with 206 Partial Content. Video players use ranges to seek without downloading the whole object.
Conditional requests use ETag or Last-Modified. A client sends If-None-Match; if the content is unchanged, the server returns 304 Not Modified without the response body.
Video Streaming
For adaptive bitrate streaming, transcode one source video into several resolutions and bitrates. HLS uses playlists and media segments; DASH uses manifests and segments. The player selects a suitable stream as bandwidth changes. A background processing pipeline should create these outputs after upload.
Access Control and Safe Serving
Keep private media behind signed URLs or signed cookies. A signed URL grants access to one object for a short time. Signed cookies are useful when a player must fetch many HLS or DASH segments.
Serve user files from a separate domain. Set an accurate Content-Type, add X-Content-Type-Options: nosniff, and use Content-Disposition: attachment for downloads that should not render inline. Never trust a filename or browser-provided MIME type when deciding how to process a file.
Lifecycle and Cost
Configure lifecycle rules to delete incomplete multipart uploads and temporary variants. Delete database records and storage objects together, using a retryable cleanup job for failures. Track CDN egress, cache-hit ratio, and origin traffic. Smaller variants and good cache keys reduce bandwidth costs.
Exercise
Why should a changed image receive a new URL instead of relying on cache invalidation?
Show answer
A new URL lets existing cached responses remain valid while guaranteeing that requests for the changed image fetch the new representation.