Short answer: treat image generation and object storage as two separate jobs, make the upload idempotent, and retry a 429 with bounded exponential backoff and jitter. For a marketplace, the retention policy decides the storage layout; the queue only decides how work gets retried.

Choice Good fit Main cost
Upload from the worker The generator already exposes bytes to your process Your worker carries large media and needs enough temporary disk
Direct upload from the generator The generator can write to an approved object-storage target More credential and callback plumbing
Keep generated images in a temporary prefix You need moderation or deduplication before publication A sweeper must delete abandoned objects
Write directly to a permanent key Every generated result is immediately publishable Mistakes become retention and deletion incidents

For most Node.js marketplace pipelines, I would start with a worker that owns the upload, a queue message that contains a deterministic object key, and a separate cleanup job for expired work. It is the least complicated option that still gives you a clean audit trail. The image was created already. That does not mean the upload succeeded.

Implement generation-to-upload state transitions

Generation and storage have different failure boundaries. A generation response can arrive, the process can lose its network connection while uploading, or the storage service can ask the client to slow down with HTTP 429. A queue that marks the job complete after generation has created an image will lose the asset. A queue that retries the entire generation step may create duplicates and waste provider capacity.

Split the work into two state transitions:

type ImageJob = { jobId: string; marketplaceItemId: string; generationId: string; objectKey: string; contentType: "image/png" | "image/jpeg" | "image/webp"; retentionClass: "draft" | "published"; }; type AssetState = "generated" | "uploading" | "stored" | "expired"; 

The durable record should say generated before the upload attempt begins. The upload worker claims that record, writes to the exact objectKey, verifies the result, and then changes the state to stored. If the process dies between those operations, the queue can safely run the upload again.

Separate the clocks.

Here is the failure sequence worth testing: generation returns bytes, the worker writes them, the process dies before the database update, and the queue redelivers the message. On the second delivery, a random filename creates a second object and leaves the first one orphaned. A deterministic key makes the second delivery a check against the same destination; a durable state transition makes it possible to tell “the bytes exist” from “the application recorded them.” Add a deletion deadline to that record and the abandoned first object has an owner too. This is more bookkeeping than a one-function upload, but it is much less work than explaining a missing marketplace image and an unbounded pile of temporary files later.

That safety depends on idempotency. Do not use a random filename on every retry. A key such as marketplace/{itemId}/{generationId}.webp gives the retry the same destination. If overwriting is unacceptable, make the write conditional and treat an existing object with the same content identity as success after verification. The precise conditional-write feature varies by storage system, so test it against the system you will operate.

The generated bytes also need a lifetime. A draft image can sit in a temporary prefix, while a published image can move to a retention class with a different deletion rule. This is where many pipelines quietly fail: a retry mechanism is designed, but nobody owns the object left behind when a message is permanently discarded.

How should a Node.js queue retry 429 uploads with backoff?

Retry only the operation that failed. A 429 during upload should requeue the upload record, not call the image generator again. Honor a valid Retry-After header when the storage endpoint provides one. Otherwise, calculate a bounded delay and add jitter so a batch of workers does not wake up together.

type RetryDecision = { retry: boolean; delayMs: number; }; function retryDecision( status: number, attempt: number, retryAfterSeconds?: number, ): RetryDecision { if (status !== 429 && status !== 503) { return { retry: false, delayMs: 0 }; } const serverDelay = retryAfterSeconds === undefined ? 0 : Math.max(0, retryAfterSeconds * 1_000); const exponential = Math.min(60_000, 1_000 * 2 ** attempt); const jitter = Math.floor(Math.random() * 500); return { retry: attempt < 6, delayMs: Math.max(serverDelay, exponential + jitter), }; } 

The important details are easy to miss. The attempt limit is finite. The delay is capped. Jitter is applied to the client-calculated delay, while an explicit server delay remains the lower bound. A production worker should also persist the attempt count and next-attempt time in the queue or job record; an in-memory counter vanishes when the process restarts.

Do not retry every error. A malformed object key, rejected content type, authentication failure, or a payload that cannot be read will keep failing. Send those jobs to a dead-letter path with the jobId, generationId, object key, status, and last error. Keep the generated asset discoverable until its retention deadline, or delete it deliberately as part of dead-letter handling. “The message is gone” is not a deletion policy.

A queue can also redeliver a message after a timeout even while the first worker is alive. Use a lease, a compare-and-set state transition, or an equivalent ownership mechanism. The upload target and the durable state machine must both tolerate that duplicate delivery.

Retention and deletion need named owners

Start with data classes, not bucket names. For this marketplace scenario, three classes are enough for a first pass:

Class Example Retention decision Deletion owner
Draft An unreviewed generated image Short deadline from creation Expiry worker
Published The image attached to a live listing Until listing policy says it may leave Listing lifecycle
Failed or abandoned An upload that never reached stored Deadline from the last attempt Reconciliation job

Store createdAt, storedAt, retentionClass, and deleteAfter in the database. The object metadata can repeat the identifiers, but it should not be the only source of truth. A deletion worker can query due records, issue the object deletion, and record the outcome. A second reconciliation pass can find database rows whose objects are missing and storage objects with no durable row.

Deletion needs an explicit answer to one awkward question: what happens when the listing is removed while an upload is in flight? My default is to let the in-flight write finish into the temporary prefix, then let the retention worker remove it. That avoids a race between a listing callback and a partially completed upload. Your mileage may vary if the content is regulated or the deletion deadline is strict; in that case, the worker needs a revocation check before it commits the object.

The Content-Disposition header is also part of the delivery contract. If a browser should download an image instead of displaying it inline, set the response deliberately and test filenames containing spaces and non-ASCII characters. MDN documents the header's inline and attachment behavior and its filename parameters. This is a small HTTP detail, but a marketplace image that downloads with an unusable name is still a broken user workflow.

Test the state machine before tuning the queue

Measure each boundary separately. Track generation success, upload success, 429 count, retry count, time spent waiting, dead-letter count, orphan count, and deletion age. A single “job succeeded” metric cannot tell you whether the image exists, whether it is reachable, or whether it will be deleted.

Use a correlation object in every log line:

const logContext = { jobId: job.jobId, generationId: job.generationId, objectKey: job.objectKey, retentionClass: job.retentionClass, }; 

The useful test is an integration test with a storage-compatible test target and a controllable queue. Make it return 429 twice, then accept the same key. Assert that generation runs once, upload runs three times, the delay is bounded, and the final state is stored. Then kill the worker after the object write but before the state update. A later delivery should converge on the same record instead of producing a second object.

Also test deletion. Create an abandoned generated record, advance the clock past deleteAfter, and verify both the object and the durable record reach their intended final state. Test a missing object, a duplicate delivery, and a queue message whose payload has the wrong content type. These cases expose ownership gaps faster than a happy-path test.

For systems with formal security or authorization requirements, document who can create, read, and delete each class of object. FedRAMP's program materials are a useful reference point for treating authorization and continuous monitoring as program concerns rather than a checkbox in an upload function; the exact controls for your system still depend on its scope.

When is a different design the better choice?

The worker-owned upload is not suitable when generated files are too large for the worker's available disk, when the generator cannot expose a readable stream, or when policy forbids the application from seeing image bytes. In those cases, use a direct-upload design with short-lived credentials and a completion message, then keep the same idempotent key and retention state machine.

Stick with a simpler synchronous flow when the files are small, the generation request is already part of a user-facing transaction, and the business can tolerate the request waiting for storage. A queue adds operational machinery. It does not automatically improve a pipeline.

The decision rule is plain: separate generation from upload, retry only transient throttling, make the destination deterministic, and make deletion a first-class job. Pick the design your retention policy can explain six months later. If it cannot say who deletes a generated image after an abandoned upload, the architecture is unfinished, regardless of how quickly the happy path runs.

Further reading