03.4 CDN & blob storage

Intern · Component

Core idea

A CDN (Content Delivery Network) serves static content from edge nodes geographically close to the user. Blob storage (S3, GCS) stores large binary files cheaply and durably. Together they handle all media delivery at scale.

Mental model

A global bookstore: instead of shipping every book from one warehouse (origin server) to every country, you store copies in regional distribution centres (CDN edge nodes). Someone in Ireland gets their book from Dublin, not New York. The main warehouse only ships when a region runs out.

Why it matters

  • A single origin server in us-east cannot efficiently serve users in Asia
  • Static files served from origin waste compute and bandwidth needlessly
  • CDN dramatically reduces latency for assets that don’t change per-request

What to know

  • CDN cache: edge serves cached response for TTL duration. After TTL, re-fetches from origin
  • Cache-Control headers: you control TTL. Long TTL for versioned assets (image-v2.png), short for frequently changing ones
  • Blob storage (S3): object store, not a filesystem. Key (path) → blob. Infinite scale, cheap, durable (11 nines)
  • Pre-signed URLs: time-limited URLs that grant direct upload/download access to S3 without going through your server
  • Multipart upload: for large files, upload in chunks — resumable on failure
  • CDN invalidation: force edge to drop cached copy — use sparingly, expensive

Common traps

  • Serving user-generated content (profile photos) through your server instead of blob store + CDN — terrible at scale
  • Setting TTL too long for content that changes — stale content served
  • Not versioning asset URLs — can’t update without breaking cache (use content-hash filenames)

Recognise it

Recognition trigger: Any image, video, or file in your system → store in blob (S3), serve via CDN. Never serve binary files from your application servers. Pre-signed URLs for user uploads so the file goes directly to S3, not through your backend.

Practice question

10 million users upload profile photos. How do you store and serve them efficiently?

Apply at work

Answer these for the system you work on.

Go deeper