Object storage and CDNs
Overview
Photos, videos, documents and backups don’t belong in a relational database: they’re large, they’re read as whole files, and storing billions of them in tables is expensive and slow. Object storage is designed for exactly this, and a CDN gets those files to users quickly anywhere in the world. Together they appear in almost every design that handles media.
Object storage
Amazon S3, Google Cloud Storage, Azure Blob Storage and compatible systems (Cloudflare R2, MinIO) store objects in buckets:
- An object is a blob of bytes plus metadata, addressed by a key such as
photos/2026/12/04/981.jpg. - Operations are simple: put, get, delete, list by prefix. You replace objects rather than editing them in place.
- Durability is extremely high (S3 advertises eleven nines) because data is copied across devices and zones.
- Capacity is effectively unlimited; you pay per GB stored, per request and for data transferred out.
- Storage classes trade price for access speed: standard, infrequent access, archive. Lifecycle rules move or delete objects automatically (“move to archive after 90 days, delete after 7 years”).
What it isn’t: a database (no queries over contents) or a POSIX file system (no appending or locking). Keep the metadata (owner, size, type, status, which sizes exist) in your database and the bytes in object storage.
Uploads and downloads without your servers
Streaming a 2 GB video through your API servers ties up threads and bandwidth for minutes. Instead:
- The client asks your API for permission to upload.
- The API checks authentication and limits, then returns a presigned URL: a URL with a signature that allows one specific operation (PUT this key, up to this size) for a short time, such as 15 minutes.
- The client uploads directly to object storage. Large files use multipart upload: parallel chunks that can be retried individually.
- Object storage emits an event (or the client calls “upload complete”), and your system records the metadata and starts processing.
Downloads of private files work the same way with a presigned GET URL or signed CDN URL.
Processing uploads
Uploaded files usually need work: resizing images, transcoding video, scanning for malware, extracting text. Do it asynchronously: the upload event goes onto a queue, workers process the file and write results back to object storage, and the metadata’s status changes from processing to ready. The video-streaming case study builds a full pipeline.
Content delivery networks
A CDN (Cloudflare, Akamai, Amazon CloudFront, Fastly, Google Cloud CDN) runs cache servers in hundreds of locations. Users are routed to a nearby edge:
- Hit: the edge has the file and returns it, often within tens of milliseconds.
- Miss: the edge fetches it from the origin (your bucket or servers), returns it and keeps a copy.
Benefits: lower latency, far less load and bandwidth at the origin, and protection against traffic spikes and some attacks.
Controlling CDN caching
Cache-Control: public, max-age=31536000, immutablefor files that never change at a given URL.- Unique or versioned URLs for changing content: a new profile photo gets a new key (
/avatars/42/7f3c.jpg) instead of overwriting/avatars/42.jpg. Old cached copies simply stop being referenced, with no purge needed. - Purge or tag-based invalidation for the cases where a URL’s content must change.
- Origin shielding: a middle tier of CDN caches so that a miss in 200 edges doesn’t cause 200 origin fetches.
- Signed URLs or cookies for private or paid content.
CDNs also cache API responses that are the same for many users, terminate TLS near users and run small functions at the edge.
Costs to keep in mind
For media-heavy products, egress (data transferred out) often dominates the bill. CDNs reduce origin egress and usually charge less per GB; compression, modern formats (WebP, AVIF, AV1) and right-sized images reduce bytes further.
In an interview
For any feature with user uploads: “Clients upload directly to S3 using presigned URLs; an upload event goes to a queue for processing; metadata lives in the database; files are served through a CDN with long cache lifetimes and unique keys per version.” That covers scalability, cost and caching in one breath.
Recap
Object storage holds large files cheaply and durably by key, while metadata lives in a database. Presigned URLs let clients upload and download directly, keeping heavy transfers off your servers, and uploads are processed asynchronously. A CDN caches files near users; use long cache lifetimes with unique or versioned URLs, and lifecycle rules to manage cost over time.
Design profile-photo uploads
Design profile-photo uploads for an app with 30 million users. Photos can be up to 10 MB; the app shows each photo in three sizes (thumbnail, medium, full). Describe: (a) the upload flow, (b) where files and metadata live, (c) how resized versions are produced, (d) how photos are served quickly worldwide, and (e) what happens when a user changes their photo (caching).
(a) Upload flow:
(b) Storage:
(c) Resizing:
(d) Serving:
(e) Changing the photo:(a) Upload flow: the app asks the API for an upload URL; the API checks auth and
limits (type, max 10 MB) and returns a presigned PUT URL for a new key, e.g.
uploads/{user_id}/{uuid}.jpg. The app uploads directly to object storage.
(b) Storage: originals and resized files in object storage (S3/GCS); metadata
(user_id, photo key, sizes, status) in the database.
(c) Resizing: the storage "object created" event (or the app's "upload complete"
call) puts a message on a queue; workers validate the image, strip metadata,
create 3 sizes, store them under new keys and mark the photo ready.
(Alternatively an image CDN resizes on the fly and caches the result.)
(d) Serving: a CDN in front of the bucket (origin). URLs point at the CDN; the bucket
is private and only the CDN can read it. Long cache lifetimes.
(e) Changing the photo: each upload gets a new unique key, and the profile record
points to the new key. Old URLs stay valid in caches but nobody references them;
no CDN purge needed. Delete old objects later with a lifecycle rule or a cleanup job.Summary
- Object storage (S3, GCS, Azure Blob) stores files as objects by key: very durable, cheap, effectively unlimited, but not a file system or database.
- Presigned URLs let clients upload and download directly, keeping large transfers off your servers.
- Store file metadata in a database and the bytes in object storage; process uploads asynchronously.
- A CDN caches content at edge locations near users; set Cache-Control headers and use versioned or unique URLs instead of purging.
- Lifecycle rules move old objects to cheaper storage classes or delete them.