Video in progress
A service runs on three instances and users upload files. Do you store the files on local disk or in object storage? How do you justify the decision?
In a multi-instance service, local disk means state: knowing which pod holds a file, backups and migration all become problems. So I usually take object storage (S3 or a compatible one) + metadata in the database; local disk stays only in a small single-server system or as a temporary buffer.
📖 Answer
If you choose local disk, questions come up right away: the upload landed on pod 1 and the download request came to pod 2, so what now? Sticky sessions, a shared NFS or file synchronization. Each comes with its own pain: NFS has weak lock and rename semantics, and synchronization is a distributed system you have to write yourself.
With object storage those questions go away:
- the service is stateless: you can kill and add pods at any time;
- durability and replication are the provider's job;
- the browser uploads large files directly (presigned URL), saving the service's traffic and heap;
- lifecycle rules: move to a cheaper class after 90 days, delete after a year.
It has a price too: every operation is a network request (latency in milliseconds, versus microseconds on local disk), there is no rename (it's copy + delete), the idea of a "directory" is just a prefix, and you pay per request. For a workload that reads a huge number of small files this is noticeable.
These are the questions I ask:
- How many instances will there be, and do they autoscale? If more than one, lean toward object storage.
- Who reads the files? If only users download them, a CDN + presigned URL. If the service itself processes them often, a local cache layer.
- Legal or customer requirements: must the data stay in the country? Then your own MinIO or a local provider.
- Backup and recovery: with local disk, who checks the backup and how?
Whichever you choose, put the boundary in the code behind one interface: FileStorage.put/get/delete. Then replacing the local implementation you started with on a single server by S3 later becomes a migration script and a configuration change, not a rewrite of the whole code. The metadata (owner, size, hash, MIME) always lives in the database; the storage is only for the bytes.
Sign up to mark studied questions and save your progress.