Short answer: resize logistics images in a worker, upload the thumbnail directly to a private S3-compatible bucket through a tenant-scoped storage adapter, and issue a short-lived presigned download URL only after an authorization check. Keep the original and thumbnail under different keys, and never make the bucket public just to simplify browser delivery.
| Design | Tenant isolation | App complexity | Use it when |
|---|---|---|---|
| Backend proxy for every byte | Easy to centralize, but the app handles all transfer traffic | Low at first, high under large uploads | Files are small or inspection must happen before storage |
| Direct upload with presigned URL | Strong when the key, bucket, and expiry are policy-controlled | Medium: signing, callbacks, and reconciliation | Large media should bypass the application process |
| Public object URL | Poor for private tenant media | Low | The image is intentionally public |
For a logistics platform, the middle row is the least complicated design that meets the real constraint: large media bytes do not pass through the Node.js app, while the application still owns the tenant decision. A presigned URL is a temporary capability, not proof that a caller belongs to a tenant.
Retry policy: tenant isolation is the first storage primitive
Start with the key namespace, but do not mistake a prefix for authorization. A key such as tenants/acme/shipments/waybill-7/thumb-320.webp makes cleanup and inspection legible; it does not stop a caller who can guess another key. The signing service must derive the tenant from the authenticated session, check shipment access, and only then sign a specific object operation.
Keep the bucket private. The browser receives a presigned download URL after the API has made that decision. The URL should expire soon enough to limit accidental sharing, but the exact lifetime belongs to the product's access pattern and threat model. I am not sure there is a useful universal default: a dispatcher on a fast office connection and a driver on a weak mobile connection have different needs. Your mileage may vary.
Tenant isolation also has a boring data model. Store tenantId, assetId, objectKey, contentType, byteLength, sourceObjectKey, and processing status in the application database. Do not accept tenantId from a browser as the authority. The request can carry an asset id; the server resolves the tenant relationship.
The failure mode worth designing around is a split write. The thumbnail upload can succeed while the database update times out, or the database row can exist while processing has not produced an object. Give each processing attempt an id and reconcile rows against the tenant-scoped key prefix. A cleanup worker can then distinguish an orphan from a slow job without scanning unrelated tenants.
One rule matters.
A signed URL grants delivery, not ownership.
Benchmark: what must a thumbnail worker record?
For thumbnails, resize before the final upload. The worker reads the source object, uses an image library to constrain dimensions, chooses an output format, and writes a new object key. The original stays immutable unless the product has a clear replacement policy. That separation makes retries idempotent: the same source version and transform profile map to the same thumbnail key.
The transform profile belongs in the key or in metadata. If a dispatcher later asks for 640 pixels instead of 320, do not overwrite the old result while another client may still be downloading it. A key like thumb/w320-q80.webp makes the output variant explicit.
Here is the application boundary I would use. The storage adapter owns S3-compatible request details; the worker owns image policy and tenant context. The example does not proxy a browser upload through Node.js, and it does not claim that a generic storage interface has one universal HTTP route.
import sharp from "sharp";
type TenantAsset = {
tenantId: string;
assetId: string;
sourceKey: string;
};
type StoredObject = {
key: string;
contentType: string;
byteLength: number;
};
type ObjectStore = {
get: (key: string) => Promise<Uint8Array>;
put: (input: {
key: string;
body: Uint8Array;
contentType: string;
}) => Promise<StoredObject>;
};
function thumbnailKey(asset: TenantAsset, width: number): string {
return `tenants/${asset.tenantId}/assets/${asset.assetId}/thumb-w${width}.webp`;
}
export async function buildThumbnail(
store: ObjectStore,
asset: TenantAsset,
width = 320,
): Promise<StoredObject> {
const source = await store.get(asset.sourceKey);
const body = await sharp(source).resize({ width, withoutEnlargement: true }).webp({ quality: 80 }).toBuffer();
return store.put({
key: thumbnailKey(asset, width),
body,
contentType: "image/webp",
});
}
The adapter should make retries safe. If the object key is deterministic, a retry can write the same logical result rather than creating a second random thumbnail. If overwrites are unacceptable, include a source version or content digest in the key and make publication a database state transition. Do not use the file name supplied by a camera or browser as a tenant boundary.
Validate image type and dimensions before expensive work. A declared Content-Type is metadata, not a complete inspection result. Set limits for source bytes, pixel dimensions, and processing time. A small compressed file can still expand into an unreasonable number of pixels.
How should a Node.js image thumbnail resize upload flow protect each tenant?
The API should issue a presigned upload URL for one expected object key, content type, and expiry. The client uploads directly to object storage. After the upload, the API verifies the object metadata it cares about, records the source asset, and queues thumbnail generation. For a worker-generated thumbnail, the API can sign a download URL only after the thumbnail record says the object is ready.
Do not sign a broad prefix. Do not let the client choose a bucket. Do not turn an asset id into a key without checking the tenant relationship. Those shortcuts make a multi-tenant system look simpler while moving its hardest rule into an untrusted caller.
A minimal TypeScript service can keep signing behind an interface so tests do not need live storage credentials:
type UploadGrant = {
url: string;
objectKey: string;
expiresAt: number;
};
type DownloadGrant = {
url: string;
expiresAt: number;
};
type Signer = {
signUpload: (input: {
objectKey: string;
contentType: string;
expiresInSeconds: number;
}) => Promise<UploadGrant>;
signDownload: (input: {
objectKey: string;
expiresInSeconds: number;
}) => Promise<DownloadGrant>;
};
async function createUploadGrant(
signer: Signer,
tenantId: string,
assetId: string,
contentType: string,
): Promise<UploadGrant> {
const objectKey = `tenants/${tenantId}/assets/${assetId}/source`;
return signer.signUpload({ objectKey, contentType, expiresInSeconds: 600 });
}
async function createDownloadGrant(
signer: Signer,
objectKey: string,
): Promise<DownloadGrant> {
return signer.signDownload({ objectKey, expiresInSeconds: 120 });
}
The real authorization check is intentionally outside these helpers. A route handler should load the asset by assetId, verify the current principal can read that tenant's shipment, compare the stored object key with the requested variant, and only then call createDownloadGrant. The signer should never be the place where business access is inferred from a path string.
Record grant creation and object events without logging the full URL. A presigned URL contains authorization material. Log the tenant, asset, operation, expiry, and request correlation id; redact query parameters from application logs and error reports.
Cost and control in a logistics thumbnail pipeline
The decision is operational, not a popularity contest.
| Choice | Good fit | Cost or control trade-off |
|---|---|---|
| Direct S3-compatible provider integration | The team needs provider-specific lifecycle, replication, or access controls | The application owns SDK behavior, credential rotation, and provider coupling |
| A storage abstraction with one adapter contract | The team values portability and a small integration surface | The abstraction may not expose every provider-specific control |
| Self-hosted object storage | Storage location and operations are strategic requirements | The team owns durability, capacity, upgrades, backups, and recovery |
The catch is that an abstraction is not suitable when legal retention, replication, object locking, or audit requirements depend on a control it cannot express. Choose a direct provider integration in that case. Stick with the simple adapter when provider portability is a real requirement and the application can state its own invariants clearly.
Lifecycle policy is part of tenant isolation too. A deleted shipment should not leave thumbnails indefinitely, and abandoned multipart uploads need their own cleanup process. Object lifecycle management can express expiration rules, but the policy still needs an owner, a test, and an audit signal. The cleanup worker should use the database's deletion state and a tenant-scoped key pattern rather than treating an anonymous bucket listing as business truth.
For delivery, the safest default is a private bucket with temporary download grants. A public bucket is suitable for a deliberately public tracking gallery or static image catalog. It is not suitable for private shipment documents, driver identity images, or tenant-specific generated media.
I would benchmark three things before choosing a final design: upload completion time by file size, thumbnail worker latency by pixel dimensions, and authorization-to-download latency. Also measure retry amplification and orphan cleanup age. A single average hides the tenant or carrier segment that is actually failing.
Top comments (0)