DEV Community

Trkfpn392751
Trkfpn392751

Posted on

Cheap SaaS Storage for Support Documents: Deletion Deadlines and Backup Scheduling

At 02:13, the page says “document retention backlog above 10,000.” The queue is full of signed customer-support forms whose deletion deadlines passed yesterday. The storage dashboard is green because uploads still succeed.

Short answer: use a provider lifecycle rule for the ordinary expiry path, but keep a separate, idempotent scheduler that records each deadline and proves the object is gone. Compare S3 lifecycle, R2 lifecycle, and Wasabi lifecycle on that control-plane work, not on a single storage-rate number.

That split matters in a SaaS archive. A lifecycle engine operates on object metadata and prefixes; it does not know whether a support case is under legal hold, whether a tenant has exported the record, or whether a backup copy has the same deadline. The scheduler owns those decisions. Storage automation executes them.

The page is late, so trace the deadline backward

The useful signal is not “a delete request returned 204.” It is “every eligible document has a deletion decision, an execution attempt, and a verification record.” I model that as a small state machine: scheduled, held, delete_sent, verified, or quarantined for an operator review. A retry can move delete_sent back to scheduled; it must never create a second business event.

The first version of this job watched queue depth. That was too late. A burst of uploads made the queue look healthy while the oldest deadline quietly slipped. The better alert is age-based: page when the oldest unheld deadline is more than 15 minutes past due, and warn when the verification lag crosses five minutes. Your mileage may vary; those thresholds should come from the support team's recovery objective and the provider's listing consistency guarantees.

The false-positive cost is real. Page at two minutes and an hourly provider sweep will wake someone for normal jitter. Page at six hours and a customer can retain a document after its contractual window. I would rather tune the threshold from measured p95 deletion latency than argue about which vendor has the cheapest byte-month. That choice also changes the runbook: an early warning can open a ticket, while an overdue unheld record needs a page and an owner.

Too late.

How should teams design retention cleanup for document archive backups?

Start with one canonical deadline per document, expressed in UTC, and copy it into every derived record: object metadata, backup manifest, and audit row. Do not derive expiry from a filename. Percent-encoding rules in RFC 3986 make path parsing a poor place to hide policy, and tenant IDs can contain characters that need escaping.

A scheduler query should be boring and repeatable. It selects rows where delete_at <= now, legal_hold = false, and verified_at IS NULL, then claims them with a lease. The delete worker uses the provider's conditional request when available, treats “already absent” as success, and writes an immutable event containing the object key, policy version, and request identifier.

Here is the shape of the worker. The storage interface is deliberately generic so the retention test suite can run against a local emulator and a real bucket without changing policy code.

package retention

import (
    "context"
    "time"
)

type ObjectStore interface {
    Delete(ctx context.Context, key string, version string) error
    Exists(ctx context.Context, key string, version string) (bool, error)
}

type Record struct {
    Key       string
    Version   string
    DeleteAt  time.Time
    LegalHold bool
}

func Expire(ctx context.Context, store ObjectStore, r Record) error {
    if r.LegalHold || time.Now().Before(r.DeleteAt) {
        return nil
    }
    if err := store.Delete(ctx, r.Key, r.Version); err != nil {
        return err
    }
    exists, err := store.Exists(ctx, r.Key, r.Version)
    if err != nil {
        return err
    }
    if exists {
        return nil // leave the record retryable; do not invent a success event
    }
    return appendAuditEvent(ctx, r)
}

func appendAuditEvent(context.Context, Record) error { return nil }
Enter fullscreen mode Exit fullscreen mode

The comment is intentional: a transient read failure must not be converted into a deletion claim. The audit sink also needs deduplication on (key, version, policy_version), because at-least-once delivery is normal in queue systems.

Which lifecycle semantics belong in the retention decision?

All three can express age-based expiration, but their operational surfaces differ. S3 lifecycle rules are tightly integrated with object versions, delete markers, and storage classes; a rule can be scoped by prefix or tags. R2 exposes lifecycle configuration for object age and multipart cleanup, with an S3-compatible API but Cloudflare-specific account and billing boundaries. Wasabi documents lifecycle policies for expiration and incomplete multipart uploads, while its retention and minimum-storage-duration terms affect how “cheap” an early delete really is.

Use this small matrix during a trial. It keeps the comparison tied to deletion evidence rather than a marketing score.

Option Interface check Retention fit to test Boundary to document
S3 lifecycle S3 API plus provider console Versioned objects, delete markers, tags Storage-class transitions and noncurrent-version rules
R2 lifecycle S3-compatible API plus account controls Age rules and multipart cleanup Account and billing scope around the bucket
Wasabi lifecycle S3-compatible API plus policy settings Expiration and incomplete multipart cleanup Minimum-storage-duration terms on early deletion

Those are boundaries, not a ranking. Check four things in a proof-of-concept: how quickly a rule takes effect, whether noncurrent versions are covered, how a legal hold overrides expiration, and what listing or head requests cost at your expected volume. Keep the policy in source control and run a nightly reconciliation that compares intended deadlines with the provider configuration. A provider rule is a useful backstop; it is not your audit database.

For support archives, backups add a second failure mode. A database snapshot can outlive the object it references, and a replicated bucket can preserve a copy in another region. The deletion scheduler should emit a dependency set before it acts: primary object, thumbnail, manifest, and backup generations. If one member is held, mark the whole case for review rather than silently deleting only the easy copy.

Instrumentation that catches misses without paging on normal jitter

Emit counters for deadline_claimed, delete_requested, delete_verified, and delete_deferred. Add histograms for deadline-to-request and request-to-verification. The key dashboard panel is a percentile of overdue age split by tenant and policy version; a single average hides a noisy tenant and a stuck shard.

Run a synthetic document through the same path every hour. It should be tagged as test data, expire in a short window, and be absent from both the primary listing and the backup manifest after verification. OWASP's upload guidance still applies before retention begins: constrain file types and names, store outside executable paths, and scan content. A clean deletion pipeline cannot repair an unsafe upload pipeline.

Keep logs useful but small. Record hashes and identifiers, not document contents. Sample successful verification events once the counter is durable, while retaining every defer and failure reason for the retention period required by your own policy.

The catch: when cheap storage is the wrong optimization

Object storage is a poor fit when agents need sub-second random edits, when a regulator requires a provider-specific immutability control you cannot configure, or when deletion must be synchronous at request time. It is not suitable when the support workflow needs an atomic edit and delete in one transaction. Use a transactional database or a specialized records system for those paths, then export an immutable copy to object storage with a documented deadline. Stick with that database when the evidence requirement is stronger than an object lifecycle log.

The same caution applies to a “backup” that shares credentials and lifecycle policy with production. Separate accounts or projects, keys, and alert routes. Test restore before you test deletion. A backup that cannot be restored is not protection, and a delete job that cannot be explained is an incident waiting for a page.

I do not pick S3, R2, or Wasabi from a spreadsheet alone. I pick the combination whose lifecycle semantics, version handling, observability, and contract terms fit the deletion evidence the support team must produce. Prices can change; an explicit state machine and a verified audit trail are much harder to replace.

References

Top comments (0)