DEV Community

sawyerflynn1578
sawyerflynn1578

Posted on

Cheap Storage for User Documents — 3 Lifecycle Cleanup Tiers for Support Archives

Short answer: for cheap storage of user documents, put upload bytes directly into object storage with a signed request, then use lifecycle cleanup to move and delete objects from three retention tiers; the application should record the policy decision and verify it asynchronously instead of streaming a large media file through a support API.

That decision is about throughput, but throughput is not the only invariant. A document archive needs tenant isolation, an auditable retention clock, recoverable deletes, and a reconciliation path for the cases where a browser closes halfway through a multipart upload. In payment systems I treat an object key as a ledger reference: it is useful only when its state transition can be explained later, including who changed the policy, which retention version applied, and whether a legal hold was active when cleanup became eligible.

Keep the bytes out of the API.

The architecture decision record

The critical path has four actors: the support service authorizes an upload, the client sends bytes to a bucket, a worker validates the completed object, and a retention job applies the policy. The API never handles the media payload. It handles intent and metadata.

For a 2 GB screen recording, the authorization response can contain a short-lived signed URL and a generated key such as tenant/7f2e/case/8841/objects/2026-08-20T14:32Z-uuid. The key is opaque; user-supplied filenames stay in metadata, where they cannot alter path semantics. OWASP recommends allow-listing extensions, validating content, and storing uploads outside the webroot. Those controls belong in the worker before the object is made available to an agent.

The options below are implementation families, not a ranking. S3 lifecycle configuration is broadly portable; an R2-style implementation is attractive when an account already uses that provider's object and egress model; Wasabi lifecycle rules can be operationally simple but still require checking minimum-storage-duration and deletion semantics in the current contract. Your mileage may vary because retention guarantees depend on the exact storage class and legal hold features selected.

Option Useful property Boundary to test
S3 lifecycle Mature filters by prefix, tag, and age Archive classes can add restore delay and minimum-duration charges
R2 lifecycle S3-compatible API shape for direct uploads Compatibility is not identity; verify multipart, tagging, and event behavior
Wasabi lifecycle Straightforward age-based expiration for archives Confirm retention and early-deletion rules before promising a date

The record should name the failure boundary: a successful PUT is not proof that malware scanning, indexing, or retention registration succeeded. Those are separate state transitions.

How should SaaS teams compare lifecycle cleanup for archived user documents?

Start with a policy table owned by the tenant, not with a provider's console. For example, support recordings may stay hot for 30 days, move to an archive tier on day 31, and expire on day 395. A legal hold changes the final transition; it does not silently rewrite the upload timestamp.

The policy service writes an append-only event before issuing a URL. The event includes tenant ID, object key, policy version, actor, and an idempotency key. A retry with the same key returns the original authorization result. This is the exactly-once mindset applied where exactly-once delivery is unavailable: make every consumer safe to run twice, and make the audit trail explicit.

Here is a deliberately small Go sketch for the authorization boundary. The storage client is an interface so tests can use a fake signer and never need cloud credentials.

package upload

import (
    "context"
    "fmt"
    "time"
)

type Signer interface {
    SignPut(ctx context.Context, key, contentType string, expires time.Duration) (string, error)
}

type Authorizer struct {
    Signer Signer
}

func (a Authorizer) Create(ctx context.Context, tenant, caseID, contentType string) (string, error) {
    if tenant == "" || caseID == "" || contentType == "" {
        return "", fmt.Errorf("missing upload identity")
    }
    key := fmt.Sprintf("tenant/%s/case/%s/%d", tenant, caseID, time.Now().UnixNano())
    return a.Signer.SignPut(ctx, key, contentType, 10*time.Minute)
}
Enter fullscreen mode Exit fullscreen mode

The production version also persists the key and policy version in the same transaction as the authorization event. The timestamp above is illustrative; a real service uses a monotonic identifier or UUID generated by the transaction boundary so clock skew cannot shorten retention.

Retention is a state machine, not a cron expression

Lifecycle engines evaluate object age asynchronously. They are excellent at bulk transitions and poor at expressing business exceptions such as an open investigation or a customer export that is still being downloaded. Keep those exceptions in a database and project them into object tags or holds where the provider supports them.

A worker should reconcile three views: the database says what should exist, object listing says what does exist, and lifecycle reports say what was transitioned. A daily sample is not enough for regulated records; retain a complete event for every delete request and a digest of the listing used to reconcile it. Deletion must be idempotent, and a late completion event must not resurrect an expired record.

There is a practical catch: lifecycle timing is not a precise timer. If a contract says “delete after 395 days,” describe it as an eligibility boundary and measure the observed completion window. Do not put a customer-facing promise on an undocumented scheduler interval.

Large-file throughput without losing auditability

Multipart upload improves recovery from a dropped connection, but it introduces orphaned parts. Configure an incomplete-upload cleanup rule and emit metrics for initiated, completed, aborted, and expired uploads. A client retry should reuse the same upload intent while changing only the part number and checksum.

The API should return a narrow status object, not a proxy stream:

type UploadStatus struct {
    Key       string
    Policy    string
    ExpiresAt time.Time
    ScanState string
}
Enter fullscreen mode Exit fullscreen mode

Measure p95 time to first signed URL, p95 completion time by object size, abort rate, scan latency, and the age of the oldest unreconciled object. These metrics explain throughput regressions better than counting API requests, because the bytes are deliberately moving outside the application tier.

When the cheapest-looking lifecycle choice is wrong

Do not choose an option solely because its storage line item is low. A provider with an inconvenient restore path can increase support handling time; a provider whose compatibility omits an event you rely on can weaken the audit trail. Keep a self-hosted S3-compatible gateway when regulatory residency or custom encryption-key custody is the primary constraint, even if it increases operational work. This design is not suitable when agents need synchronous, byte-level transformations inside the request path, or when policy exceptions cannot be represented as tags, holds, or a durable database record.

In those cases, stick with a controlled processing service in front of storage and accept the throughput cost. For ordinary support archives, direct upload plus a reconciled lifecycle state machine keeps the boundary legible.

References

Top comments (0)