Prompt
How do I store uploaded files for a web app so they are shared across instances and easy to restore if deleted?
Latest observation
For a web app with multiple instances, the usual pattern is:
Recommended approach
Store uploaded files in object storage, not on the app server’s local disk.
Examples:
- Amazon S3
- Google Cloud Storage
- Azure Blob Storage
- DigitalOcean Spaces
- MinIO (self-hosted, S3-compatible)
Why this works
Shared across instances
All app instances read and write to the same central storage, so any instance can serve any file.
Easy to restore
If files are accidentally deleted, you can restore them if you have:
- versioning enabled
- regular backups / lifecycle snapshots
- object retention / soft delete, if supported
Typical architecture
- User uploads file to your app.
- App validates it and uploads it to object storage.
- App stores metadata in your database:
- storage key/path
- original filename
- MIME type
- size
- owner/user ID
- upload timestamp
- App serves files either:
- directly from object storage via signed/public URLs, or
- through your app if you need access control or processing
Best practices for durability and recovery
1. Enable versioning
This lets you recover overwritten or deleted objects.
2. Use soft-delete / retention
If supported, deleted files are retained for a period before permanent removal.
3. Back up metadata too
Your database is just as important as the files themselves.
4. Don’t rely on local disk
Local disk on containers/instances is often ephemeral and won’t be shared.
5. Use unique object keys
Avoid filename collisions by using IDs or UUIDs, e.g.:
uploads/2026/10/uuid-file.pdf
6. Consider antivirus/scanning
If users upload arbitrary files, scan them before making them available.
Common implementation pattern
- App server: handles auth, validation, metadata
- Object storage: stores file bytes
- Database: stores file records and permissions
- CDN (optional): speeds up downloads
If you need easy restore after deletion
Use:
- object storage versioning
- deleted-object recovery windows
- offsite backups
- infrastructure-as-code to recreate buckets/policies
If you want, I can also suggest a setup for a specific stack like AWS + PostgreSQL, Docker/Kubernetes, or Node/Express, including example code.