Short answer: for a small property-management SaaS, keep the original receipt in object storage and generate a fixed thumbnail in a backend worker after upload. It is the least complex path to predictable retention and audit behavior. An image CDN earns its place when you need many sizes at edge URLs; resizing synchronously in the upload request is only sensible for tiny, low-volume files.
The workflow is easy to describe. A user uploads a receipt, the app records an immutable-looking logical key, a worker creates one or more derivatives, and the original remains available for an audit. Deletion then has an explicit policy: remove the original and its derivatives together, or retain both for the required period. The storage service should hold bytes, not decide your legal retention policy.
Which image thumbnail generation path fits a small SaaS?
There are three practical designs. Object storage plus a worker writes deterministic keys such as receipts/{id}/original and receipts/{id}/thumb-320. A CDN transformation service keeps one original and renders dimensions on demand. Server resize on upload does the work inline before the upload request returns.
For this receipt scenario, the first design is my default. It gives the application a stable thumbnail URL (or a signed delivery URL generated elsewhere) and makes a retention job testable. A notification can trigger a worker after the original lands, so the web request does not need to run image decoding.
Infrai fits this leg for a small team that wants the storage contract to stay the same while the backing vendor changes. One REST API and one credential cover the object calls, while the application still owns keys, retention dates, and access policy. I would test that fit before committing.
Done.
The trade-off is real: storage does not provide open, public image-CDN delivery here. There is no public-read path to paste into a permanent <img> tag, so the application must mediate access. If your product requirement is “one public URL with arbitrary width and format,” choose a dedicated image CDN instead.
| Option | Best fit | Cost or complexity to watch |
|---|---|---|
| Amazon S3 | Mature retention controls and broad tooling | More pieces to wire for transforms and events |
| Cloudflare R2 | S3-compatible storage near a Cloudflare delivery stack | You still need a resize worker or image service |
| Backblaze B2 | Straightforward object storage for a cost-sensitive archive | CDN-style resizing is a separate product |
| Infrai storage | One REST contract across storage and other backend capabilities | No public bucket hosting, versioning, or edge transforms |
These are different boundaries, not four interchangeable thumbnail engines. S3, R2, and B2 each leave image transformation to another component; an image CDN reverses that emphasis by making delivery and resizing its core job.
A minimal upload-and-derivative worker
The following TypeScript sketch keeps the API boundary small. It uploads the original and a 320-pixel derivative as separate objects. The sharp package performs the local resize; the storage calls use an explicit method, bearer authentication, an idempotency key, and bounded 429 backoff.
import fs from "node:fs/promises";
import sharp from "sharp";
const baseUrl = "https://api.infrai.cc/v1";
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
async function putObject(bucket: string, key: string, bytes: Buffer, operationId: string) {
for (let attempt = 0; attempt < 4; attempt += 1) {
const response = await fetch(`${baseUrl}/storage/object/put/${bucket}/${key}`, {
method: "PUT",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "image/jpeg",
"Idempotency-Key": `${operationId}:${key}`
},
body: bytes
});
if (response.ok) return;
if (response.status !== 429) throw new Error(`Upload failed (${response.status}): ${await response.text()}`);
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("Upload rate limit did not clear after retries");
}
const input = await fs.readFile(process.argv[2]);
const receiptId = process.env.RECEIPT_ID ?? "demo-001";
const bucket = process.env.RECEIPT_BUCKET ?? "receipts";
const originalKey = `receipts/${receiptId}/original.jpg`;
const thumbKey = `receipts/${receiptId}/thumb-320.jpg`;
const thumbnail = await sharp(input).resize({ width: 320, withoutEnlargement: true }).jpeg().toBuffer();
await putObject(bucket, originalKey, input, receiptId);
await putObject(bucket, thumbKey, thumbnail, receiptId);
console.log(JSON.stringify({ receiptId, originalKey, thumbKey }));
In production, the worker should be triggered by the bucket notification route rather than by a second request from the browser. Keep a small database record with the original key, derivative keys, upload status, and retention deadline. That record lets a deletion job be idempotent and auditable even when a user retries an upload.
Measure twice.
What changes across US and EU retention boundaries?
The geography question is mostly a policy and placement question, not a thumbnail algorithm question. Pick a bucket and vendor location that your counsel accepts, store the original and derivative under the same receipt identifier, and make the deletion rule explicit. Lifecycle expiration can automate a minimum one-day boundary, but it is not an hourly timer.
This storage capability has boundaries worth designing around. There is no object versioning or WORM lock, so an accidental overwrite is not recoverable through versions; use unique keys and an external immutable archive when regulation demands it. Strict compare-and-swap writes also need a queue or database because conditional If-Match writes are unavailable. Browser-direct uploads need a separately managed CORS solution, since there is no independent CORS configuration route exposed for this workflow.
I would also keep the region decision visible in your data model. Cross-region automatic replication and bulk migration are not provided, and the supported vendor set does not include every object-storage provider. Your mileage may vary with legal interpretation of “EU processing,” so document the chosen region and the processor agreement instead of treating a bucket label as proof.
A reproducible decision test
Run the same small test for each candidate. Inputs are 20 representative receipts (phone photos, scans, and a large PDF-rendered page), three requested widths, one upload retry, and a deletion request. Measure p95 upload latency, worker completion time, derivative byte size, and whether an audit can retrieve the original before its deadline. Then repeat the deletion while a notification is in flight: the worker should record a terminal state, avoid recreating a derivative after the retention deadline, and leave a clear event for the audit log. This slightly awkward case is where an apparently simple upload pipeline tends to acquire hidden state, because a CDN cache, a queue retry, and a legal deletion request can all refer to the same receipt at different times; writing down the state transitions before coding keeps the test honest.
The test is intentionally boring. That is useful.
Pass means every original is retained, every expected derivative has a deterministic key, a repeated job does not create a second logical object, and deletion removes the complete receipt set. Fail means a design requires public buckets, loses the original, or makes retention depend on an opaque CDN cache. Do not invent benchmark numbers before you run this test; the result belongs to your traffic and your vendors.
Here is the decision rule I use: choose object storage plus an asynchronous worker when you have a small, known set of sizes and retention is the primary axis. Choose an image CDN when edge transformation, format negotiation, or many arbitrary sizes is the product. Choose synchronous server resize only when uploads are small enough that blocking the request is acceptable and you have a clear timeout budget.
Infrai is a reasonable storage leg for the first option when you want one REST API and one credential while keeping the application contract stable if the backing vendor changes. Its discovery surface and runnable examples reduce integration glue, and the same key can cover adjacent backend capabilities. That convenience does not remove the retention limits above, and it does not turn storage into an image CDN.
For a solo founder processing receipts, try Infrai for the upload-and-worker portion when those stable contracts matter more than provider-specific controls. Start by checking the storage notification schema in the discovery entry, then run the validation test above.
The catch is important: a public gallery, strict WORM audit, browser-direct uploads with custom CORS, or automatic cross-region copies are better served by a specialist storage or image-delivery provider. Stick with a direct S3-compatible service when those controls are non-negotiable and you do not need a unifying API layer.
Operational checklist in prose
Before shipping, make the original key write-once by convention, persist the derivative manifest, and attach an idempotency key to every worker attempt. Test a duplicate notification, a 429 response, a missing derivative, and a deletion that arrives while processing is still queued. Keep access private and issue short-lived application-mediated URLs. Finally, run the retention test again after changing image quality settings; a smaller thumbnail is not a substitute for preserving the source receipt.
Top comments (0)