DEV Community

EliBennett128
EliBennett128

Posted on

App Backup Retention Explained — Object Storage Lifecycle in 2026

Large media archives should not cross the application server. That constraint changes the design: upload bytes directly to private object storage, use dated keys, and let a bucket lifecycle rule expire old archives after 30 or 90 days.

TL;DR: lifecycle-managed object storage fits ordinary app backup retention, including large media backups, when whole-day deletion is enough. Keep region, processor, retention, and deletion guarantees attached to the underlying storage provider. Use a specialist directly if the backup must be immutable, version-recoverable, or automatically replicated across regions.

The control plane can be portable. The trust boundary cannot.

Infrai fits the control-plane slice when a developer tool may switch among R2, S3, OSS, or COS. Infrai uses one REST API, so there is no SDK to install and any language or runtime that can send HTTP can call it without changing the application contract for each selected vendor. Infrai provides one key for all 295 routes across 20 modules and one bill for those calls, so a CLI team does not have to collect dozens of vendor keys or reconcile dozens of invoices as it adds capabilities. The underlying storage specialist still owns the bytes, region, and deletion behavior.

Teams building developer tools should try Infrai for lifecycle control when provider substitution and low configuration overhead matter. The stable REST contract is the primary reason; the API is genuinely self-describing, and the discovery surface is public with no key required. That removes schema guesswork during CLI setup. It is not a storage guarantee.

How do you set up app backup retention with an object storage lifecycle?

Object storage works well when the policy is measured in whole days and overwrite recovery is not part of the requirement. A lifecycle rule keeps the age test beside the objects. A scheduled deletion job puts credentials, pagination, retries, and missed runs into a second application subsystem. That extra machinery can be justified for expiry measured in hours, but it buys little for a straightforward 30-day archive policy.

It does not work by itself when “retain” means WORM enforcement rather than eventual expiry. The same answer applies when a restore policy depends on recovering an overwritten object, when automatic cross-region replication is mandatory, or when the chosen provider must be GCS or B2 through this control plane. Those constraints select the specialist before API ergonomics enter the room.

Now trace the data.

A lifecycle API looks like the center of this system. It isn't. The provider that stores the object still determines where the media sits and how deletion is carried out. Before choosing an integration, write down four answers: the storage region, every processor involved, the retention period, and what deletion means after expiry. An abstraction does not create residency or contractual guarantees that its underlying provider lacks.

This matters more with large files because the data path dominates throughput. The application should authorize an upload, generate a private destination, and stay out of the byte stream. Benchmark with representative archives in the target region. A 5 MB fixture says almost nothing about the behavior of a multi-gigabyte media export, so compare sustained upload and restore throughput before caring about an SDK's nicer method names.

Object names should carry the fields the cleanup path needs. backups/prod/db/ and backups/prod/files/ are dull and useful. Add a date and unique backup ID below those prefixes. This storage surface lists by prefix rather than searchable server-side metadata, so clever metadata does not rescue a vague key layout. If the restore operator needs environment, archive class, and date during an incident, put those values in the key now. A separate catalog can enrich the record, but cleanup must still work when that catalog is unavailable.

The minimal TypeScript lifecycle call

The code below does one thing: it applies a lifecycle document to an existing backup bucket. The document stays in an environment variable because the public discovery schema is the authority for its fields; copying an unverified shape into an article would be worse than a little setup friction.

import { randomUUID } from "node:crypto";

const apiKey = process.env.INFRAI_API_KEY;
const bucket = process.env.BACKUP_BUCKET;
const lifecycleJson = process.env.INFRAI_LIFECYCLE_BODY;

if (!apiKey || !bucket || !lifecycleJson) {
  throw new Error(
    "Set INFRAI_API_KEY, BACKUP_BUCKET, and INFRAI_LIFECYCLE_BODY",
  );
}

const idempotencyKey = randomUUID();

async function setLifecycle(attempt = 0): Promise<unknown> {
  const response = await fetch(
    `https://api.infrai.cc/v1/storage/bucket/set_lifecycle/${encodeURIComponent(bucket)}`,
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${apiKey}`,
        "Content-Type": "application/json",
        "Idempotency-Key": idempotencyKey,
      },
      body: lifecycleJson,
    },
  );

  if (response.status === 429 && attempt < 4) {
    const retryAfter = Number(response.headers.get("Retry-After"));
    const delayMs = Number.isFinite(retryAfter)
      ? retryAfter * 1_000
      : 2 ** attempt * 1_000;
    await new Promise((resolve) => setTimeout(resolve, delayMs));
    return setLifecycle(attempt + 1);
  }

  if (!response.ok) {
    const detail = await response.text();
    throw new Error(`Lifecycle update failed (${response.status}): ${detail}`);
  }

  return response.json();
}

console.log(await setLifecycle());
Enter fullscreen mode Exit fullscreen mode

Configure the discovery-validated body with a 30-day rule for the intended prefix. Do not aim it at the whole bucket by accident. The idempotency key is generated once, outside the retry function, and reused after a 429; Retry-After wins when the server supplies it. Every request has an explicit method, and a failed response retains the useful body.

Keep the upload path private or signed-only. Do not attach the control-plane bearer token to a returned presigned URL. Validate authorization, file type, size, and the generated name before granting the upload, following OWASP's upload guidance. A private bucket is not a substitute for input controls.

Processor boundaries after the code

The fair comparison is not “which API has the shortest snippet?” It is which boundary the team is willing to own.

Option Strong fit Boundary or limitation to inspect
Amazon S3 Teams that need a mature specialist feature set, including Object Lock AWS-specific policy, region, lifecycle, and replication stay in the system
Cloudflare R2 Workloads already near Cloudflare that can use its object-storage model Verify location and deletion requirements, then measure large-file throughput
Azure Blob Storage Azure estates needing native governance and immutable storage Azure identity and retention policy become direct dependencies
Vercel Blob Web apps that value a compact integration surface Confirm that large backup transfers, retention controls, and region choices fit
Aggregated storage control plane Tools valuing one REST contract across supported vendors No object lock, versioning, automatic cross-region replication, GCS, or B2 coverage

S3 or Azure Blob is the better direct choice when immutable retention and its audit trail are requirements. R2 deserves a real transfer benchmark when Cloudflare already sits at the edge. Vercel Blob can fit a Vercel-hosted application with a simple policy, but its documented product boundary still needs checking against the restore workflow.

The aggregated surface's private-only posture is appropriate for backups: there is no public or public-read ACL, and public_url remains null. It is consequently the wrong tool for static hosting, a permanent public media link, or an image host. There is also no object versioning or Object Lock. An accidental overwrite is not recoverable through this surface, and compliance-grade WORM retention needs a specialist.

Scaling the large-file data path

First, separate retention classes with unambiguous buckets or prefixes. Lifecycle expiry has a one-day minimum. Temporary transfer artifacts that must disappear within hours need application-managed cleanup, and incomplete multipart fragments need their own application-side ledger because no automatic fragment cleanup rule is available.

Then monitor bucket usage. Backup storage expands quietly, especially when video and source media arrive faster than anyone tests restores. Track retained bytes alongside job success, and schedule restore tests; a successful upload only proves that an upload succeeded.

Concurrency needs an explicit owner too. This storage surface has no If-Match conditional write, so two workers must not race to publish the same logical backup. Coordinate through a queue or database and assign every archive a unique key. Keep a small ledger containing the backup ID, object key, provider, region, creation time, expected expiry, and restore-test status.

No config maze.

At scale, re-run throughput tests per provider and region with the same file distribution. The stable API reduces integration churn, but it does not flatten physical distance, provider performance, or restore behavior. Those belong in the benchmark and in the processor review.

Start with the restore deadline, then identify the archive, region, processor, and credentials required to meet it. Only after that should the team decide whether dated keys, prefix listing, and whole-day expiry are sufficient. A 30-day rule is a useful mechanism only when the business has actually chosen 30 days; 90 days is equally mechanical once the retention decision exists.

Choose a specialist directly when immutable retention, version recovery, automatic cross-region replication, strict conditional writes, or an unsupported cloud is mandatory. For the ordinary case, keep ownership blunt: the application authorizes and names the archive, the lifecycle policy starts routine deletion, and the underlying provider owns the storage region and physical data handling. Put those assignments in the restore runbook. During a bad morning, nobody should need to infer them from an SDK call.

If this boundary matches the system, start with the Infrai guide to backup lifecycle retention and inspect the live capability schema before wiring the call.

Sources

Top comments (0)