Short answer: treat a large ZIP export as an auditable job with an explicit recovery policy, then issue an expiring signed download link only after the archive is complete and the requester still owns the job. Multipart upload keeps transport manageable; it does not decide who can download a private logistics file.
The useful unit is not the URL. It is the export record. A dispatcher asks for delivery labels, proof-of-delivery images, or a manifest; the API creates a job and returns quickly; a Node.js worker assembles the ZIP from bounded reads; object storage receives numbered parts; and a later authorization check mints a short-lived link. The database records the decisions so a retry does not have to guess from a filename.
This framing changes what I optimize first. A fast happy path is nice, but an export that cannot explain its state after a worker restart is expensive to operate. Start with the ledger.
Keep it private.
How should a Node.js worker govern a large ZIP export, multipart upload, and signed download link?
Give each job a random ID, account ID, requested document set, private object key, expected item count, and lifecycle timestamps. queued, running, ready, failed, and expired cover a practical first version. The object key should contain the account and job identity, such as exports/account-42/job-8f3d.zip; never use a shared latest.zip key.
The state transition is the control plane:
type ExportState = "queued" | "running" | "ready" | "failed" | "expired"; type ExportJob = { id: string; accountId: string; objectKey: string; expectedItems: number; writtenItems: number; state: ExportState; uploadId?: string; }; function canIssueLink(job: ExportJob, requesterAccountId: string): boolean { return job.accountId === requesterAccountId && job.state === "ready" && job.writtenItems === job.expectedItems; } The worker should publish ready only after multipart completion succeeds and the archive policy passes. A completed upload with a failed database update is recoverable if the upload ID and job ID are recorded. A ready row with no completed object is not a state; it is a leak waiting to happen.
The implementation: make recovery visible in the upload adapter
The runnable part should show the lifecycle rather than hide it behind a large provider-specific client. Keep the storage adapter small: begin, upload numbered parts, complete, abort, and sign a private read. The ZIP producer must yield chunks incrementally. Otherwise the worker has only moved the memory spike into another function.
type UploadPart = { number: number; etag: string }; type UploadSession = { id: string }; interface ObjectStore { begin(key: string, contentType: string): Promise<UploadSession>; putPart(upload: UploadSession, number: number, bytes: Uint8Array): Promise<UploadPart>; complete(upload: UploadSession, parts: UploadPart[]): Promise<void>; abort(upload: UploadSession): Promise<void>; signGet(key: string, lifetimeSeconds: number): Promise<string>; } interface ZipSource { next(): Promise<Uint8Array | null>; } const PART_SIZE = 8 * 1024 * 1024; export async function writeExport( store: ObjectStore, source: ZipSource, key: string, ): Promise<void> { const upload = await store.begin(key, "application/zip"); const parts: UploadPart[] = []; let pending = new Uint8Array(0); let number = 1; try { for (;;) { const chunk = await source.next(); if (chunk === null) break; const next = new Uint8Array(pending.length + chunk.length); next.set(pending); next.set(chunk, pending.length); pending = next; while (pending.length >= PART_SIZE) { parts.push(await store.putPart(upload, number++, pending.slice(0, PART_SIZE))); pending = pending.slice(PART_SIZE); } } if (pending.length > 0 || parts.length === 0) { parts.push(await store.putPart(upload, number, pending)); } await store.complete(upload, parts); } catch (error) { await store.abort(upload); throw error; } } export function issueDownloadLink( store: ObjectStore, job: ExportJob, requesterAccountId: string, ): Promise<string> { if (!canIssueLink(job, requesterAccountId)) { throw new Error("export is not available"); } return store.signGet(job.objectKey, 15 * 60); } The example holds one assembled part plus the current source chunk. That is bounded, but next temporarily duplicates the pending buffer while joining arrays; a production ZIP stream should use a reusable buffer or a stream primitive when chunks are large. The important rule is to bound source reads, queued bytes, and in-flight part requests together. I would measure that memory envelope before increasing concurrency.
Small detail, large consequence: persist the upload ID and acknowledged part identifiers before asking the queue to retry. On restart, the worker can resume according to policy or abort the old session and start again. Duplicate delivery must be harmless, so the final ready transition should be conditional on the job still being unfinished and owned by the same export request.
What does a private signed download link actually promise?
A signed link is a bearer capability with an expiry, not a live authorization session. Keep the object private. Create a fresh link after checking account ownership, job state, completion, and retention. Do not place the link in logs, traces, analytics, or support tickets.
The catch is revocation. Direct delivery is not suitable when every byte needs a policy decision or access must be revoked immediately; use an authenticated download service in that case and accept extra application bandwidth and latency. Stick with direct signed delivery when a short access window is acceptable and delivery simplicity matters more than per-byte inspection.
| Delivery boundary | Suitable case | Cost of the choice |
|---|---|---|
| Expiring signed link | Large private archive and ordinary browser delivery | A copied link can remain usable until expiry |
| Authenticated application stream | Immediate revocation or byte-level policy | More application bandwidth and latency |
The lifetime is a policy input, not a performance claim. I’m not sure 15 minutes fits every dispatcher: archive size, network quality, and the ability to request a fresh link after reauthorization should determine it. Your mileage may vary.
Recovery is a product feature, not a queue detail
Most bad export incidents are state errors. A ZIP can be structurally valid while missing one source object. A worker can finish uploading parts and die before publishing the job. An expired link can point to an object that still needs retention. These are different cases and should produce different support actions. Consider a dispatcher requesting a month of proof-of-delivery images: the source query returns 1,842 records, the worker writes two parts, and the process exits while waiting for the third part acknowledgement. A retry that looks only for exports/account-42/job-8f3d.zip cannot tell whether the archive is complete, whether the object belongs to this account, or whether the previous upload is still consuming storage. The ledger can answer those questions because it has the expected count, the upload ID, acknowledged part numbers, and the conditional state transition. That extra recordkeeping feels slower during the happy path, but it turns an opaque support ticket into a bounded decision -- resume, abort, or issue a fresh link.
Before queueing, estimate document count and bytes where practical; enforce limits while reading as well. Decide what a missing input means: fail with a useful reason, or produce a manifest that explicitly lists omissions. Quietly returning a partial archive as successful is a data-integrity failure, even when storage completed correctly.
Use a reconciler for jobs stuck in running and abandoned multipart sessions. It should inspect the recorded job, upload session, and object metadata, then choose the declared resume-or-abort path. It should not infer readiness from the presence of an object key.
Test the awkward cases: zero documents, a ZIP smaller than one part, a ZIP larger than one part, a missing source file, a failure during part three, a worker restart, duplicate queue delivery, and one account requesting another account’s job. The expected behavior should be boring. In one test I expect an unauthorized request to produce error code EXPORT_NOT_AVAILABLE and no object metadata; the exact transport status belongs to the API contract.
For operations, record queue wait, archive duration, bytes read, bytes written, part retries, completion latency, and abandoned-session age. Log job IDs and upload IDs, never signed URLs. A short runbook is enough: inspect job state, verify ownership, inspect the upload session, then resume or abort. Keep completed-export retention separate from abandoned-upload cleanup, because link expiry and object deletion are separate controls.
This design is not suitable for a workflow that needs immediate revocation on every download or deep content inspection. Choose an authenticated application stream there. It is also a poor fit for unbounded exports; split the request or add a hard size limit when the archive cannot fit the worker’s operational budget. For routine private logistics bundles, the ledger-plus-worker pattern keeps the application in charge of policy while storage handles the bytes.