Short answer: for a small gaming SaaS that stores product artwork and produces tenant-scoped exports, upload the original directly to object storage, enqueue thumbnail work after the upload is committed, and store each generated size as another object. Build exports from those stable objects. An image CDN can wait until delivery transformations become a bigger job than the game catalog itself.
The deciding constraint is large-file throughput. Artwork should not travel through the application server merely because a 320-pixel thumbnail is also needed. That couples the slowest byte transfer to application capacity and makes an export depend on live resizing. My trade-off is explicit: accept a queue and four visible asset states because they keep bulk bytes and image compute away from the API. I would spend more operational complexity only after demand proves it is necessary; a solo SaaS gets better revenue per engineering hour from a boring asynchronous path that can ship this week.
Should image thumbnail generation use object storage or request-time resizing?
Doing the resize inside the request looks like the smallest system. It is the smallest diagram, but the request now owns four different jobs: receiving a large original, validating it, decoding it, and writing derivatives. A retry can repeat expensive work. A client disconnect can leave an ambiguous result. A burst of new game artwork competes with ordinary API traffic.
Keep the application in the control plane instead. It issues a tenant-bound upload instruction, records the expected object key, and moves the asset from pending to ready only after storage confirms the original exists and the thumbnail worker has produced the required variants. The data plane carries the large file directly to storage.
This also creates a clean export rule: an export reads only ready asset records and references immutable derivative keys. It never asks a resizing service to invent a thumbnail halfway through building a ZIP or manifest. Predictability wins.
Keep it dull.
Use opaque IDs in keys rather than titles supplied by a tenant. One workable layout is tenants/{tenantId}/products/{productId}/assets/{assetId}/original beside thumb-320.webp. Authorization must still come from application data; a key prefix is organization, not proof of access.
The smallest implementation I would ship
The contract below leaves storage signing, image decoding, and queue delivery behind narrow interfaces. Those are undifferentiated components. The valuable code is the tenant state machine and export policy.
type AssetState = "pending" | "processing" | "ready" | "failed";
type Asset = {
tenantId: string;
productId: string;
assetId: string;
originalKey: string;
thumbnailKey: string;
state: AssetState;
};
interface ObjectStore {
exists(key: string): Promise<boolean>;
read(key: string): Promise<Uint8Array>;
put(
key: string,
body: Uint8Array,
metadata: { contentType: string; sourceKey: string }
): Promise<void>;
}
interface ImageProcessor {
thumbnail(input: Uint8Array, width: 320): Promise<Uint8Array>;
}
interface AssetRepository {
find(tenantId: string, assetId: string): Promise<Asset | null>;
setState(tenantId: string, assetId: string, state: AssetState): Promise<void>;
}
async function generateThumbnail(
tenantId: string,
assetId: string,
store: ObjectStore,
images: ImageProcessor,
assets: AssetRepository
): Promise<void> {
const asset = await assets.find(tenantId, assetId);
if (!asset) throw new Error("asset not found");
if (asset.state === "ready") return;
await assets.setState(tenantId, assetId, "processing");
if (await store.exists(asset.thumbnailKey)) {
await assets.setState(tenantId, assetId, "ready");
return;
}
const original = await store.read(asset.originalKey);
const thumbnail = await images.thumbnail(original, 320);
await store.put(asset.thumbnailKey, thumbnail, {
contentType: "image/webp",
sourceKey: asset.originalKey,
});
await assets.setState(tenantId, assetId, "ready");
}
Idempotency matters more than queue branding. The worker checks the destination first, uses a deterministic derivative key, and marks the asset ready only after the write completes. A repeated message converges on the same result. Production code should also validate the decoded image, cap its dimensions and decoded memory, reject unsupported formats, and record a bounded failure reason. Never trust the filename or declared media type alone. The export query must carry tenantId as a required parameter all the way to the repository; do not fetch by assetId and filter later. Tests should create two tenants with similarly shaped catalogs, then prove that each manifest contains only its own original and thumbnail keys. Add a test for a duplicated job and one for an export attempted while an asset is still processing. That combination tests the two boundaries that matter most: repeated execution and tenant isolation.
Object storage, dynamic delivery, or synchronous resizing?
There is no universal winner. The choice follows the work that must happen on the critical path.
| Path | Large-file path | Export behavior | Operational cost | Best fit |
|---|---|---|---|---|
| Stored derivatives from a worker | Original goes directly to storage | Reads stable, known keys | Queue, worker, and state transitions | A few known sizes and repeatable exports |
| Dynamic image delivery | Original goes to storage; variants are produced on demand | Must pin transformation rules or materialize export assets | Transformation policy, cache behavior, and another delivery boundary | Many sizes or presentation-led transformations |
| Resize during application upload | Original crosses the app server | Derivatives exist when the request succeeds | Long requests and coupled compute | Small, tightly bounded uploads at low concurrency |
For this game catalog, the first path matches the throughput constraint and the export contract. It adds a worker, yet removes large uploads and image decoding from the API request. That is a useful trade: one explicit asynchronous state is easier to operate than hidden work inside every request.
The limitation is storage amplification and regeneration work. Every predefined size occupies another object, a recipe change creates another generation run, and an asset is unavailable for export until the worker finishes. This approach is a poor fit for a design tool with arbitrary crops or dozens of client-selected dimensions; dynamic image delivery is the more direct boundary there. Request-time resizing can also be the smaller choice when inputs are strictly tiny, concurrency is bounded, and the caller genuinely needs every derivative before the response returns.
I would not add dynamic image delivery just to avoid writing a 320-pixel object. It becomes attractive when clients demand many dimensions, formats, or crop rules and those rules change often. Even then, tenant exports deserve a pinned transformation version or prebuilt artifacts. Otherwise the same export definition can yield different bytes after a policy change.
Synchronous resizing remains defensible for a strict input envelope. The envelope must be enforced, not hoped for. Once large product art is a normal input, proxying it through the SaaS API consumes capacity that could serve metadata, billing, and export coordination.
Failure handling is part of the data model
The happy path is short. Recovery decides whether it stays short.
Retries are normal.
Store the original first. Keep it when thumbnail generation fails, because it is the source for a retry and for new derivative policies. Track the processor version with the derivative record or key. When the thumbnail recipe changes, enqueue a new deterministic version rather than overwriting the old one while exports are running.
Observe counts and age, not just exception logs: assets stuck in pending, jobs in processing beyond their lease, failures grouped by bounded reason, and time from original commit to ready. Export jobs need their own totals for omitted, pending, and failed assets. A tenant should receive an explicit incomplete result instead of a plausible-looking package missing product art.
Lifecycle rules can retire old derivative versions and abandoned uploads. Amazon S3 documents lifecycle configuration for transitioning and expiring objects; its documentation also warns that lifecycle behavior has details such as rule scope and asynchronous removal. Treat deletion as a policy with tests and inventory checks, not as immediate transactional cleanup. Google Cloud Storage likewise provides object storage documentation that should be checked for the selected location, access, and lifecycle configuration.
Do not log signed upload material or tenant object keys indiscriminately. Logs need stable asset and job IDs, state transitions, processor version, byte counts, and timing. That is enough to debug the pipeline without turning observability into a second catalog of sensitive paths.
What I would change at scale
First, split queues by work class so a flood of large originals cannot starve ordinary thumbnails. Then stream object reads and writes through the processor instead of holding whole encoded files in memory, while keeping hard decoded-pixel limits. Finally, place workers near the storage location used for that tenant and measure cross-region transfer before designing a clever global system.
US and EU operation adds a placement decision, not a reason to duplicate every image everywhere. Record the tenant's chosen storage location, route uploads and workers to it, and keep export assembly in the same location unless the product has a documented reason to move bytes. Storage documentation is the source of truth for location behavior; avoid assuming two providers use identical region semantics.
I would revisit dynamic delivery only when the derivative matrix grows faster than releases can absorb. Until then, precomputed thumbnails keep export inputs inspectable, retries deterministic, and the application's large-file path out of the application server. It is plain infrastructure. That is precisely why it leaves a one-person company free to ship product work every week.
Top comments (0)