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).
Push vs Pull Strategies
Pull CDN (Lazy Loading)
The default. CDN works like a "Cache-Aside" proxy.
- User asks CDN for `image.jpg`.
- CDN checks cache. Miss!
- CDN fetches from Origin.
- CDN serves User + caches it for next time.
Push CDN
You explicitly upload content to the CDN beforehand.
- You deploy new code.
- CI/CD script uploads assets to CDN.
- CDN distributes to all edge locations instantly.
- User requests `bundle.js`. Hit!
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).
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
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
- Client asks Server: "I want to upload `video.mp4`".
- Server generates a Presigned URL (temporary permission) from S3.
- Server gives URL to Client.
- Client uploads directly to S3 using that URL.
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.