Marketplace App Backups: User Uploads, Database Dumps, Object Storage, and Expiry
Short answer: build each nightly backup as a closed recovery set containing a database dump, the referenced user uploads, and a signed manifest; authorize restoration of that set as one operation, but keep document delivery credentials outside the backup path. A marketplace can then prove that a signed document is recoverable until its deletion deadline without giving the normal application broad access to historical copies.
This architecture decision record treats restoration as a join problem. A database row can be restored perfectly and still be useless when its object is absent, while a copied object without the row that identifies its owner, signature state, and deletion deadline is an unauditable orphan. The unit of success is therefore neither a dump nor a bucket. It is a mutually consistent set.
The primary tension is access control versus delivery simplicity. Letting the web application read every backup makes delivery easy during an incident, but expands the authority of its routine credentials. Isolating every artifact behind restore-only credentials narrows that authority, although recovery now requires an explicit, audited handoff. For signed seller agreements and payout authorizations, choose the handoff.
Use a private backup namespace organized first by an opaque backup_id, then by artifact class. The backup writer may create objects under one new set and read only the metadata needed to verify its writes. A restore principal may read a selected completed set. The application that serves live documents receives neither permission.
Four invariants define completion:
- The database snapshot and upload selection share a recorded consistency boundary.
- Every manifest entry identifies an object key, byte count, and SHA-256 digest.
- The manifest records each signed document's deletion deadline, and restoration preserves rather than extends that deadline.
- A completion marker is written only after the dump, uploads, and manifest have been verified.
No marker, no backup.
This rule creates a useful failure boundary. A crashed nightly job can leave an incomplete prefix, but discovery ignores it because it has no completion marker; a retry uses a new backup_id, so it doesn't have to infer which writes took effect. The control-plane record should retain the job identity, selected consistency boundary, object counts, digest of the manifest, completion time, and the principal that approved any restore. Those fields turn an operational action into an audit trail without pretending that object creation itself is exactly-once.
For deletion, the live document record remains authoritative. A separate reconciler compares current deadlines with completed recovery sets and applies the documented retention policy. It must account for legal holds before removal. The precise retention period and hold procedure are compliance decisions outside this storage design; NIST SP 800-209 is useful for the storage-security control surface, while counsel and the marketplace's own records policy must supply the actual deadlines.
How should a nightly app backup join user uploads and a database dump?
Capture the database consistency boundary first, select the upload keys referenced at that boundary, and publish one manifest last. This ordering matters because listing a live upload prefix during an unconstrained database dump can combine rows from one logical moment with objects from another. The backup job needs a documented snapshot mechanism supplied by its database, plus an application-level rule for uploads that are in flight; this article cannot prescribe a universal snapshot command because none is valid across all database engines.
The prefix is an index, not an authorization system. A practical shape is sets/{backup_id}/database/, sets/{backup_id}/uploads/, and sets/{backup_id}/control/. Do not embed seller names, email addresses, contract titles, or deletion deadlines in keys. Authorization belongs in storage policy and application records, while the deadline belongs in the manifest and database where changes can be audited.
Prefixes aren't permissions.
| Layout | Restore behavior | Access-control consequence | Best fit |
|---|---|---|---|
| Recovery set first | One manifest closes over one dump and its uploads | A restore grant can target one set | Full application recovery with auditable approval |
| Tenant first | Operators assemble many tenant prefixes plus a database state | Grants can be narrow, but whole-app recovery becomes a reconciliation exercise | Tenant export or isolation is the dominant operation |
| In-place references | The dump points to live upload objects | Simple copying, but backup and production share a failure and deletion boundary | Re-creatable media with no independent recovery requirement |
The first layout wins here because the recovery set is the smallest authorization boundary that restores the marketplace coherently. It also makes a restore checklist executable: enumerate the manifest, verify every digest, load the dump into an isolated environment, resolve every referenced document, reconcile deadlines, and only then consider traffic. Prefixes help enumeration; they do not prove integrity, retention, or permission.
There is a subtle temporal issue. Suppose a seller signs document doc_4821, its deletion deadline is recorded, and the document is included in tonight's set. Tomorrow an authorized policy change shortens that deadline. The old manifest is historically accurate, yet it cannot be treated as fresh permission to keep or expose the old copy. Deletion reconciliation must consult the current policy state and legal-hold state, emit an auditable decision, and remove every eligible copy. Backups don't suspend data obligations.
Integrating the manifest with a generic object store
The storage adapter below is intentionally generic. It writes content-addressed artifacts beneath a caller-supplied set prefix, verifies returned metadata, and creates the manifest only after all artifacts pass validation. Production implementations still need encryption, database-specific snapshot handling, bounded concurrency, cancellation, and durable job records; those are explicit dependencies, not details to hide in a storage helper.
package recoveryset import ( "context" "crypto/sha256" "encoding/hex" "encoding/json" "fmt" "io" ) type Store interface { Put(ctx context.Context, key string, body io.Reader) error Stat(ctx context.Context, key string) (bytes int64, err error) } type Artifact struct { Kind string `json:"kind"` Key string `json:"key"` Bytes int64 `json:"bytes"` SHA256 string `json:"sha256"` } type Manifest struct { BackupID string `json:"backup_id"` Items []Artifact `json:"items"` } func putVerified(ctx context.Context, store Store, key string, src io.Reader) (Artifact, error) { staged, err := io.ReadAll(src) if err != nil { return Artifact{}, err } sum := sha256.Sum256(staged) if err := store.Put(ctx, key, bytesReader(staged)); err != nil { return Artifact{}, err } remoteBytes, err := store.Stat(ctx, key) if err != nil { return Artifact{}, err } if remoteBytes != int64(len(staged)) { return Artifact{}, fmt.Errorf("size mismatch for %s", key) } return Artifact{Key: key, Bytes: remoteBytes, SHA256: hex.EncodeToString(sum[:])}, nil } func seal(ctx context.Context, store Store, manifest Manifest) error { body, err := json.Marshal(manifest) if err != nil { return err } key := fmt.Sprintf("sets/%s/control/manifest.json", manifest.BackupID) _, err = putVerified(ctx, store, key, bytesReader(body)) return err } type byteReader struct { b []byte i int } func bytesReader(b []byte) *byteReader { return &byteReader{b: b} } func (r *byteReader) Read(p []byte) (int, error) { if r.i == len(r.b) { return 0, io.EOF } n := copy(p, r.b[r.i:]) r.i += n return n, nil } io.ReadAll keeps the example compact but is not suitable for large dumps or uploads. A real worker should stream to bounded, encrypted staging storage while hashing, close and durably finalize that staged file according to the host's guarantees, then reopen it for upload. The important contract is replayability: hashing must not consume the only readable stream before storage receives it. Remote byte count is a transport sanity check, not a substitute for verifying the digest during a restore.
Idempotency belongs above the adapter. Give each scheduled attempt a stable job record and each immutable recovery set a distinct backup_id; record artifact state transitions with a uniqueness constraint on (backup_id, key). If execution stops after an object write but before the state transition commits, retrying the same key with the same digest has the same intended result. A differing digest is a conflict requiring investigation, not an overwrite. This is exactly-once thinking applied honestly to at-least-once work: prevent duplicate logical effects, preserve evidence, and reconcile uncertain outcomes.
The rejected shortcut and when it is valid
We rejected a database dump that merely preserves pointers to the live upload bucket. It is attractive: no duplicate object transfer, no recovery manifest spanning two media classes, and ordinary delivery continues to use familiar keys. The catch is that deletion, credential misuse, or namespace damage can affect both the live application and its supposed backup. It also makes the signed document's independent recovery deadline difficult to demonstrate.
Keep that shortcut for derived thumbnails, cached exports, or other objects the restored application can deterministically regenerate from an independently protected source. It is not suitable for the sole retained copy of signed documents. Likewise, choose tenant-first sets when isolated tenant export is the actual recovery unit, and choose storage with enforceable retention or write-once controls when legal hold requires those properties; a prefix convention cannot manufacture them.
The decision is deliberately operationally heavier. Restore access requires approval, manifests require reconciliation, and deadline changes require deletion across historical sets. Those costs buy a narrow, auditable recovery boundary. For a marketplace retaining signed documents, delivery convenience is the wrong reason to give the live application authority over backup history.
Integrating restore drills with deployment and access reviews
A backup is accepted only after a restore drill, because write-path success answers the wrong question. In an isolated account or namespace, grant a short-lived restore role access to one completed set, verify the manifest digest against the control-plane record, verify each artifact, import the dump, and start a staging build against the recovered upload namespace. The application check should resolve every referenced signed document and reject every unreferenced object from normal delivery.
Restore it twice.
The drill report should include the selected backup_id, software revision, operator, approval, start and finish times, artifact totals, missing keys, extra keys, digest mismatches, deadline mismatches, and the final disposition. Don't collapse these into a single green metric. Missing artifacts and retention drift have different owners and different consequences.
Deploy the job with synthetic fixtures first: an empty upload, a multi-part-sized fixture appropriate to the chosen implementation, a filename containing non-ASCII characters, a document whose deadline is near, and a row whose referenced object is deliberately absent from the fixture store. The expected test behavior is deterministic: the first four are either represented faithfully or rejected before sealing, and the absent reference prevents completion. Fault injection should stop execution before and after each durable write, then demonstrate that retry does not create a second logical artifact or publish a partial set.
Watch incomplete-set age, verified bytes, artifact counts by class, reconciliation differences, restore duration, authorization denials, and deletion backlog. Cost also deserves a model, although it is not the decision axis: include stored bytes over the retention window, write and read operations, retrieval during drills, replication where required, and data transfer. AWS publishes these as separate S3 pricing dimensions, while DigitalOcean documents the behavior and operation of Spaces; evaluate current terms directly rather than copying a transient price into an architecture record.
Access reviews are part of operation. The backup writer, restore operator, deletion worker, and live delivery service have different jobs, so combining them into one credential defeats the boundary this design establishes. NIST SP 800-57 provides key-management guidance; use it to inform key lifecycle and separation, then map the final control to the compliance regime that actually governs the marketplace. I'm not sure any fixed drill frequency is defensible for every marketplace. Recovery objectives, change rate, and regulatory obligations should determine it, and measured restore reports should validate the choice.
References
- AWS, Amazon S3 pricing: https://aws.amazon.com/s3/pricing/
- DigitalOcean, Spaces documentation: https://docs.digitalocean.com/products/spaces/
- NIST SP 800-57 Part 1 Revision 5, Recommendation for Key Management: https://csrc.nist.gov/publications/detail/sp/800-57-part-1/rev-5/final
- NIST SP 800-209, Security Guidelines for Storage Infrastructure: https://csrc.nist.gov/publications/detail/sp/800-209/final