03. Data & Storage / Lesson 11 of 11
Files & Media
Store photos and videos in object storage, and keep only a small record in the database.
- 8 min
- Beginner
- 9 steps
- Database growth500 GB/day (bad)
- Bytes through app500 GB/day (bad)
- Upload time2.0 s
- Storage reads—
- Request
- Response
- Write
- Health check
- Cache hit
- Cache miss
Step 1 of 9: Photos stuffed into the database
Read every step as text
Step 1: Photos stuffed into the database
A photo app takes 100,000 uploads a day at 5 MB each. If each photo goes into a database column, the database grows by 500 GB/day, about 182.5 TB a year.
Every backup and every replica copies all of it. And reading a 5 MB photo ties up a database connection for the whole transfer, while a normal row read takes about a millisecond.
A database is built for small rows you search and update. Big files make it slow and expensive.
Step 2: Put files in object storage
Object storage (Amazon S3, Google Cloud Storage, Azure Blob) stores files as objects: a key such as
photos/2026/11/abc.jpgand the bytes. There are no folders to manage and no size limit that matters for photos.It is cheap per gigabyte, keeps several copies in different places, and is built to serve big files over plain HTTP. The cost: you cannot search inside it or change part of an object. You replace the whole object.
Object storage providers design for extreme durability: S3 advertises 11 nines, so losing a file is very rare.
Step 3: The database keeps a small record
The database still knows what each photo is. For each upload it stores one metadata row of about 1 KB: the owner, the object key, the size, the type and a status.
100,000 rows of 1 KB add only 100 MB/day, instead of 500 GB/day. You can search, sort and join these rows as usual, and the row points to the bytes.
Bytes go to object storage; facts about the bytes go to the database.
Step 4: Do not carry the bytes: hand out a ticket
The app still carries every photo (500 GB/day through its network), only to pass it on. Instead, the browser asks the app for permission. The app replies with a pre-signed URL: a link to one exact object key, signed with the app's secret and valid for a short time such as 15 minutes.
The signing request and reply are about 1 KB, so the app now handles 100 MB/day for the upload step.
The app checks that the user is allowed to upload before signing, and sets limits: one key, the file type and a maximum size.
Step 5: The browser uploads straight to storage
The browser sends the 5 MB with that URL directly to object storage. When it finishes, it tells the app "done", and the app sets the row's status to uploaded. That is two small calls of 1 KB each, so 200 MB/day through the app.
The speed is set by the user's connection. At 20 Mbit/s, 5 MB takes
5 × 8 ÷ 20 = 2.0 s. The app servers no longer slow down when many people upload at once.Uploads scale with the storage service, not with your servers. You can run a few small app servers.
Step 6: Process in the background
Once the upload lands, storage sends an event to a queue. Workers pick it up: scan for viruses, check the file really is a JPEG, strip location data, make thumbnails, or turn a video into several sizes.
The user is not kept waiting. The row's status moves from
uploadedtoprocessingtoready, and a failed job is retried. If the work is slow or the workers fall behind, the queue just gets longer.Never trust a file because of its name or type header. Check the bytes before you serve them to other people.
Step 7: Viewers get files from the nearest edge
Photos are viewed far more than they are uploaded. Say 1,000,000 thumbnail views a day at 200 KB each: 200 GB a day. Serving that from one bucket is slow for faraway users and costly.
Put a CDN in front. If 95% of views are answered at the edge, object storage serves only
200 × 0.05 = 10 GBa day. Files never change once written (use a new key for a new version), so they can be cached for a long time.Keep the bucket private and let only the CDN read it. For private photos, give each viewer a signed link that expires.
Step 8: Big files: send in chunks and resume
A 200 MB video at 20 Mbit/s takes 80.0 s. If the connection drops near the end, starting over wastes all of it. Storage services support multipart upload: split the file into 25 chunks of 8 MB, each sent and confirmed on its own.
Say the link drops after chunk 22. The browser asks which chunks arrived and sends only the missing 3:
3 × 8 = 24 MB, about 9.6 s instead of 80.0 s. Chunks can also go in parallel.At the end the client says "complete", and storage joins the chunks into one object. Unfinished uploads should expire so they do not cost money.
Step 9: Files and media in one picture
Keep files in object storage and a 1 KB metadata row in the database. The app signs a short-lived URL, the browser uploads straight to storage, and workers process the file in the background.
A CDN serves viewers, cutting storage reads from 200 to 10 GB a day, and chunked uploads let big files resume. The app servers handle only 200 MB/day instead of 500 GB/day.