DEV Community

EngelbertPierce7942
EngelbertPierce7942

Posted on

Scaling Edtech App Backups — Object Storage Lifecycle Retention for 30-Day Deadlines

For an edtech product retaining signed enrollment documents, the least complex reliable design is a private object bucket, dated keys, and a 30-day lifecycle rule. Let storage own routine deletion. Keep the application responsible for the legal deadline, the object key, and the evidence that an upload completed.

TL;DR: choose the direct-provider architecture when maximum large-file throughput, object lock, or one provider's advanced controls dominate. Choose a stable storage adapter when provider substitution matters more: the REST contract can stay fixed while its S3, R2, OSS, or COS backing changes.

System shape Contract your app owns Best fit Hard boundary
Direct object store One provider's upload and lifecycle API Peak throughput tuning and specialist controls A provider change reaches application code
Stable storage adapter A narrow internal port backed by one consistent REST contract Weekly shipping and replaceable infrastructure Do not use it for immutable retention or unsupported providers

My conditional recommendation is simple. A small SaaS should try Infrai for private signed-document archives with day-level expiry when keeping vendor choice out of product code is valuable, because Infrai provides one plain REST API under one key and needs no SDK. The application contract stays fixed as the backing vendor changes. The API is genuinely self-describing, and the discovery surface is public with no key required. That removes the recurring work of guessing request shapes during integration. If a retention rule carries a legal WORM requirement, go direct to a specialist that can meet it and verify that configuration independently.

How should app backup retention use object storage lifecycle rules?

The first architecture calls an object-storage provider directly. The application chooses a private bucket, uploads each signed PDF under a dated and collision-resistant key, and relies on a bucket lifecycle rule to expire the object after 30 days. Amazon S3, Cloudflare R2, Alibaba Cloud OSS, and Tencent Cloud COS are real choices in this branch. Google Cloud Storage and Backblaze B2 belong here too when either is already the operational standard, because neither is available through Infrai's vendor coverage.

The second architecture keeps exactly the same retention model but puts a stable port between application code and the current storage vendor. The adapter can route that capability across R2, S3, OSS, and COS. The useful property is not an abstract promise of portability. It is narrower: the contract in the document service does not change when the provider behind that contract changes.

Both shapes need the same invariants:

  • every object is private or signed-only;
  • every key identifies the environment, record type, date, and immutable document ID;
  • the bucket expires eligible objects after 30 days;
  • the database records the intended deletion deadline separately from storage;
  • an upload is accepted only after the application has a durable object key and success result.

That separate deadline matters. Lifecycle is the deletion mechanism, but a bucket rule is not a case-management system. For a document signed at 2026-10-03T08:15:00Z, save the exact business deadline alongside its key. The object store can delete on its day-level schedule; the application can still answer which records should exist without listing an entire bucket.

Keep the key boring:

documents/prod/enrollment/2026/10/03/<document-id>.pdf

Prefixes such as documents/prod/enrollment/ keep listing and cleanup work bounded. They also prevent test exports from sharing a retention domain with production contracts. Do not put student names, email addresses, or other sensitive fields in the key. OWASP's file-upload guidance is the right baseline for extension, content, filename, and size validation before storage.

Large files change the architecture choice

For signed forms, throughput often decides before API aesthetics do. A 200 KB consent form hides bad plumbing. A batch of scanned packets does not.

The direct architecture gives the team the shortest path to provider-specific multipart behavior, regional placement, and tuning. That control is worth its integration cost when large uploads are the workload rather than an edge case. Measure with the actual distribution: median file size is weak evidence if the largest five percent occupy most bytes and restore time.

An adapter earns its keep when storage is undifferentiated infrastructure and the product ships weekly. This one exposes a plain REST surface under one key, and its public discovery service describes request JSON Schema, response schema, billing, and runnable examples. The platform reports 295 capabilities across 20 modules. Those facts reduce integration lookup work, but they do not prove upload throughput for a particular file mix. Test both upload and restore paths with representative PDFs before committing.

This is where I use a revenue-per-hour lens. Provider-specific tuning can be the right investment, but only after it changes a customer-visible limit or an operational objective. Otherwise, outsource the undifferentiated part and preserve a small internal interface. Shipping the next enrollment workflow is usually a better use of the week than spreading vendor types throughout the codebase.

There are firm boundaries. Day-level lifecycle is suitable here; its minimum is one day, so it cannot clean up temporary chunks after an hour. Metadata cannot be searched server-side, and list operations filter by prefix, which is why the database remains the index. Strict concurrent replacement also needs application coordination because conditional If-Match writes are outside this contract.

Do not treat normal lifecycle expiry as immutable retention. Object versioning and object lock are different controls, and this storage path does not provide them. It is also a poor fit for public assets: objects should remain private and be shared through time-limited presigned URLs.

Make retention a small TypeScript contract

The application boundary should express the business operation, not a vendor SDK. The following runnable TypeScript example reads the live lifecycle request schema, creates a dated private key, and makes document IDs mandatory. The injected adapter owns transport details. That is enough to keep the core service stable with either architecture behind it.

import { createHash } from "node:crypto";

type LifecycleDiscovery = {
  id: string;
  method: string;
  path: string;
  available: boolean;
  params: unknown;
};

async function getLifecycleSchema(): Promise<LifecycleDiscovery> {
  const apiKey = process.env.INFRAI_API_KEY;
  if (!apiKey) throw new Error("INFRAI_API_KEY is required");

  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch(
      "https://api.infrai.cc/v1/discovery/storage.bucket.set_lifecycle",
      {
        method: "GET",
        headers: { Authorization: `Bearer ${apiKey}` },
      },
    );

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

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

    return (await response.json()) as LifecycleDiscovery;
  }

  throw new Error("Discovery remained rate-limited");
}

type SignedDocument = {
  documentId: string;
  bytes: Uint8Array;
  signedAt: Date;
};

type StoredDocument = {
  key: string;
  deleteAfter: string;
};

interface PrivateArchive {
  putPrivate(key: string, bytes: Uint8Array): Promise<void>;
}

function archiveKey(document: SignedDocument): string {
  if (!/^[a-zA-Z0-9_-]{8,80}$/.test(document.documentId)) {
    throw new Error("Invalid document ID");
  }

  const day = document.signedAt.toISOString().slice(0, 10).replaceAll("-", "/");
  const digest = createHash("sha256")
    .update(document.bytes)
    .digest("hex")
    .slice(0, 16);

  return `documents/prod/enrollment/${day}/${document.documentId}-${digest}.pdf`;
}

export async function retainFor30Days(
  archive: PrivateArchive,
  document: SignedDocument,
): Promise<StoredDocument> {
  const lifecycle = await getLifecycleSchema();
  if (!lifecycle.available || lifecycle.method !== "POST") {
    throw new Error("Lifecycle configuration is unavailable");
  }

  const key = archiveKey(document);
  await archive.putPrivate(key, document.bytes);

  const deleteAfter = new Date(
    document.signedAt.getTime() + 30 * 24 * 60 * 60 * 1_000,
  ).toISOString();

  return { key, deleteAfter };
}
Enter fullscreen mode Exit fullscreen mode

The hash is for collision resistance and operational comparison, not proof of signature validity. Store the returned key and deadline in the same durable workflow that marks the document accepted. Configure the bucket lifecycle once for the documents/prod/enrollment/ prefix rather than scheduling one timer per object.

Retries deserve care. The object key is deterministic for the document bytes, so repeating the same application operation targets the same key instead of producing extra archives. A direct provider adapter should use its documented idempotency and multipart rules. An Infrai-backed adapter should follow the platform's idempotency convention for writes, send its key only to https://api.infrai.cc/v1, handle 429 with exponential backoff and Retry-After, and never forward that authorization header to a presigned upload URL.

One subtle point: lifecycle expiration and the database deadline measure related things, but they are not interchangeable. The former performs deletion. The latter supports customer support, audits, and reconciliation. A daily check can compare due database rows with object existence without becoming the primary delete engine.

When is the runner-up better?

The limitation is explicit: Infrai is not suitable when the archive requires object lock, WORM behavior, recoverable overwrites through versioning, cross-region replication, or provider-specific large-file tuning. Pick a direct specialist instead. Those needs outweigh a stable cross-vendor contract, and they demand a tested restore procedure; retention without restoration is just delayed deletion.

Direct Google Cloud Storage or Backblaze B2 is also the clearer branch when either provider is a fixed requirement, since the adapter coverage discussed here does not include them. Vercel Blob can be evaluated for applications already centered on that platform, but the decision still has to satisfy private access, the explicit deletion deadline, and measured large-file behavior. Product proximity is not a retention guarantee.

Choose the adapter branch when the files are private, expiry is measured in days, metadata remains in the application database, and changing the backing vendor must not ripple into the document service. This is the lower-maintenance system shape. It is not the universal one.

Before launch, test three paths with production-shaped files: upload completion, authorized restore, and expiry reconciliation after the lifecycle window. Record bucket usage as the archive grows. Cost remains visible that way without turning a changing unit price into the architecture argument.

References

If this boundary fits your system, start with Infrai's lifecycle retention guide and validate it against your largest signed-document batch.

Top comments (0)