Object storage and media
Store files and media cheaply and durably, and keep large bytes away from your servers.
14 min readWhy files do not belong in your database
Images, videos, documents and backups are large, written once and read many times. Storing them as database blobs bloats the database, slows backups and replication, and wastes expensive memory and IOPS on data that never needs a query. Object storage services such as Amazon S3 are built for exactly this: a flat namespace of keys mapped to byte objects, virtually unlimited capacity, a low price per gigabyte and very high durability achieved by replicating or erasure-coding data across devices and facilities. The database keeps only metadata: the object key, owner, size, content type and status.
Uploads with presigned URLs
Routing a 2 GB upload through your API servers ties up a connection and bandwidth for minutes and makes those servers stateful in practice. Instead, the client asks your API for permission and receives a presigned URL: a time-limited, signed link that allows one upload to one key. The client sends the bytes directly to object storage, then tells the API the upload is complete.
- API: authenticate, check quotas, create a metadata row with status pending, return a presigned URL
- Client: upload directly, using multipart upload for large files so failed parts can be retried
- Completion: storage event or client callback marks the row as uploaded and triggers processing
Processing media asynchronously
Uploaded media usually needs work: thumbnails, format conversion, virus scanning or video transcoding. These jobs are slow and CPU-heavy, so they run in background workers fed by a queue, never inside the upload request. Workers read the original from object storage, write derived files back under new keys and update the metadata row. Always keep the original: if you later add a new thumbnail size or a better codec, you can reprocess from the source.
Serving media
Reads should rarely hit object storage directly. Put a CDN in front of the bucket so popular images and video segments are served from the edge, which cuts latency and egress cost. For private content, issue short-lived signed URLs or signed cookies per user. Plan storage growth with the estimation lesson's formula: 1 million uploads a day at 3 MB each is about 1 PB a year, so use lifecycle rules to move old, rarely read objects to cheaper storage classes.
Key takeaways
- Store bytes in object storage and metadata in the database
- Presigned URLs let clients upload directly, keeping large transfers off your servers
- Process media in queue-fed workers and always keep the original
- Serve media through a CDN and use lifecycle rules for cold data
Sign in to track lessons and earn badges.