Object Storage
S3-style storage for files and blobs: buckets, keys, presigned URLs, and how it compares to block and file storage.
What is it?
Apps need to store large, unstructured files: images, videos, PDFs, backups, logs. Putting them in a database bloats it, and putting them on an app server's disk ties them to one machine.
Object storage (Amazon S3, Google Cloud Storage, Azure Blob Storage, and S3-compatible systems like MinIO or Cloudflare R2) is a service built for this. You store an object (the bytes plus some metadata) under a key inside a bucket, and read it back by that key over HTTP. It scales to effectively unlimited size, is replicated for very high durability, and is cheap per gigabyte.
The usual pattern: the file goes in object storage, and a row in your database stores its key and metadata (owner, size, content type, created date), so you can query and authorise access.
Explain like I'm 10
Object storage is a giant coat check. You hand over a coat (the file), get a ticket number (the key), and later hand the ticket back to get the coat. You can't alter one sleeve in place; you swap the whole coat. The venue's guest list (your database) records which ticket belongs to which guest.
Examples
Upload and download with the AWS CLI
aws s3 mb s3://acme-user-uploads # create a bucket
aws s3 cp avatar.png s3://acme-user-uploads/users/42/avatar.png
aws s3 ls s3://acme-user-uploads/users/42/ # list by prefix
aws s3 cp s3://acme-user-uploads/users/42/avatar.png ./copy.png
aws s3 presign s3://acme-user-uploads/users/42/avatar.png --expires-in 300Direct browser upload with a presigned URL
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
const s3 = new S3Client({ region: "us-east-1" });
// API server: authorise the user, record metadata, hand back an upload URL.
export async function createUpload(userId: string, contentType: string) {
const key = "uploads/" + userId + "/" + crypto.randomUUID();
await db.files.insert({ key, ownerId: userId, contentType, status: "pending" });
const uploadUrl = await getSignedUrl(
s3,
new PutObjectCommand({ Bucket: "acme-user-uploads", Key: key, ContentType: contentType }),
{ expiresIn: 300 },
);
return { key, uploadUrl }; // browser PUTs the file straight to S3
}The file bytes never pass through your servers, so they don't spend bandwidth or memory on uploads. An event notification (or a follow-up 'complete' call) then marks the row as uploaded.
How it works
The model. A flat namespace: bucket + key → object. An object is immutable bytes plus metadata (content type, custom headers). You replace objects rather than editing them in place; there's no "append" or "seek and write" in the S3 API. Operations are HTTP verbs: PUT, GET (including byte-range GETs), DELETE, LIST by prefix, HEAD.
Durability and consistency. Objects are stored redundantly across multiple devices and facilities. S3 Standard is designed for 99.999999999% ("11 nines") durability and 99.99% availability. Since December 2020, S3 provides strong read-after-write consistency for PUTs and DELETEs, and LIST reflects writes immediately. Other providers vary, so check.
Limits worth knowing (S3). A single object can be up to 5 TB. A single PUT can upload up to 5 GB; larger files use multipart upload (recommended above ~100 MB), with parts of 5 MB–5 GB and up to 10,000 parts, uploaded in parallel and retried individually.
Block vs file vs object storage - Block storage (EBS, local SSD): a raw disk attached to one machine. Lowest latency, supports in-place writes; used for databases and OS disks. Usually attached to one instance at a time. - File storage (NFS, EFS): a shared filesystem with directories, locks and in-place edits, mounted by many machines. Good for legacy apps expecting a POSIX filesystem. - Object storage: HTTP API, flat keys, whole-object writes, massive scale, cheapest per GB, higher per-request latency (tens of ms).
Presigned URLs. Your server signs a URL with its credentials, granting one specific operation (GET or PUT) on one key until an expiry time (up to 7 days with SigV4). Clients upload or download directly, the bucket stays private, and your servers stay out of the data path.
Typical setup. Private bucket → CDN in front for public reads → lifecycle rules move old objects to cheaper tiers (infrequent access, archive) or delete them → event notifications trigger processing (e.g. thumbnail generation via a queue).
1. POST /uploads ─────────▶ API server ──▶ DB: files(key, owner, status=pending)
│ signs URL
2. ◀──── presigned PUT URL ───┘
3. Browser ── PUT bytes ─────────────────▶ Object storage (bucket/key)
4. │ event notification
▼
Queue ──▶ Worker: thumbnail, status=ready
5. Reads: Browser ─▶ CDN ─▶ Object storageWhy does it exist?
File systems and block devices don't scale to billions of files across many machines, and they're expensive to make highly durable. Object storage gives up in-place edits and directory semantics in exchange for near-unlimited scale, very high durability, simple HTTP access and low cost, which is exactly what media, backups and data lakes need.
When to use it
User uploads (images, video, documents), static website assets, backups and database snapshots, logs and analytics data (data lakes queried by engines like Athena, Spark or Trino), ML datasets and model artifacts, and anything served through a CDN.
When not to use it
Not for data that needs low-latency, small, in-place updates or transactions: use a database or block storage. Not for workloads needing a real shared filesystem with locking (use file storage). And avoid huge numbers of tiny objects read individually and frequently, since per- request latency and cost add up; batch them or use a database.
Common mistakes
Storing large files as blobs inside the relational database, which bloats backups, replication and the buffer cache.
Proxying every upload and download through the app servers instead of using presigned URLs, wasting bandwidth and memory.
Making a bucket public to serve files, then exposing private user data. Keep buckets private and use presigned URLs or a CDN with origin access control.
Using guessable keys (users/42/avatar.png) for private content without access checks, and trusting client-provided content types or filenames.
Not keeping metadata in a database, then having to LIST millions of keys to answer simple questions like 'which files does this user own?'.
Practice exercises
- Easy:
Explain the difference between block, file and object storage, and give one workload that fits each.
- Medium:
Design the upload flow for profile pictures: API calls, presigned URL, database schema for metadata, and how you validate size and type.
- Hard:
Design storage for a video platform receiving 2 GB uploads over unreliable mobile networks, including resumable uploads, transcoding to several resolutions, CDN delivery, and lifecycle rules for old originals.
Interview questions
What is object storage?
A service that stores immutable blobs (objects) with metadata under keys in buckets, accessed over an HTTP API. It's highly durable, effectively unlimited in scale and cheap per GB, e.g. Amazon S3 or Google Cloud Storage.
How does object storage differ from block and file storage?
Block storage is a raw disk for one machine with in-place writes (databases). File storage is a shared POSIX filesystem (NFS). Object storage has a flat key namespace, whole-object writes, HTTP access, and scales furthest at the lowest cost.
Why store files in object storage and metadata in a database?
Object storage is great at bytes but poor at queries. The database row (key, owner, size, type, status) supports lookups, permissions and joins, while the bytes live where they're cheap and durable.
What is a presigned URL, and why use one?
A URL signed with server credentials that grants one operation on one object until it expires. Clients upload or download directly, so the bucket stays private and your servers don't carry the file traffic.
Are there 'folders' in S3?
No. The namespace is flat; slashes in keys are just characters. Consoles and LIST with a prefix and delimiter make keys look like folders.
How do you upload a very large file reliably?
Multipart upload: split it into parts (5 MB–5 GB each in S3, up to 10,000), upload them in parallel, retry failed parts individually, then complete the upload. Clean up abandoned uploads with a lifecycle rule.
What durability and consistency does S3 offer?
S3 Standard is designed for 11 nines of durability by storing data redundantly across multiple facilities. Since December 2020 it gives strong read-after-write consistency for PUTs, DELETEs and LISTs.
How would you serve user-uploaded images globally with low latency?
Keep the bucket private, put a CDN in front with origin access control, use immutable content-addressed or versioned keys with long cache TTLs, and generate resized variants on upload or on demand.
How do you keep the database and object storage consistent when an upload might fail midway?
Create a 'pending' row first, upload, then mark it 'ready' on the storage event notification or a completion call. A periodic job removes stale pending rows and orphaned objects; lifecycle rules abort incomplete multipart uploads.
What security risks come with user uploads to object storage?
Public buckets leaking data, guessable keys, malicious files (malware, HTML/SVG served with an executable content type), oversized uploads, and long-lived presigned URLs. Mitigate with private buckets, random keys, presigned PUT limits on type and size, scanning, safe Content-Type/Content-Disposition headers, and short expiries.