Node.js Browser Download Link 404s — Object Storage Export Job Race Conditions
Short answer: treat a tenant export as unpublished until the worker has stored the exact completed-object identity in a durable record. A browser download link should be derived from that record, never from a filename guessed when the job was queued. This turns a confusing object-storage 404 into a small set of inspectable state transitions. For a healthtech system that stores product images and…
When a tenant initiates an export of its data in a healthtech system that utilizes Node.js and object storage, the export worker handles the process of creating a ZIP archive of the requested data. The crucial step is to ensure that the export record contains the exact object identity of the completed archive before deriving a browser download link from it. This avoids confusion that can arise from a 404 error on the object storage when attempting to access the download link.
The process begins with the export worker storing the completed archive in object storage and recording the archive's key and version in a durable database record. This serves as an immutable identifier for the completed archive, ensuring that the browser download link points to the correct location. The link service reads the ready records specific to the authenticated tenant, verifying that the object identity has been correctly persisted.
The race condition between the export worker and the queue or retry mechanism can lead to a situation where the browser link points to a non-existent archive. This can happen due to a missing tenant segment, URL encoding changes, or retry suffixes in the generated link. To mitigate this, the system should wait for the finalization of the export before generating the download link.
This involves checking the record's lifecycle state and ensuring that the storage write has completed and the identity was persisted in the durable database.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.