Object Storage & Blob Handling
Why files never belong in your database, presigned uploads, multipart and resumable transfers, storage tiers, and the metadata pattern every media system uses.
#The rule
Never store large binary files in your relational database. This comes up in nearly every media-related design, and stating it early with reasons is quick, easy signal.
First, the term: object storage is a service that holds whole files — photos, video, backups — under a key, and hands them back over HTTP. S3 is the canonical example. It doesn't do queries or updates-in-place; you put a file, you get a file.
Why not keep them in the database:
- Backups become impossible. A 5 TB database of photos takes hours to back up and longer to restore. Your recovery time is now measured in hours for reasons that have nothing to do with your actual data.
- Replication cost. Every byte gets shipped to every replica. Upload a 50 MB video and each read replica has to receive 50 MB too, delaying the small, important row changes queued behind it.
- It poisons your cache. Databases keep hot pages in memory; giant files push out the index pages and popular rows that genuinely needed to be there, so unrelated queries slow down.
- It's the wrong price. Object storage costs roughly an order of magnitude less per GB than provisioned database storage, and scales without your involvement.
- Serving. You cannot put a CDN in front of a database row, but object storage integrates with CDNs natively.
The pattern instead — metadata in the database, bytes in object storage:
photos table (Postgres)
┌──────────┬─────────┬──────────────────────┬───────────┬─────┐
│ photo_id │ user_id │ storage_key │ width │ ... │
├──────────┼─────────┼──────────────────────┼───────────┼─────┤
│ 8821 │ 42 │ photos/2026/8821.jpg │ 1920 │ │
└──────────┴─────────┴──────────────────────┴───────────┴─────┘
│
▼
┌────────────────────┐
│ Object storage │ ──► CDN ──► users
│ (S3 / GCS / R2) │
└────────────────────┘The database stays small, fast, and cheap to back up. The bytes live somewhere built for bytes.
#What object storage actually is
A flat key-value store for immutable blobs, addressed by key, accessed over HTTP. Not a filesystem — there are no real directories (prefixes only look like paths), no partial in-place updates, and no rename (a rename is a copy plus a delete).
Properties:
- Extreme durability — typically ~11 nines (99.999999999% chance a stored object survives a year). It's achieved with erasure coding (explained below) — each object is cut into pieces spread across several availability zones (AZs, physically separate data centres). Effectively, you will not lose an object.
- Lower availability than durability — around 99.9–99.99%. The bytes are safe; occasionally you can't reach them. Design for retries.
- Effectively unlimited capacity, no provisioning.
- Strong read-after-write consistency for new objects in modern implementations (this was famously eventual for years — worth knowing, since older material still says otherwise).
- Object-level operations only — replace the whole object; you can't edit a byte in place.
Strong consistency plus conditional writes ("create only if absent", "replace only if unchanged") changed what object storage can do. Conditional writes let two writers race safely — only one of them wins — which is the basic guarantee a database needs. So object storage is no longer just somewhere a database puts its backups; databases can now keep their actual data in it — see databases on object storage.
#Upload: use presigned URLs
A presigned URL is a link your server generates that grants permission to upload (or download) one specific file, for a short window. The client uploads straight to the storage service using it, so the bytes never pass through your servers — but you still control who gets a link.
The naive design routes uploads through your application servers instead. Don't.
NAIVE (bad)
client ──10MB──► app server ──10MB──► object storage
▲
your bandwidth, your memory, your timeouts,
your servers tied up for the whole transfer
PRESIGNED (correct)
client ──► app server: "I want to upload"
client ◄── signed URL + key (valid 15 min, size/type limited)
client ──10MB──────────────────► object storage (direct)
client ──► app server: "done, key=X"
app: verify object exists & size, write metadata rowWhy this matters: your application tier never touches the bytes. So:
- It stays small and stateless.
- Doubling upload traffic doesn't mean doubling your app servers — the storage service absorbs the bandwidth.
- A 10-minute upload on a bad mobile connection doesn't occupy one of your request threads for 10 minutes.
The signed URL carries its permissions, expiry, and constraints (max size, content type) inside it, protected by a cryptographic signature — the client can't edit them without invalidating the URL.
The important detail: never trust the client's "done" call blindly. Verify the object exists and matches expectations (size, content type, and ideally a checksum) before writing the metadata row — otherwise a client can create metadata pointing at nothing, or claim a file it never uploaded.
Downloads work the same way in reverse: for private content, issue a short-lived presigned download URL rather than proxying bytes.
#Multipart and resumable uploads
For large files, a single HTTP PUT is fragile — a dropped connection at 90% means starting over.
Multipart upload splits the object into parts (typically 5–100 MB), each uploaded independently and retried independently, then assembled server-side:
1. initiate → upload_id
2. upload part 1, 2, 3 ... N (parallel, independently retried)
3. complete(upload_id, [etags]) → object assembledEach part upload returns an ETag (a fingerprint of that part), and the final complete call lists them so the storage service knows which parts to stitch together, in which order.
Benefits: parallel uploads use all the available bandwidth, failures retry one part instead of the whole file, and you can upload while still generating data.
Operational detail worth knowing: the parts of an abandoned upload sit there costing money even though no finished file ever appeared, and they're invisible in a normal file listing. Set a rule that automatically bins incomplete uploads after a few days — a genuinely common source of surprise bills.
#Storage tiers
Access patterns are wildly skewed over time: a photo is viewed heavily for a week, occasionally for a month, and essentially never after a year. Paying hot-storage prices for cold data is the biggest avoidable cost in media systems.
| Tier | Access | Retrieval | Relative cost |
|---|---|---|---|
| Standard | Frequent | Immediate | 1× |
| Infrequent access | Monthly | Immediate | ~0.5×, + per-GB retrieval fee |
| Archive | Rarely | Minutes to hours | ~0.1× |
| Deep archive | Almost never | Hours | ~0.03× |
Lifecycle policies automate the transitions: "move to IA after 30 days, archive after 180, delete after 7 years." At petabyte scale this is often the largest single line item in the bill, and it is routinely left out of designs entirely.
The trap: infrequent-access tiers charge per retrieval. Data that's genuinely cold saves money; data you misjudged as cold and still read regularly costs more than standard storage.
#Durability: replication vs erasure coding
Worth knowing for a deep dive.
Replication — store 3 full copies. Tolerates 2 failures, costs 3× storage, and recovery is a simple copy.
Erasure coding — split the object into k data shards, then compute m extra parity shards — redundant pieces calculated from the data, a bit like a checksum you can rebuild from. Store all k+m shards on different machines. Any k of them are enough to rebuild the whole object.
Reed-Solomon (10, 4):
10 data shards + 4 parity shards = 14 total
Tolerates any 4 failures
Storage overhead: 1.4× (vs 3× for triple replication)Same or better fault tolerance at less than half the storage cost. The tradeoff shows up in a degraded read — a read while one of the shards is missing. To rebuild the object you must fetch k shards from k different nodes and do CPU work to recompute it, so a degraded read is slower and more network-intensive than reading one replica.
This is why object storage uses erasure coding (cheap, durable, and reads are rarely degraded) while databases use replication (a replica can serve reads immediately with no reconstruction).
#Serving media
- Always front it with a CDN. Object storage egress (data transferred out to the internet) is billed per GB and is expensive, and every request is a full round trip to the storage region.
- Immutable keys. Include a content hash or version in the key —
avatar_42_v3.jpgrather thanavatar_42.jpg. The bytes behind a key then never change, so CDNs and browsers can cache it forever. When the user uploads a new avatar, it gets a new key (_v4) and the app points to that — so you never have to tell caches to throw away a stale copy (invalidation). - Generate derivatives on upload. Thumbnails and resized variants should be produced asynchronously by a worker after upload, not on every read. Store each as its own object.
- Or resize on the fly at the edge, cached — better when the set of variants is large or unpredictable, since you don't pre-generate variants nobody requests.
- Signed URLs with short expiry for private content, and a CDN configured to respect them.
#The processing pipeline
The standard shape for any upload-and-process system (video, images, documents):
client → presigned upload → object storage
│ event notification
▼
queue → workers
│ transcode / resize /
│ scan / extract metadata
▼
derived objects + DB update
│
▼
mark ready, notify userKey properties: the upload completes fast and independently of processing; processing is retriable and scales separately; and the user gets a "processing" state rather than a blocked request. Making the workers idempotent — safe to run twice on the same input — matters. The queue delivers at least once: if a worker crashes before acknowledging a message, the message is redelivered, so you will process the same object twice. Key the work on the object version (e.g. write the thumbnail to 8821_v1_thumb.jpg), so a second run just overwrites the same output instead of creating duplicates.
#Check yourself
Give four reasons not to store large files in your relational database.Show answer
What is the standard pattern for files?Show answer
How does a presigned upload work, and what must the server still do?Show answer
What do multipart uploads give you, and what's the hidden cost?Show answer
How do storage tiers and lifecycle policies save money, and what's the trap?Show answer
Erasure coding (10, 4) versus triple replication: what does each cost?Show answer
Why does object storage use erasure coding while databases use replication?Show answer
Why must media processing workers be idempotent?Show answer
#What to carry forward
- Bytes go in object storage, metadata in the database, delivery through a CDN.
- Upload directly with presigned URLs — and verify the object before trusting the client.
- Use multipart uploads for big files and lifecycle rules for tiers and abandoned parts.
- Object storage is extremely durable (erasure coding) but less available — design for retries.
- Process uploads asynchronously through a queue with idempotent workers, and use immutable keys for caching.