← Building blocks

Keep large blobs out of the database

Scaling & loadfundamental

Images, videos and uploads bloat the database and the app servers.

Say it like this

Bytes that are written once and read many times belong in object storage, which gives me eleven nines of durability and effectively unlimited capacity behind a plain HTTP interface, so my database and app servers never touch a blob.

Basic solution

Store blobs in object storage and keep only the key and metadata in the database. Upload directly with pre-signed URLs.

S3GCSAzure BlobMinIO

Immutable objects by key, with lifecycle tiers

The client uploads parts straight to the bucket with a pre-signed URL; the API holds only the key. Reads go through the CDN. Lifecycle rules move cold originals to cheaper tiers and remove abandoned parts.

How it works

  1. An object is an immutable blob stored under a key in a bucket, with a set of metadata headers. There are no directories, only key prefixes that look like paths, and no partial updates: changing an object means uploading a whole new one under the same key or a new one.
  2. A PUT request sends the bytes to the service, which writes them to several disks in several availability zones before it acknowledges the write, so a single disk or zone failure never loses the object. Large objects are uploaded as parallel parts (a multipart upload) and assembled when the client says it is done.
  3. A GET request fetches an object by key, optionally asking for just a byte range, over plain HTTP. The service is built for very high total throughput across many requests rather than for low latency on any one request; expect tens of milliseconds to first byte.
  4. Access is controlled by bucket policies and by short-lived pre-signed URLs, so a client can read or write one specific key without the application having to proxy the bytes.
  5. Lifecycle rules move objects to cheaper storage classes after N days and expire or delete them later; versioning keeps old copies so a delete can be undone, and replication copies the bucket to another region so a regional outage does not lose data.

The contract to remember

  • Reads after a successful write return the new object (the major providers now guarantee strong read-after-write). Listing a bucket is expensive and paginated, so design keys so that you never need to list to find something.

Worked example

Video platform bytes

  • 500K uploads per day; originals average 2 GB, plus five renditions totalling about 1 GB after transcoding. Written once, read millions of times via the CDN.
  • Upload: a 2 GB original in 5 to 50 MB parts, 200 parts uploaded with 8 in parallel on a 50 Mbps connection takes about 5 minutes; any failed part is retried alone. Parts not completed within 7 days are cleaned by a lifecycle rule.
  • Keys: originals under raw/{video_id}, renditions under v/{video_id}/{rendition}/seg_{n}.m4s. The CDN caches by URL, so a re-encode writes a new rendition id rather than overwriting, and old URLs stay valid until expired.
  • Durability: objects are stored across three zones; the advertised 99.999999999 percent durability means losing about one object in a hundred billion per year, far below the database's own risk.
  • Volume: 1.5 PB per day of new bytes, 550 PB per year. Originals move to infrequent-access storage after 30 days and to archive after a year: at roughly $0.02, $0.0125 and $0.001 per GB-month, that cuts storage cost by about 80 percent for the long tail.
  • Reads: the CDN absorbs 95 percent of segment requests; the origin sees about 5 percent, roughly 20K GETs per second at peak, which is well within what a bucket serves with request-rate scaling across key prefixes.

Variants and when each wins

Managed object store (S3, GCS, Azure Blob)

  • The cloud provider handles durability, scaling, lifecycle, versioning and replication. It wins as the default for anything cloud-hosted, because you get eleven nines of durability without engineering it.

Self-hosted object store (MinIO, Ceph)

  • The same API running on your own hardware. It wins for on-premises deployments and strict data-residency needs; the cost is that you own the durability engineering yourself.

Distributed file system (HDFS, NFS, EFS)

  • Mutable files with directories and POSIX semantics. It wins when existing software expects a real file system; it scales more slowly and offers weaker durability guarantees than object storage.

Blobs in the database

  • The bytes live in a column next to the row. It wins only for small blobs (under about 100 KB) that must change transactionally with the row; anything larger bloats backups, replicas and caches.

Recommendation: managed object storage for every blob over a few hundred KB, with the key in the database; self-hosted only when residency or cost at exabyte scale forces it.

Failure modes

Listing on the hot path

  • A page that shows a user's files takes seconds to load. The code lists the bucket under a prefix to discover which keys exist, and listing is slow and paginated. Make the database the index: store every key there and only ever GET objects by key.

Orphans and runaway cost

  • The bucket grows faster than the metadata says it should. Deletes removed the database row but not the object, and abandoned multipart uploads left parts behind that nobody can see. Delete objects from a background job driven by the database, add lifecycle rules for incomplete uploads and old versions, and run a monthly reconciliation between the two.

Overwriting a cached key

  • Some users keep seeing the old video for hours after a re-upload. The new bytes were written under the same key, and the CDN had already cached the old bytes under that URL. Treat keys as immutable: a new version gets a new key, and the metadata row is updated to point at it.

Public bucket

  • Private uploads turn up in a search engine's index. The bucket policy allowed public reads. Make buckets private by default and grant access only through short-lived pre-signed URLs or through the CDN with signed cookies.

Hot prefix

  • Uploads or reads fail with 503 slow-down errors during a premiere. Millions of requests hit keys that share one prefix before the store has scaled that partition. Spread keys across prefixes (a hash or the video id first), and pre-warm the CDN so the origin sees only a trickle of the requests.

Interviewer follow-ups

Answer out loud before you open each one.

Why not store files in the database?

Every replica, backup and cache would carry the bytes, and the database is optimised for small rows with indexes and transactions, not multi-gigabyte sequential reads. Object storage is built for exactly that shape and costs ten to fifty times less per gigabyte.

How do you keep the database and the object store consistent?

Write the metadata row first with a pending status, upload, then mark it ready after verifying the object exists. Deletes go the other way: mark the row, delete the object in a background job, and run a periodic reconciliation to catch strays in either direction.

How do clients upload large files reliably?

With a pre-signed multipart upload: the client sends parts of 5 to 50 MB in parallel, retries only the parts that fail, and calls complete at the end. The app never sees the bytes, and a lifecycle rule removes uploads that never complete.

What do storage classes change?

Cost per gigabyte against retrieval cost and latency. Hot data stays in standard, data read rarely moves to infrequent access after a month, and originals you may never read again go to archive, where a retrieval can take hours. Lifecycle rules do the moves automatically.

Connections

In study paths
Video from upload to play
Pairs with
Separate metadata from bytes · Upload large files without touching your servers · Serve static bytes from the edge · Process uploads in parallel · Let browsers and proxies cache
Pulls against
Default to a relational database
Used in
Video Streaming Platform (YouTube / Netflix)

The same parts on other clouds

The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.

AWSUsed here asGoogle CloudMicrosoft AzureOpen source and others
Amazon EC2 Auto ScalingAPICompute Engine managed instance groupsVirtual Machine Scale SetsKubernetes Deployment with a HorizontalPodAutoscaler, Nomad
Amazon DynamoDBMetadata DBFirestore, BigtableCosmos DBScyllaDB, Apache Cassandra
Amazon S3Bucket: standard, Infrequent access, ArchiveCloud StorageBlob StorageCloudflare R2, MinIO, Ceph
Amazon CloudFrontCDNCloud CDN, Media CDNAzure Front DoorCloudflare, Fastly, Akamai