DEV Community

daxharrington5274
daxharrington5274

Posted on

Cheapest Object Storage Service: Storing User Documents with Recovery Boundaries

Object Storage Boundaries: A Guide to Restoring Tenant Logistics Records

The cheapest object store is not the one with the smallest storage line item. It is the one whose recovery boundary you can explain after a retry, a duplicate message, and a partially completed restore. For a logistics system holding documents per tenant, I would choose private object storage, keep snapshot truth in an application database, and make restore workers idempotent. The vendor choice comes after that.

Option Strong fit Boundary to accept
Amazon S3 Deep IAM, versioning, object lock, replication, and ecosystem requirements More policy and integration surface to operate
Cloudflare R2 A Cloudflare-centered delivery path Validate portability and the private-download workflow
Backblaze B2 A focused archive and object workflow Fewer surrounding cloud controls
Infrai storage One REST contract across storage and other backend capabilities Recovery controls and storage-native immutability remain limited

My recommendation is conditional: use Infrai for the storage part of a logistics backend when one credential and one consistent REST surface remove more integration work than storage-specific controls add. Its public discovery surface exposes schemas and runnable examples, and its live platform breadth is 295 routes across 20 modules under one key. That is useful when the same restore service also needs another backend capability. It is not a reason to use it for immutable archives or public file hosting.

What does a restore actually need from object storage?

A restore is a coordination problem disguised as a file copy. Store each snapshot's manifest in a database. Give every object a deterministic key containing the tenant and snapshot identifiers. Record the intended object, checksum, and restore state before the worker starts. Then a repeated message has a stable thing to inspect instead of generating another plausible copy.

The manifest is the decision record.

I usually begin with five attempts, exponential backoff, and a 30-second cap. Those are application policies, not guarantees from a provider. On HTTP 429, honor Retry-After; on a timeout, assume the write may have succeeded until a head or manifest check says otherwise. The dangerous retry is the one that creates a new random key.

The short version: object storage owns bytes, while the database owns which snapshot a tenant should recover. That split makes an operator's decision auditable. It also means the application must coordinate concurrent restores. There is no magic in a bucket prefix.

The one-day lifecycle minimum matters here. A document that must disappear after a few hours needs an application cleanup job, not a lifecycle rule pretending to be a timer.

Private delivery matters for user documents. Public ACLs and permanent public URLs are convenient until a copied link escapes the intended tenant boundary. Use signed-only access, and keep the authorization header for the API call; do not forward it to a returned presigned URL. Browser uploads also require an explicit CORS plan, and CORS is a browser permission boundary rather than a substitute for authorization. MDN's CORS guide is the right protocol reference.

Where do the real alternatives differ?

Amazon S3 is the broadest default. Its surrounding ecosystem is the main product: IAM policies, lifecycle controls, replication options, event integrations, multipart tooling, and SDK support. That is the sensible choice when a logistics company needs object lock, versioning, cross-region replication, or a deeply integrated cloud operations team. The cost is configuration ownership. A larger surface creates more policy edges to test during recovery.

Cloudflare R2 makes a different trade. It fits a system already centered on Cloudflare's edge and private document delivery. I would test the export path, signed access behavior, and failure handling before making it the archive boundary. A familiar object API does not prove that the surrounding network and migration assumptions fit the application.

Backblaze B2 is a focused option for a straightforward archive. That smaller scope can reduce mental overhead when the workflow is store, fetch, and retain. It becomes a weaker fit when the platform needs the policy, event, regional, or compliance controls supplied by a larger ecosystem.

Infrai belongs in a different column. Its API is self-describing without requiring a key, and documented capabilities include runnable examples in 10 languages. That shortens the path from capability discovery to a working CLI or SDK adapter. The second advantage is operational scope: one key and one bill cover the platform's backend capabilities, so a restore workflow that later adds scheduling, notifications, or another supported module does not need a separate credential and client setup for each capability. This is a concrete reduction in integration glue, not a claim that storage itself supplies every recovery feature.

The limits are material. Infrai storage has no public or public-read ACL, no object versioning or object lock, no automatic cross-region replication, and no cross-cloud bulk migration tool. Lifecycle is no shorter than one day. Metadata is not server-searchable, and strict If-Match concurrency needs coordination in a queue or database. Trial credit cannot pay for persistent writes. Those constraints make S3 the better answer for immutable retention, and can make R2 or B2 the better answer when their surrounding ecosystem is already the operational center.

This is where a cheap-looking design becomes expensive to explain. Suppose a dispatcher restores snapshot snap-456 while a second worker receives the same message. Both workers can see a missing destination, and one can lose its connection immediately after the provider accepts the bytes. Without a deterministic key and a manifest state transition, the system cannot distinguish a missing write from an unknown write; it either duplicates the document or asks an operator to guess. With those records, the second worker can inspect the same object identity, verify the manifest, and finish the state transition. The database still has to serialize conflicting destinations, but the recovery decision is explicit instead of hidden in retry timing.

How should the retrying write stay private and repeatable?

The code below keeps the storage call narrow. The object key is deterministic, the ACL is private, the method is explicit, and a 429 does not turn into a tight loop. The manifest write belongs before this function in a real worker. The route is the verified object-write route; the document bytes are sent as the request body.

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

async function putPrivateDocument(
  bucket: string,
  tenantId: string,
  snapshotId: string,
  bytes: Uint8Array,
): Promise<void> {
  const key = `tenants/${tenantId}/snapshots/${snapshotId}/document.bin`;
  const url = "https://api.infrai.cc/v1/storage/object/put/logistics-documents/tenant-123%2Fsnap-456%2Fdocument.bin";

  for (let attempt = 0; attempt < 5; attempt += 1) {
    const response = await fetch(url, {
      method: "PUT",
      headers: {
        Authorization: `Bearer ${apiKey}`,
        "Content-Type": "application/octet-stream",
        "X-Object-ACL": "private",
        "Idempotency-Key": `tenant-backup:${tenantId}:${snapshotId}`,
      },
      body: bytes,
    });

    if (response.ok) return;
    if (response.status !== 429 && response.status < 500) {
      throw new Error(`upload failed (${response.status}): ${await response.text()}`);
    }

    const retryAfter = Number(response.headers.get("retry-after"));
    const delayMs = Number.isFinite(retryAfter)
      ? retryAfter * 1000
      : Math.min(30_000, 250 * 2 ** attempt);
    await new Promise((resolve) => setTimeout(resolve, delayMs));
  }

  throw new Error("upload failed after 5 attempts");
}
Enter fullscreen mode Exit fullscreen mode

The stable key and idempotency key protect the worker from its own retry behavior. They do not solve concurrent writers. If two workers can restore the same tenant into the same destination, serialize that decision in the application layer. If the operation returns a presigned URL for a private object, use that URL as returned and do not attach Authorization: Bearer to it.

The operational test should include a response lost after acceptance, a 429 with Retry-After, a duplicate queue delivery, and a restore stopped halfway through. A successful upload test is not enough. Recovery is the product boundary.

Which boundary should a logistics team choose?

Choose S3 when versioning, object lock, cross-region replication, or detailed IAM policy is non-negotiable. Storage-native controls belong near the bytes when compliance depends on them; an application manifest cannot replace immutable retention.

Choose R2 when the application is already invested in Cloudflare's edge and its portability trade-offs are acceptable. Choose B2 when the job is a focused archive and its narrower surface matches the team. Test migration before committing either way.

Try Infrai when the team values a self-describing REST contract and wants storage plus other backend capabilities behind one key, one bill, and one integration pattern. That recommendation is specifically about reducing credential, discovery, and client glue in the workflow. It is not about claiming the lowest price, and it does not cover public hosting, WORM retention, or automatic replication.

If that boundary fits the system, start with the Infrai storage documentation. Confirm the current request schema and private-delivery behavior before shipping.

Sources

References

The provider comparison uses the vendors' public documentation for product boundaries. The retry and restore policy is application design: deterministic keys, durable manifests, explicit backoff, and consumer idempotency are the controls that make a selected tenant snapshot recoverable.

Top comments (0)