How a CDN works
CloudFront edge delivery
StreamHub production architecture (AWS)
CDN flow
- User requests
cdn.streamhub.com/segments/v_9182/720p/004.ts. - DNS resolves to the nearest edge PoP (point of presence).
- Cache HIT — edge serves file from local SSD; origin never contacted.
- Cache MISS — edge fetches from origin (S3 or origin shield), caches per TTL, serves user.
What to put on a CDN
| Asset type | Cache strategy | StreamHub example |
|---|---|---|
| Video segments (.ts, .m4s) | Long TTL, immutable URLs | HLS/DASH chunks |
| Thumbnails / posters | Medium TTL, purge on update | creator avatars, video posters |
| JS / CSS bundles | Long TTL + content hash in filename | app.v3f2a1.js |
| API responses | Short TTL or no cache | Only public, read-heavy endpoints |
Video segments (.ts, .m4s)
Cache strategyLong TTL, immutable URLsStreamHub exampleHLS/DASH chunksThumbnails / posters
Cache strategyMedium TTL, purge on updateStreamHub examplecreator avatars, video postersJS / CSS bundles
Cache strategyLong TTL + content hash in filenameStreamHub exampleapp.v3f2a1.jsAPI responses
Cache strategyShort TTL or no cacheStreamHub exampleOnly public, read-heavy endpoints
Never cache personalised or authenticated API responses at the CDN without careful Vary headers and cache-key design.
Cache control headers
GET /static/app.v3f2a1.js HTTP/1.1
Host: cdn.streamhub.com
HTTP/1.1 200 OK
Content-Type: application/javascript
Cache-Control: public, max-age=31536000, immutable
ETag: "3f2a1b9c"
GET /segments/v_9182/720p/004.ts HTTP/1.1
HTTP/1.1 200 OK
Cache-Control: public, max-age=86400
Content-Type: video/mp2t
Immutable tells browsers and CDNs the URL will never change content — safe to cache forever. Versioned filenames (app.v3f2a1.js) enable this pattern.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 4 sections
- CDN vs origin architecture
- Cache invalidation
- Dynamic content at the edge
- Measuring CDN effectiveness
Test yourself
Answer these before moving on — recall is what makes it stick.