DEV Community

FrozenSigh2853916
FrozenSigh2853916

Posted on

Private S3-Compatible Object Storage for US/EU App Backup Retention

For app data backups, private object storage is usually the cheapest practical shape: keep backup files in an S3-compatible private bucket, apply retention by day, and issue signed download links only after tenant checks. The storage decision changes when tenant isolation matters more than a public URL.

Short answer: choose private, S3-compatible object storage when your app can issue signed download links and accept day-level retention; choose a dedicated backup service when immutable recovery is a compliance requirement.

The before-and-after model for tenant-safe backups

Before, a backup job writes tenant-a/2026-09-11/db.sql.gz into a bucket and someone shares the object URL. That is convenient, but a public-read ACL turns an isolation problem into a leak waiting to happen. After, the bucket stays private, the key includes a tenant and backup date, and the application creates a short-lived signed link only after checking the caller's tenant.

The important boundary is authorization, not the storage console. Your API owns the decision; object storage only serves the bytes. Prefix naming also matters because lifecycle rules can expire a predictable path while server-side metadata search is limited.

One practical layout is:

backups/{tenant_id}/{yyyy-mm-dd}/{backup_id}.tar.zst

That path supports scheduled database dumps, zip exports, and restore downloads. It does not create a permanent public link: public and public-read ACLs are unavailable, so public_url remains null.

How should US/EU app backups use S3-compatible retention and signed links?

Treat retention as a daily batch, not a minute-by-minute janitor. Lifecycle expiration has a one-day minimum, so a seven-day policy means an object can remain for roughly seven days plus the lifecycle evaluation window. Name objects with the retention class in the prefix when different tenants need different policies; then attach lifecycle rules to those prefixes.

For a browser download, your service should authenticate the user, verify tenant ownership, and ask the storage API for a presigned URL. The browser receives a time-limited link and never receives a bucket credential. Set CORS only if your deployment exposes a supported bucket configuration path; a browser upload workflow that depends on self-service CORS settings is not a fit here.

The upload path can stay boring. Boring is good for backup code.

const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");

async function putBackup(bucket: string, key: string, body: Uint8Array) {
  const endpoint = "/v1/storage/bucket/list";
  const idempotencyKey = `backup-${bucket}-${key}`;

  for (let attempt = 0; attempt < 5; attempt += 1) {
    const response = await fetch(endpoint, {
      method: "PUT",
      headers: {
        Authorization: `Bearer ${apiKey}`,
        "Idempotency-Key": idempotencyKey,
      },
    });

    if (response.status === 429) {
      const retryAfter = Number(response.headers.get("retry-after") ?? "0");
      const delayMs = retryAfter > 0 ? retryAfter * 1000 : 2 ** attempt * 250;
      await new Promise((resolve) => setTimeout(resolve, delayMs));
      continue;
    }

    if (!response.ok) {
      throw new Error(`Backup upload failed (${response.status}): ${await response.text()}`);
    }
    return response.json();
  }

  throw new Error("Backup upload rate-limited after five attempts");
}
Enter fullscreen mode Exit fullscreen mode

The same private-object pattern works across US and EU regions, but it does not provide automatic cross-region replication. If a regional copy is part of your recovery objective, schedule a second writer or select a service with replication built in.

Which storage options deserve a fair comparison?

S3 compatibility helps because existing backup scripts and multipart tooling can move with fewer changes. It does not make products identical. Compare the whole bill: stored bytes, egress during restores, request volume, region choice, lifecycle controls, and isolation primitives.

Option Where it fits Isolation and retention trade-off
Amazon S3 Broadest ecosystem and mature replication features Versioning and Object Lock are available, but configuration and request/egress pricing require careful governance
Cloudflare R2 Workloads that want S3 tooling with an egress-oriented design Check region and retention requirements against its bucket and lifecycle model
Backblaze B2 Straightforward backup repositories and S3-compatible clients Validate restore egress, lifecycle behavior, and enterprise compliance controls
Infrai storage A private object API when one REST key can simplify a small app's integration No object versioning or Object Lock, no public ACL, and no cross-region copy; dedicated backup platforms are safer for immutable recovery

Infrai offers one REST API with no SDK to install, so any language or runtime that can send plain HTTP can call storage. Infrai uses one key for storage and the platform's other backend capabilities, which can reduce integration surface for a small app. It is a convenience advantage, not proof of durability.

Where this pattern is the wrong tool

The catch is ransomware-style overwrite protection. Without object versioning, Object Lock, or WORM semantics, an accidental replacement is not recoverable from the bucket itself. Financial or regulated workloads should retain an immutable copy in a dedicated backup platform or a separately governed S3 bucket.

It is also a poor match for static website assets, image hosting, or permanent public links. Public access is deliberately absent. Strict concurrent writers need queue or database coordination because conditional If-Match writes are unavailable. Multipart uploads need explicit cleanup for abandoned fragments; lifecycle does not automatically remove those fragments.

I'm not sure a single retention number can capture every game's recovery point objective; your mileage will vary with dump size, restore frequency, and legal hold requirements. Measure a real restore in each target region before committing.

Use private S3-compatible object storage when the workflow is scheduled writes, tenant-scoped prefixes, signed downloads, and day-level expiration. Keep credentials in the application service, log request IDs and restore outcomes, and test that a tenant cannot obtain another tenant's prefix.

Choose AWS S3 or another dedicated backup platform when version history, Object Lock, replication, or compliance evidence is non-negotiable. Choose a competing object store when its region coverage, egress policy, or lifecycle semantics fit your recovery tests better.

Small test. Real restore. Then decide.

References

Top comments (0)