Short answer: retry the upload only when the failure is plausibly transient, and make every attempt idempotent. For a logistics report service, the thumbnail should be written to a deterministic object key, verified after the write, and deleted by a retention policy rather than by a retry worker. That separates a temporary storage outage from a bad image, a revoked customer session, or a report that has reached its deletion deadline.
I have been paged for missed jobs and duplicate deliveries, so I treat retry state as production data. A thumbnail worker should record the report ID, source image version, attempt count, next attempt time, and the final classification. The worker can then retry a 503 or a network timeout without retrying a 400, an authentication failure, or an image decoder error. Three attempts with bounded exponential backoff are a reasonable starting policy; the exact limit belongs in a runbook and should be tested against the storage service's documented behavior.
I first thought a longer retry window would hide most transient failures. It did not solve the ambiguous-success case; it only kept stale jobs alive longer. The useful tradeoff is a short, visible retry budget plus a queue state an operator can inspect.
Why do thumbnail retries fail in the first place?
A resize pipeline usually has two different failure domains. The image processor may finish successfully while the object write times out. Conversely, the write may succeed and the client may lose the response. Treating both as “upload failed” creates duplicate objects or overwrites a newer thumbnail.
The dangerous case is the ambiguous result. If the request timed out after the storage service accepted it, the next attempt must address the same logical object, not create a second random key. A deterministic key such as reports/{reportID}/thumbnails/{sourceVersion}.webp gives the worker a stable destination. It also makes a replay safe when the source version is unchanged.
Do not use a successful HTTP response as the only business signal. Store the object identifier and a content digest in the job record, then verify the metadata that matters to the application. A digest check catches a producer bug; it does not prove that a customer can still access the report, which is an authorization decision at read time.
Keep the key boring.
The retry boundary belongs in the worker
The request handler should enqueue work and return a job state. It should not hold a customer request open while an image is resized and uploaded. The worker owns classification, backoff, and the transition to a terminal state. This keeps a transient storage error from turning into a second customer request and a second report-generation job.
Here is the important part of that boundary in Go. The storage interface is deliberately generic, because the retry policy should survive a provider change.
package thumbnail import ( "context" "crypto/sha256" "errors" "fmt" "time" ) type Store interface { Put(ctx context.Context, key string, body []byte, contentType string) error } type Classifier interface { Transient(error) bool } func Upload(ctx context.Context, store Store, classify Classifier, reportID, sourceVersion string, body []byte) error { key := fmt.Sprintf("reports/%s/thumbnails/%s.webp", reportID, sourceVersion) digest := sha256.Sum256(body) _ = digest // Persist this digest beside the job before production use. for attempt := 0; attempt < 3; attempt++ { err := store.Put(ctx, key, body, "image/webp") if err == nil { return nil } if !classify.Transient(err) || errors.Is(err, context.Canceled) { return err } if attempt == 2 { return fmt.Errorf("thumbnail upload exhausted: %w", err) } timer := time.NewTimer(time.Duration(1<<attempt) * time.Second) select { case <-ctx.Done(): timer.Stop() return ctx.Err() case <-timer.C: } } return errors.New("unreachable") } This example leaves two operational details explicit. Transient must be implemented from the storage client's typed errors and HTTP semantics, not from string matching. The job record also needs a lease or compare-and-swap transition so two workers cannot process the same retry at once. A lock without an expiry can strand work; an expiry without idempotency can duplicate work. Use both.
The retry budget is part of the data contract.
What should be retained, and what should be deleted?
Retention is a product and compliance decision expressed as a storage rule. Keep the thumbnail only as long as the customer can reasonably need the generated report, then delete the thumbnail and its job metadata together, subject to legal holds and audit requirements. A failed upload should not create an indefinite retry loop or an orphaned source image.
I separate these clocks:
| Record | Retention question | Deletion trigger |
|---|---|---|
| Source image | Is it still needed to reproduce the report? | Report expiry, legal hold release, or explicit policy event |
| Thumbnail | Can the report still reference it? | Report expiry plus a bounded cleanup window |
| Job record | Do operators need the failure history? | Audit retention deadline |
The cleanup worker must be idempotent too. A missing object is already in the desired state for deletion. A timeout should produce a retryable cleanup event, while an authorization failure should page an owner and stop blind retries. Deletion should use the same deterministic key as upload; otherwise a later cleanup pass cannot reliably find every version.
This policy has limits. A three-attempt budget is unsuitable for a multi-hour outage if the business requires automatic recovery, while an unlimited budget is unsuitable for customer data with a firm deletion deadline. Choose the queue's retry horizon from the retention contract, then make the exception path explicit.
How do storage choices change the failure mode?
Object storage systems differ in consistency details, conditional-write support, lifecycle controls, and error taxonomies. Those differences affect the adapter, not the application rule. Amazon S3, Google Cloud Storage, and Azure Blob Storage all document object operations, but their SDK types, precondition mechanisms, and lifecycle configuration are not interchangeable. Read the chosen service's current documentation before mapping errors into Transient.
The useful comparison is narrow: S3 exposes conditional request mechanisms such as If-None-Match; Cloud Storage documents preconditions such as generation matching; Azure Blob Storage exposes access conditions through request headers and SDK options. These are tools for preventing an older worker from replacing a newer version. None removes the need for a job lease, a bounded retry budget, or deletion accounting.
For local development, a fake store should model the ambiguous outcome: accept the bytes, then return a timeout. A test that only returns a clean 503 misses the duplicate-delivery path. Add a property test that runs the same job twice and asserts one logical key, one source version, and one terminal result. Observe retry count, age of the oldest pending job, upload latency, cleanup failures, and bytes retained past policy. Those metrics answer whether the system is recovering or accumulating hidden debt.
When this advice does not apply
A deterministic key is wrong when every upload is an immutable event and consumers require every version. In that design, use an event ID as the key and make downstream publication idempotent. It is also insufficient for content that must never be reconstructed after deletion; that requirement needs an explicit retention and legal-hold review.
For ordinary customer-facing report thumbnails, the decision rule is simpler: classify the error, retry a bounded number of times with cancellation-aware backoff, write to a stable key, and make cleanup converge. Keep authentication and authorization outside the retry loop. The queue can recover from a temporary storage failure; it cannot repair an invalid customer permission or a retention policy that was never recorded.
Sources
- Cloudflare Workers documentation: https://developers.cloudflare.com/workers/
- RFC 9110, HTTP Semantics: https://www.rfc-editor.org/rfc/rfc9110
- Amazon S3 conditional requests: https://docs.aws.amazon.com/AmazonS3/latest/userguide/conditional-requests.html
- Google Cloud Storage request preconditions: https://cloud.google.com/storage/docs/generations-preconditions
- Azure Blob Storage concurrency: https://learn.microsoft.com/en-us/azure/storage/blobs/concurrency-manage



