Short answer: keep avatar metadata in the database, keep the bytes in an object-oriented store, and treat local disk as a cache; for a fintech app that must restore tenant snapshots, measure large-file throughput and recovery time before choosing a layout.
I learned this from a backup drill, not a diagram. A tenant restore looked healthy because the database rows came back quickly, while the larger file set was still copying. The login path then served a mix of old and new avatars. Nothing crashed. The data was simply at two points in time, which is worse during an incident because it is easy to miss.
The invariant is simple: one database record names the immutable object version, and a restore changes the active pointer only after the corresponding bytes and checksum are verified. Local disk can accelerate a hot read, but it cannot be the source of truth for a multi-instance service.
Evaluating the split-brain avatar set after a restore
Start with a control-plane row. It needs a tenant identifier, an opaque object key, content type, byte length, checksum, snapshot identifier, and lifecycle state such as pending, active, or deleted. The client may send a filename for display, but it must not choose the storage key. A stable key also makes retries understandable: an upload attempt can be repeated without overwriting a different tenant's object.
The byte plane should support streaming writes, range reads, checksums, and lifecycle rules. Those are boring requirements. They are also the ones that decide whether a 400 MB restore is observable or just a spinner. Database blobs can give transactional coupling, but large values compete with indexes, replication, backups, and connection memory. Local disk has low latency until the process is rescheduled, the volume fills, or a second instance receives the request. During one drill, the metadata replay finished in seconds while the file copy was still running; an API process on another host then answered with the previous avatar version. The monitor saw 200 responses and called the test green. The restore report was wrong because it counted rows, not verified bytes, and nobody had recorded which snapshot each object belonged to. Since then, I treat the pointer switch as the recovery event and every earlier step as preparation.
For a small app in the EU and US, residency is a policy decision, not a country-code column. Place each tenant's objects in an allowed region, record that placement with the snapshot, and make a restore refuse a cross-region copy unless policy explicitly permits it. Your mileage may vary: the acceptable region set, retention period, and recovery objective belong in the service's written requirements.
Keep the transaction boundary narrow. The database transaction records pending; the upload happens outside it; a finalize step verifies size and checksum before setting active. If the worker dies after bytes arrive but before finalize, a reconciler can find the orphan by key and apply a retention rule. If finalize succeeds before the bytes are durable, reads must fail closed rather than silently falling back to an older version.
No shortcut.
Reliability signals from the restore worker
Throughput is end-to-end. A fast storage target cannot compensate for a single-threaded copy loop, a tiny HTTP connection pool, or a restore job that serializes every tenant. Measure at least four values: sustained write rate, sustained read rate, time to first byte, and time to restore a representative snapshot. Record p50 and p95, because a mean hides the slow tenant that keeps an on-call shift open.
I use bounded concurrency per tenant and a separate global limit. That keeps one customer's 2 TB restore from consuming every socket while still allowing independent tenants to make progress. Each object copy carries its snapshot ID and checksum. The destination is written under a new immutable key; only the metadata pointer is mutable.
Here is the core of that copy decision in Go. It is intentionally storage-agnostic so the same test can run against a local emulator and the production adapter.
package restore import ( "context" "fmt" ) type Object struct { Key string Size int64 Checksum string } type Store interface { Copy(ctx context.Context, sourceKey, destinationKey string) error Stat(ctx context.Context, key string) (Object, error) } func CopyVerified(ctx context.Context, store Store, source Object, destinationKey string) error { if source.Key == "" || destinationKey == "" { return fmt.Errorf("empty object key") } if err := store.Copy(ctx, source.Key, destinationKey); err != nil { return err } copied, err := store.Stat(ctx, destinationKey) if err != nil { return err } if copied.Size != source.Size || copied.Checksum != source.Checksum { return fmt.Errorf("snapshot verification failed for %s", destinationKey) } return nil } The restore coordinator should persist a per-object result and an idempotency key. A retry of CopyVerified may find the destination already present; the adapter should treat an identical verified object as success. Do not delete the old active key until the new snapshot is fully verified and the pointer switch is committed. That ordering gives operators a known rollback point.
| Layout | Large-file behavior | Restore evidence | Best fit |
|---|---|---|---|
| Database blob | Transactional metadata and bytes, but backup and replication load grow with payload size | Row commit plus database backup record | Small files where one transactional backup domain is required |
| Local disk | Excellent single-host latency; weak across replicas and replacement events | Volume snapshot, if one exists | Disposable cache or a single-node prototype |
| Object store plus metadata | Parallel transfer and independent lifecycle controls | Object checksum plus database snapshot pointer | Multi-tenant production uploads and selected-snapshot restore |
The table is a trade-off, not a ranking. A database blob is reasonable when files are tiny and the database backup system is the audited boundary. Local disk is reasonable when losing the file is acceptable and regeneration is guaranteed. Neither is suitable when a tenant must restore a selected snapshot after a host replacement without rebuilding bytes from another system.
The catch is operational ownership. Object storage shifts work into key design, lifecycle cleanup, region policy, checksums, and reconciliation. It does not remove backup testing. A lifecycle rule can expire noncurrent objects, but the application still needs to ensure that a metadata pointer never references an expired version; document those rules and test them against a staging bucket. The lifecycle model in the AWS S3 object lifecycle documentation is a useful standards reference.
How should a user avatar upload backend choose storage for recovery?
Before accepting an upload, enforce an allowlist of media types, a maximum byte length, and an authorization check for the tenant. Store the server-observed length and checksum, not only the browser's claims. On download, authorize the tenant first and send a disposition that matches the intended behavior: inline for a rendered avatar or attachment for a forced download. The MDN Content-Disposition reference documents that distinction.
During a restore, page on stalled progress, checksum mismatches, and a rising orphan count. A successful HTTP response is not proof that the selected snapshot is complete. The runbook should name the snapshot, count expected and verified objects, record bytes copied, and state whether the metadata pointer has switched. I first thought a checksum at the end was enough; later I found that per-object results were what made a partial restore explainable.
Three words: verify, then switch.
Do not choose this design when the application must run entirely offline, when policy requires all bytes inside a transactional database, or when the team cannot operate reconciliation and restore drills. In those cases, stick with a database-backed blob layout and accept its throughput ceiling, or choose a managed backup system whose audit contract you can test. The right answer is the one your team can restore at 03:00, not the one with the shortest upload handler.


