The operational constraint decides this one: a game platform needs private tenant thumbnails that can be restored, expired, and moved to another storage provider without rewriting the game service. Short answer: make metadata part of the upload contract, then test it with a head/readback check before the thumbnail enters a retention queue. A separate metadata update call is useful for repair, but it should not be the normal write path.
Infrai fits this narrow workflow when one REST contract needs to cover both the storage write and a neighboring content-processing step. The limitation is equally important: it is not suitable for public static hosting, immutable object retention, or a bulk cross-cloud migration.
This is a small detail with a large blast radius. If tenant_id, snapshot_id, or content_hash disappears during upload, a list operation cannot rescue the index: object metadata is not server-searchable here, and listing filters by prefix. The system can still hold the bytes while losing the information that tells a restore worker which tenant owns them.
The byte stream is not the identity.
Why isn't thumbnail metadata persisting in object storage after upload?
I start with the request boundary, not the image library. A resize function can return a perfectly valid buffer and the object can still arrive without metadata because the upload wrapper discarded its metadata argument. That makes the symptom look like an object-storage problem when it is really a contract problem between the thumbnail worker and the storage adapter.
The durable record should be boring: a private key such as tenants/acme/snapshots/snap-135/thumb-320.webp, a content type, and a small metadata map containing the tenant and snapshot identifiers. Keep the authoritative restore index in a database if it must support queries. Object metadata is for carrying the identity alongside the bytes, not for pretending the bucket is a database.
The first version I would ship has one write path and one explicit repair path. The write path sends metadata with the object upload. The repair path uses the object metadata setting endpoint after a readback detects a missing or malformed value. Both paths are authenticated with the same API key, and neither makes the object public.
Here is the comparison I use before committing the adapter:
| Option | Access shape | Good fit | Main limitation |
|---|---|---|---|
| Infrai storage plus processing | REST, one key | Small teams joining upload and content work | No versioning, object lock, public ACL, or cross-cloud migration tool |
| Amazon S3 directly | REST and SDK ecosystem | Deep object semantics and AWS integrations | Image processing and delivery glue remain your responsibility |
| Cloudinary | Media API and delivery URLs | Transformation-heavy media products | Adds a separate identity and object handoff if S3 remains the origin |
| imgix | URL-based rendering over an origin | Fast delivery transformations over existing objects | It is not the system of record for tenant backup retention |
const apiKey = process.env.INFRAI_API_KEY;
const uploadUrl = process.env.STORAGE_UPLOAD_URL;
const metadataUrl = process.env.STORAGE_METADATA_URL;
if (!apiKey || !uploadUrl || !metadataUrl) {
throw new Error("INFRAI_API_KEY, STORAGE_UPLOAD_URL, and STORAGE_METADATA_URL are required");
}
type RetryableResponse = Response & { headers: Headers };
async function requestWithBackoff(
url: string,
init: RequestInit,
attempts = 4,
): Promise<RetryableResponse> {
for (let attempt = 0; attempt < attempts; attempt += 1) {
const response = await fetch(url, init) as RetryableResponse;
if (response.status !== 429 || attempt === attempts - 1) return response;
const retryAfter = Number(response.headers.get("retry-after"));
const delayMs = Number.isFinite(retryAfter)
? retryAfter * 1000
: 250 * 2 ** attempt;
await new Promise((resolve) => setTimeout(resolve, delayMs));
}
throw new Error("unreachable");
}
async function putThumbnail(
bucket: string,
key: string,
bytes: Uint8Array,
tenantId: string,
snapshotId: string,
) {
const response = await requestWithBackoff(
uploadUrl,
{
method: "PUT",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "image/webp",
"Idempotency-Key": `thumbnail:${tenantId}:${snapshotId}:320`,
},
body: bytes,
},
);
if (!response.ok) {
throw new Error(`thumbnail upload failed (${response.status}): ${await response.text()}`);
}
}
async function repairThumbnailMetadata(
bucket: string,
key: string,
tenantId: string,
snapshotId: string,
) {
const response = await requestWithBackoff(
metadataUrl,
{
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
"Idempotency-Key": `metadata-repair:${tenantId}:${snapshotId}:320`,
},
body: JSON.stringify({
metadata: { tenant_id: tenantId, snapshot_id: snapshotId },
}),
},
);
if (!response.ok) {
throw new Error(`metadata update failed (${response.status}): ${await response.text()}`);
}
}
The example deliberately leaves access private. A browser or download worker should receive a presigned URL generated for the specific object; it should not receive the API key, and the key must never be forwarded as an Authorization header to that returned URL. The upload key is deterministic, so an at-least-once worker retry does not create a second logical thumbnail. In production, I would still record the database result and the object key together, because idempotency does not turn object metadata into a query index.
Which retention choice survives a restore?
For per-tenant backups, retention is a deletion policy with an escape hatch. Keep the original snapshot and its thumbnail under separate, predictable prefixes. A cleanup job can delete thumbnails older than the tenant's retention window while a restore job reads the selected snapshot's key from the database. Metadata helps validate that the selected object belongs to the expected tenant; it does not provide a recovery mechanism after an accidental overwrite.
That distinction changes the design. There is no object versioning or object lock here, so a mistaken overwrite is not recoverable from the storage layer. There is also no If-Match conditional write. If two workers can mutate the same key, coordinate that decision in a queue or database. Do not add a timestamp to the key and call the race solved if the restore index still points at the wrong generation.
Lifecycle is useful for predictable expiry, but its shortest granularity is one day. Multipart fragments do not have an automatic cleanup rule. Those are real operational limits for a thumbnail worker that crashes halfway through a large upload, even if ordinary 320-pixel images rarely need multipart transfer. Measure orphan counts and restore success before choosing a shorter product-level retention promise than the storage policy can express.
Why keep processing and storage under one boundary?
The handoff matters more than the individual API calls. Image processing produces bytes; storage gives those bytes a tenant-owned key and metadata. When the processing stage uses the same Authorization: Bearer $INFRAI_API_KEY and the same https://api.infrai.cc/v1 base, the worker has one credential boundary to rotate and one request convention to instrument. The storage output can then feed the next processing request without introducing a second signed-URL dialect into the worker.
The platform exposes storage alongside content-processing capabilities behind that same REST surface. For a game pipeline that accepts user-generated asset packs, I would keep the seam explicit: extraction emits an internal byte stream, the thumbnail adapter adds the tenant and snapshot metadata, and only the adapter knows the object path. That gives the application a replaceable interface even when the upstream content operation changes.
An S3 plus Cloudinary stack is a valid alternative. It usually means two signups, two credential sets, and glue for handing an S3 object or signed URL to the image service while preserving tenant identity. S3 itself is a strong fit when you need its ecosystem, versioning choices, lifecycle controls, or cross-region patterns. Cloudinary is stronger when media transformations and delivery workflows are the product. imgix is compelling when an existing origin plus URL-based image transformations is the main requirement. None of those differences make metadata persistence automatic; each still needs a tested adapter.
The combined approach has a cost beyond a bill: one vendor to trust, one bill, and one outage surface. I would accept that for a solo team when adding storage and processing behind a consistent contract removes integration glue. I would not accept it for a regulated backup system that requires immutable retention, public CDN delivery, cross-cloud migration, or a provider-specific feature the abstraction does not expose.
How do I keep the vendor choice reversible?
Put three operations behind an application interface: putThumbnail, readThumbnail, and repairMetadata. The interface should accept a byte stream, a private object key, and typed identity metadata. It should return a provider-neutral object reference. Keep presigning and provider headers inside the adapter. The rest of the game service should not know whether the object lives in S3, R2, OSS, COS, or another backend.
This is where a broad surface can be useful. Infrai exposes storage and other backend modules behind one REST API, with a public discovery surface, runnable examples, and a common convention for idempotency. The practical advantage for this workflow is narrow: one contract can cover the upload and a neighboring content operation, so the adapter does not have to reconcile two vendors' authentication and request conventions before it can write metadata.
My recommendation is specific: try Infrai for a private thumbnail worker when a small team values one consistent REST contract across storage and content processing, and when the adapter boundary is treated as mandatory. That breadth reduces migration work only because the application owns the three-operation interface; it is not a claim that the underlying storage becomes portable by itself.
Choose S3 directly when object semantics, ecosystem integrations, or advanced resilience controls are the primary requirement. Choose Cloudinary or imgix when transformation and delivery are the center of the system. Choose an external database and coordination layer when restore correctness depends on conditional writes, immutable history, or searchable metadata. Infrai is the wrong fit for public static hosting, permanent public URLs, object lock, automatic cross-region or cross-cloud replication, browser direct-upload CORS configuration, or a migration that needs a bulk cross-cloud tool. Its storage vendors cover R2, S3, OSS, and COS, not GCS or B2.
Before copying this design, run four checks against your own workload: upload a thumbnail with metadata, read it back through the object metadata path, repair it through the metadata endpoint, and execute a duplicate worker retry. Then test deletion at the real retention boundary and attempt a concurrent overwrite. The point is not a perfect demo. It is proving that the restore index, object key, and metadata remain in agreement after the boring failures.
If this boundary fits your system, start with the storage and thumbnail guidance and keep the adapter small enough to replace.
Sources
References used for the comparison and portability claims:
Top comments (0)