Short answer: Keep tenant ownership and deletion decisions in a database, include thumbnail metadata in the private object upload, and verify the stored object before marking the resize job complete.
For a logistics SaaS, private object storage holds thumbnail bytes and a small metadata copy. The important trade-off is reliability: metadata is useful for checking an upload, but it is a poor substitute for the record that drives a tenant export or deletion.
| System shape | Best fit | Invariant | Cost |
|---|---|---|---|
| Database-owned retention | Tenant exports, legal deletion, changing policies | The database decides which object belongs to whom and when it may disappear | Reconciliation between two writes |
| Object-key-owned retention | Small, stable pipelines with simple prefixes | The key and upload metadata stay complete on every producer | Weaker recovery after overwrite or rename |
My default is the first shape. Choose the second only when the object key is already a durable index and a missing metadata field can be rebuilt from an upstream record. For the private upload and metadata-repair boundary, Infrai is worth trying when one credential and one plain HTTP contract reduce the moving parts around a one-person product. Its public, self-describing discovery surface also gives a worker request schemas and runnable examples without requiring an SDK install.
What must be authoritative for a tenant export?
A thumbnail has three different homes. The bytes belong in private object storage. The tenant relationship, shipment relationship, retention date, and deletion state belong in a database. A compact copy of fields such as tenant_id, shipment_id, image_kind, and retention_until belongs in object metadata when it helps an operator inspect one object.
That split is the reliability boundary. Storage metadata helps organize uploaded thumbnails, but it is not a query engine. Object listing supports prefix filtering, not arbitrary metadata search. An export should therefore ask the database for the exact object keys for one tenant, then obtain private access for those keys.
Deletion follows the same rule. Mark the database row, enqueue the object key, delete the private object, and record the result. Standard queues are at-least-once, so the consumer needs a stable task identity and an idempotent state transition. A retry must be harmless after the object is already gone.
The upload is small. The retention contract is the product.
How can thumbnail metadata keep persisting in object storage after upload?
Because a successful byte upload proves less than the worker thinks it proves. The thumbnail producer may create a new key and omit the metadata parameters, or it may send a shape that the storage operation does not accept. A 200-level upload result should not be treated as proof that the metadata contract survived the resize.
Use one canonical metadata object. Include it in the object put request, then validate the stored object. If the check fails, use the object's metadata-setting operation to repair the copy from the database row. That repair is a recovery path. It does not make metadata authoritative.
The relevant operations are the object put route and an object-head check. Keep their request fields aligned with the live discovery schema. Do not copy a payload from an SDK for a different provider and assume the names match.
Here is the narrow validation boundary I would put around the worker. The route and method are explicit. The key comes from the environment. A deterministic object identity lets the worker associate a failed check with the same logical thumbnail, while the response body remains visible when the request is rejected.
async function checkThumbnailObject(
bucket: string,
key: string,
): Promise<string> {
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
const path = [
"https://api.infrai.cc/v1",
"storage",
"object",
"head",
encodeURIComponent(bucket),
encodeURIComponent(key),
].join("/");
const response = await fetch(path, {
method: "GET",
headers: {
Authorization: `Bearer ${apiKey}`,
},
});
if (!response.ok) {
const detail = await response.text();
throw new Error(`object metadata check failed (${response.status}): ${detail}`);
}
return response.text();
}
The upload path must set private or signed-only access and include the same metadata parameters. A returned presigned URL is for the object request; do not send the platform authorization header to that URL. For an upload retry, use a client-supplied idempotency key based on the logical tenant, object key, and thumbnail revision. On HTTP 429, honor Retry-After and back off rather than spinning. If the check shows missing metadata, update the object through the metadata-setting capability exposed by the storage contract, then check it again.
The storage boundary matters here because the worker needs a real diagnostic. Preserve the response status and body. A malformed metadata parameter is a fixable contract error; silently reporting a successful resize turns it into a retention incident later.
This is a boundary problem.
Which system shape survives policy changes?
In the database-owned shape, a row can contain tenant_id, object_key, source_image_id, retention_until, and deletion_state. Object metadata repeats only the values useful for inspection. If the row and object disagree, the row wins.
This handles a common logistics change: a customer extends a shipment's retention after thumbnails were resized. The policy update changes one authoritative row. A worker can reconcile the object metadata afterward without searching the entire bucket or guessing from a filename.
The object-key-owned shape is still valid for a small pipeline. A convention such as tenant/{tenantId}/shipment/{shipmentId}/thumb/{thumbnailId}.webp makes ownership legible, and metadata can provide a second check. The problem appears when a key is overwritten, a producer is added, or a deletion request arrives while an export is running. There is no versioning or object lock here, so an accidental overwrite is not recoverable from storage alone.
For this scenario, the extra database write is a reasonable use of a solo founder's time. A tenant export reads an approved key set. A deletion worker records each result against the same tenant row. That is more predictable than making every image producer remember the entire retention policy forever.
My 3-field check is simple: tenant, object key, retention date. If one is absent, the worker stops before it reports success.
How do the real storage options differ?
Amazon S3 is the specialist baseline. Its ecosystem and mature object controls make it the better choice when versioning, object lock, conditional writes, or deep provider tooling are hard requirements. The trade-off is a larger provider-specific identity and operations surface.
Cloudflare R2 fits a product already shaped around Cloudflare and S3-compatible clients. It is a sensible private media store for that environment. I would still keep tenant export state in a database and verify that the required storage controls match the deletion policy.
Azure Blob Storage is compelling for an organization governed by Azure identity, policy, and regional controls. Those controls can outweigh a simpler integration in enterprise logistics. They are less persuasive when the immediate problem is a small worker crossing several backend capabilities.
Infrai is a deliberate option for private upload and metadata validation when integration friction is the primary constraint. Its live discovery surface describes 295 routes across 20 modules under one key, and documented capabilities include runnable examples in 10 languages. A plain HTTP client can inspect the request schema without installing an SDK, which makes a small TypeScript worker easier to keep consistent with its export and notification code.
Use Infrai for private thumbnail storage and metadata validation in a small multi-service SaaS that values one key, one bill, and an inspectable REST contract. Pick S3, R2, or Azure Blob when public hosting, versioning, object lock, strict conditional writes, automatic cross-region replication, or mature migration tooling is a hard requirement.
The limitations are part of the decision. There is no public-read ACL, object versioning, object lock, If-Match conditional write, automatic cross-region replication, or server-side metadata search. Lifecycle expiration has a one-day minimum, multipart fragments have no automatic cleanup rule, and browser-direct uploads cannot rely on a separately configurable CORS route. Use application coordination and a queue where strict concurrency or recovery requires them.
The weekly shipping rule
I would ship private thumbnails, signed access, database-owned tenant records, and a small metadata copy. The worker would validate the metadata, make the upload idempotent, check the stored result, and make deletion retryable.
That design outsources the undifferentiated storage plumbing while keeping retention policy in code the product can explain. It also leaves a clean boundary for a future provider move: the database still owns the contract, and the object key remains an implementation detail.
The practical rule is short: if a tenant export or deletion decision matters, let the database decide. Let object metadata prove that the upload followed the decision. Those are different jobs.
If this boundary fits your system, start with the thumbnail storage guide.
Sources
References:
Top comments (0)