public

CDN &
Blob Storage

Serving static assets (images, CSS, video) from your application server is a waste of resources. Move them to the edge, closer to the user.

What is a CDN?

A Content Delivery Network is a group of geographically distributed servers that speed up delivery of web content.

  • 1. Origin Server:Your main server (e.g., AWS in Virginia).
  • 2. Edge Server:A CDN server in Mumbai, London, or Tokyo.
  • 3. The Magic:User in London requests `logo.png`. They fetch it from the London Edge Server (10ms) instead of Virginia (100ms).
public
Origin vs Edge

Push vs Pull Strategies

Pull CDN (Lazy Loading)

The default. CDN works like a "Cache-Aside" proxy.

  1. User asks CDN for `image.jpg`.
  2. CDN checks cache. Miss!
  3. CDN fetches from Origin.
  4. CDN serves User + caches it for next time.
Best for: General web content, heavy traffic sites.

Push CDN

You explicitly upload content to the CDN beforehand.

  1. You deploy new code.
  2. CI/CD script uploads assets to CDN.
  3. CDN distributes to all edge locations instantly.
  4. User requests `bundle.js`. Hit!
Best for: Critical assets, software updates, video catalogs.

Blob Storage (S3)

Databases hate large files. Storing images or videos in SQL (BLOBs) ruins performance and makes backups a nightmare.

Solution: Store metadata in DB, store file in Object Storage (AWS S3, GCS, Azure Blob).

// Users Table
id: 101
name: "Alice"
avatar_url: "https://s3.aws.com/bucket/avatar_101.jpg"

Key Features

  • Flat StructureNo folders (technically). Just keys with slashes: `folder/file.jpg`.
  • ImmutableYou overwrite objects, you don't modify them incrementally.
  • CheaperMuch cheaper per GB than block storage (SSD).

Presigned URLs

vpn_key

The Upload Problem

Uploading a 1GB video to your web server (to then upload to S3) is bad. It blocks your server threads and wastes bandwidth.

check_circleThe Solution

  1. Client asks Server: "I want to upload `video.mp4`".
  2. Server generates a Presigned URL (temporary permission) from S3.
  3. Server gives URL to Client.
  4. Client uploads directly to S3 using that URL.
Server never touches the file. Infinite scalability.

Invalidation is Hard

"There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton

The Problem

You updated the logo, but users still see the old one because the CDN cached it for 7 days.

The Fix: Versioning

Don't invalidate. Rename.
Instead of `logo.png`, use `logo-v2.png` or `logo-a8f3d.png`. The URL changes, forcing a fresh fetch.