Short answer: retry the thumbnail job, not the whole upload, and make every storage write replayable. In a property-management system handling inspection photos and lease documents, keep the large original separate from its derived thumbnail. A transient thumbnail-write failure should delay one derivative without sending a multi-gigabyte source file through Node.js again.
I would choose the storage interface with this matrix:
| Concern | Prefer | Why |
|---|---|---|
| Large-file throughput | Direct, resumable source upload | The application server does not proxy the payload |
| Thumbnail replay | Deterministic object key | A retry can confirm the same logical result |
| Expiring downloads | Short-lived signed capability | The browser gets no permanent public URL |
| Failure diagnosis | Attempt ID plus request ID | Retries stay distinguishable from duplicate work |
The decision rule is simple: keep bytes out of the Node.js process, and spend retry budget on small, independently derived objects. This is a throughput decision before it is a retry-library decision.
Measure the byte path first.
Why does a thumbnail retry fail after the original upload succeeded?
Because "upload succeeded" is usually three separate facts. The original object may be durable, the resize worker may have fetched it, and the thumbnail write may still be waiting behind a transient service response. Treating those facts as one transaction creates the worst retry: a large replay with unclear ownership.
The worker should verify source identity, produce bytes, then write a fixed destination key. A fixed key matters more than a clever backoff formula. If building-42/unit-7/photo-018 always maps to the same source revision and size, two workers can collide without creating two logical thumbnails. The result still needs validation; "request accepted" is not the same as "expected object available."
I initially thought three attempts was a reasonable default. The catch is that three attempts across a queue, image decoder, and storage client can become nine writes. Give one layer ownership of retry policy. Let the other layers return typed errors.
The failure boundary needs a name.
Which design protects throughput without hiding failures?
Use bounded exponential backoff with jitter, and cap total elapsed time. A retryable response means the operation may work later; it does not mean the payload is safe to replay blindly. Classify timeouts, connection resets, and service-unavailable responses separately from invalid credentials, malformed image data, and policy violations. The latter should fail fast.
For large source files, resumable upload reduces data lost when a connection breaks, while direct upload removes the application server from the byte path. For thumbnails, an idempotent whole-object write is often easier to reason about than multipart work. Measure both paths with the same image corpus. "Small" depends on the output sizes your property data actually produces.
Keep the storage adapter small. It should accept a key, bytes, content type, and optional precondition, then return an entity tag and provider request identifier. The resize algorithm should know none of the SDK's method names. That boundary is what makes a retry test cheap.
type UploadResult = { etag: string; requestId?: string };
async function putThumbnail(
put: (key: string, body: Uint8Array) => Promise<UploadResult>,
key: string,
body: Uint8Array,
): Promise<UploadResult> {
return put(key, body);
}
How do storage interfaces differ for this workload?
Amazon S3, Google Cloud Storage, and Azure Blob Storage all expose object-storage models, but upload, conditional-write, metadata, and signed-download details are not interchangeable. S3 documents multipart upload and conditional requests; Cloud Storage documents resumable uploads and preconditions; Azure Blob Storage documents block blobs and conditional headers. Those boundaries matter more than SDK method names.
For a neutral adapter, compare four behaviors with a test harness: can a failed large upload resume, can a thumbnail write reject an unexpected prior revision, can a download capability expire, and can the client expose a request identifier? The runner-up may be better when a deployment already depends on its identity model or when its tooling gives clearer failure traces. That is an integration constraint, not a universal ranking.
Keep a vendor SDK behind the adapter. Inject a fake that fails on attempt two, then test the real adapter against a disposable bucket or container. The fastest first call is the one that does not require configuration to leak through every module.
What should the operational test prove?
Start with a corpus resembling property records: phone images, high-resolution inspection photos, and one deliberately oversized or malformed file. Record upload duration, bytes sent, time to first thumbnail, retry count, duplicate-key conflicts, and end-to-end success. A single average hides the tail that tenants notice.
Inject failures before source commit, during a resumable part, after thumbnail bytes are generated, and after storage accepts the thumbnail. The last case is the trap. A timeout after acceptance must not create a second logical object or report success without verification.
Keep signed download links short-lived and derive them only after authorization checks. The URL is a capability. Log issuance metadata, never the complete query string. For deletion, retain originals and derivatives according to the documented retention rule; do not let a thumbnail retry decide policy by accident.
Optimize the large-file path with direct resumable transfer, isolate thumbnail generation, and make the derivative key deterministic. Then tune backoff from measurements. A retry count chosen before measuring throughput, tail latency, and duplicate work is guesswork wearing a configuration file.
References
- https://nodejs.org/api/
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503
- https://www.rfc-editor.org/rfc/rfc9110
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpuoverview.html
- https://cloud.google.com/storage/docs/resumable-uploads
- https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blobs-introduction
- https://developers.cloudflare.com/workers/
Top comments (0)