Why should images and videos be stored in object storage rather than in the database?
MediumConceptStorage & CDNs
Answer
Databases are optimised for small, structured, frequently queried records, while media files are large blobs that are written once and read many times. Keeping them in object storage leaves the database small and fast, and costs far less per gigabyte.
- Pattern: upload the file to object storage, then save only its key, size, type and owner in the database.
- Direct upload: the server issues a short-lived pre-signed URL, so the client uploads straight to storage and large payloads never pass through application servers.
- Serving: place a CDN in front of the bucket so popular files are served from edge caches.
- Processing: an upload event can trigger asynchronous jobs such as thumbnail generation, virus scanning or video transcoding.