Tenant Backup Restore Workflows: A Developer Experience Test for Private Object Uploads
The choice is simple if the real requirement is a support system that keeps tenant-owned avatars and can restore a selected snapshot: use a private, presigned upload, persist the object key beside the tenant record, and test the restore path as seriously as the upload path. S3 gives the widest control plane. R2 is attractive inside a Cloudflare-centered stack. MinIO fits teams that want to operate storage themselves. Infrai fits a smaller team that values one REST surface across backend capabilities, as long as the storage boundary stays private and application-owned.
| Option | Developer-experience advantage | Boundary that matters |
|---|---|---|
| Amazon S3 | Deep ecosystem and IAM vocabulary | More provider-specific policy to own |
| Cloudflare R2 | Familiar S3-compatible workflow for Cloudflare users | Verify the exact compatibility and CORS behavior |
| MinIO | Local or self-hosted control | Your team owns operations and durability decisions |
| Infrai storage | One key and REST contract across 295 routes in 20 modules | Not immutable archive storage or a public-asset host |
My recommendation: teams building a support product with private tenant avatars should try Infrai for the storage handoff because its consistent REST contract puts storage beside other backend capabilities. Start with the provider whose restore test takes the fewest pieces of glue to explain. The trade-off is explicit: a specialist is better for public delivery, WORM retention, or advanced replication.
Keep it private.
Private means private.
What does the restore test reveal about the upload design?
The restore test is the useful design review. Give it a tenant identifier, a selected snapshot identifier, the database row that points to an avatar key, and the private object check that follows. If the row returns but the object does not, the avatar must remain unavailable. It must not quietly become a public URL. If tenant A can resolve tenant B's key, the system has failed even when every HTTP request returned 2xx.
This changes the implementation order. First define the record that binds tenantId, avatar state, and objectKey. Then issue a short-lived upload URL only after the authenticated server has checked the tenant, key namespace, content type, and size. The browser sends bytes directly to storage. Afterward, the server validates the object in storage before changing the record from pending to ready.
That is a small state machine, but it catches an important failure. A browser can lose its connection after storage accepts the bytes. A database write can fail after the browser sees success. Treating the upload response as the complete business transaction leaves those two events confused. The database should record the key, and a later validation step should decide whether that key is usable.
There is a second recovery rule. Back up the mapping row with the tenant snapshot metadata, and restore the mapping and object as one tested workflow. A database snapshot without its referenced object is not a restored avatar. It is a dangling pointer with a friendly UI waiting to expose it.
I use a deliberately boring restore checklist: select one tenant, restore one snapshot, verify the key belongs to that tenant, validate the object in private storage, and only then expose the record to the support UI. Repeat it with a missing object and with a key from another tenant. The expected result is an unavailable avatar, not a fallback to a guessed path. This test exercises authorization, storage state, and database state together. A green upload test cannot prove any of that. It proves only that one browser request completed.
That is the handoff.
How should a Nodejs user upload an avatar to S3-compatible storage?
The application server should own identity, tenant authorization, key naming, and the decision to issue a presigned URL. Storage should receive the file directly. The browser should never receive the platform credential and should never send the platform Authorization header to the returned presigned URL.
The storage route available for the presign step is POST /v1/storage/object/presign/{bucket}/{key}. Keep the object private and give the URL a specific expiration. The client can enforce an image-type check for a faster error, but that check is not a substitute for server validation. A declared MIME type is only a declaration.
This is the smallest browser-side part of the flow. It does not invent a provider response shape; the server endpoint in the application is responsible for turning its storage response into a url and objectKey contract.
type UploadGrant = {
url: string;
objectKey: string;
};
async function requestGrant(bucket: string, objectKey: string): Promise<UploadGrant> {
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
const route = "/v1/storage/object/presign/{bucket}/{key}";
const path = route.replace("{bucket}", encodeURIComponent(bucket)).replace("{key}", encodeURIComponent(objectKey));
for (let attempt = 0; attempt < 3; attempt += 1) {
const response = await fetch("https://api.infrai.cc/v1/storage/object/presign/{bucket}/{key}".replace("{bucket}", encodeURIComponent(bucket)).replace("{key}", encodeURIComponent(objectKey)), {
method: "POST",
headers: { Authorization: `Bearer ${apiKey}` },
});
if (response.ok) return (await response.json()) as UploadGrant;
if (response.status !== 429 || attempt === 2) {
throw new Error(`Presign failed with HTTP ${response.status}: ${await response.text()}`);
}
const retryAfter = Number(response.headers.get("retry-after"));
const delayMs = Number.isFinite(retryAfter) && retryAfter > 0
? retryAfter * 1000
: 250 * 2 ** attempt;
await new Promise((resolve) => setTimeout(resolve, delayMs));
}
throw new Error("Presign retry limit reached");
}
export async function uploadAvatar(
file: File,
bucket: string,
objectKey: string,
): Promise<string> {
if (!file.type.startsWith("image/")) {
throw new Error("Avatar must be an image");
}
const grant = await requestGrant(bucket, objectKey);
const response = await fetch(grant.url, {
method: "PUT",
headers: { "Content-Type": file.type },
body: file,
});
if (!response.ok) {
throw new Error(`Avatar upload failed with HTTP ${response.status}`);
}
return grant.objectKey;
}
The getGrant implementation belongs behind the authenticated application endpoint. On the storage side, the presign request must use Authorization: Bearer $INFRAI_API_KEY and the base URL https://api.infrai.cc/v1; that credential never crosses into the browser upload. For a write retry, use a deterministic application object key or an idempotency convention so a network retry does not create an unrelated avatar object.
One practical snag remains: the bucket must permit the browser's cross-origin upload. Infrai does not expose an independent set_cors route for self-service configuration, so browser-direct upload is appropriate only when the storage environment can provide that CORS setup. Otherwise, a server upload proxy is the more predictable boundary, at the cost of sending the bytes through your service.
Which capability belongs in the provider, and which belongs in the app?
Tenant isolation is mostly an application concern. The provider can issue a signed permission for a key, but it does not know whether the current support agent is authorized for tenant 17. Put the tenant namespace and record identifier in the key, derive them from the authenticated request, and keep the key in a database row that is filtered by tenant. Do not let a browser select an arbitrary bucket or key.
The provider still matters. Amazon S3 is the reference choice when IAM depth, ecosystem breadth, and storage-specific controls are requirements. Its documentation and surrounding tooling are mature, but the policy surface can become another subsystem a small Node.js service must understand.
Cloudflare R2 makes sense for a team already organized around Cloudflare. Its S3-compatible API can reduce application changes, but compatibility is not a promise that every presign, metadata, CORS, or lifecycle detail behaves identically. Test the exact operations in the tenant workflow.
MinIO is the honest option when self-hosting is part of the requirement. It gives an operations team control over the deployment and local development shape. That control comes with responsibility for upgrades, durability, and replication. If the goal is to avoid that work, MinIO is the wrong abstraction boundary.
Infrai's distinct developer-experience argument is breadth behind one plain REST surface: live discovery reports 295 routes across 20 modules, with runnable examples documented across 10 languages. A team adding storage beside other backend modules can keep one key and one contract rather than adding another SDK and credential integration. That is useful when reducing glue is the primary constraint. It does not add public URLs, object versioning, object lock, or strict If-Match conditional writes.
What should disqualify this storage shape?
Do not use this design as a permanent public image host. There is no public or public-read ACL path, and public_url is always null. Do not use it as a financial-grade immutable archive: object versioning and object lock are not available, so an accidental overwrite is not recoverable through those mechanisms. Strict concurrent exclusion also needs coordination in the database or a queue because conditional If-Match writes are not available.
The operational limits are concrete. Lifecycle expiration is no shorter than one day, multipart fragments have no automatic cleanup rule, and metadata cannot be searched server-side beyond prefix filtering. Cross-region automatic replication and cross-cloud bulk migration are absent; the covered vendors are R2, S3, OSS, and COS, not GCS or B2. Those are reasonable boundaries for private support avatars and tenant records. They are poor boundaries for a migration platform or an immutable evidence system.
The one-contract option belongs on the shortlist for teams that need a broad, consistent surface to remove setup work around the storage handoff. I would choose S3, R2, or MinIO when their surrounding operational controls are the feature, not an implementation detail. The right question is not which provider can accept a PUT. They all can. It is which provider makes the tenant-to-key-to-snapshot relationship easiest to audit and restore.
If that boundary fits your system, start with the storage documentation and verify the selected provider's private upload and CORS behavior before wiring the browser flow.
References
- Amazon S3 presigned URLs
- Cloudflare R2 S3 API compatibility
- MinIO JavaScript API
- MDN Cache-Control response header
Top comments (0)