For a fintech tenant's large ZIP backup, publish the restore link only after the archive is complete and a separate read verifies its size and digest. Short answer: keep the multipart upload private until completion, validate the resulting object, then atomically mark that snapshot ready. A successful part upload is not a downloadable backup.
| Choice | Best fit | Integrity boundary |
|---|---|---|
| Multipart upload to a private staging key | Archives too large for one practical request | Complete the upload, then read and verify the object before publishing |
| Single-request upload | Archives that reliably fit within the request limit and timeout | Verify the stored object before publishing |
Use the first path for large exports, with a single-request upload as the simpler runner-up when its limits leave comfortable headroom. The decision is driven by two things: sustained large-file throughput and the point at which a tenant can actually restore a snapshot. An attractive upload progress bar says nothing about that second point.
How can a completed multipart export upload still leave an incomplete ZIP download?
Multipart upload has at least three distinct states: parts accepted, completion accepted, and object verified. Completion assembles the parts the client lists; it does not infer the parts the application meant to send. If a worker loses its part manifest after a retry, a completion request assembled from the surviving entries can produce a shorter object. In a ZIP, the missing tail may include its central directory. The download succeeds at the HTTP layer, then extraction fails. Blaming a browser cache first sends the investigation in the wrong direction.
Track the expected byte count and digest while producing the archive, alongside the ordered part manifest and a stable snapshot ID. Persist retry state somewhere that survives the export worker. On a retry, reconcile the recorded parts with the upload service's reported parts before completion; compare part numbers and returned part identifiers, rather than assuming an attempted request succeeded. Treat a completion timeout as ambiguous: inspect the final object and the upload state before starting a second completion or issuing a new link. Abort an upload that cannot be reconciled, then restart at a new staging key. Keep old staging keys out of the download namespace. For a tenant restore, inspect the archived manifest and the ZIP footer against the producer's expected output before telling an operator to retry a download: repeating the same link to an already truncated object only repeats the failure. A fresh transfer helps distinguish a damaged client download from damaged stored bytes, but it cannot recreate a part that was never included at completion.
No link yet.
There is an awkward distinction here. A digest of the ZIP bytes computed by the producer lets you compare a later full read with what the producer actually emitted; it cannot prove the source database snapshot was internally consistent. Record a source snapshot identifier and tenant ID too, and test a restore into an isolated environment. Do not promote a backup based on an object-size check alone. A truncated archive is easy to catch by size; wrong bytes at the right size are not. This is a limitation of transport verification, not a reason to skip it: verification answers what bytes arrived, while a restore test answers whether those bytes serve the recovery job.
Does the upload method meet the throughput target?
Measure end-to-end time from snapshot selection to a verified, restorable archive, not just bytes sent per second. Multipart uploads allow independent part retries and concurrent transfer. Those gains come with a manifest to persist, a completion boundary, and cleanup for abandoned uploads. For a small archive, a single request removes that state machine. For a large one, a single failed request may require sending the whole archive again. The crossover depends on your archive sizes, network behavior, concurrency ceiling, and request limits; a borrowed throughput number cannot choose it for you.
Run a test with representative tenant data and an archive whose size exceeds a single worker's comfortable in-memory budget. Measure total elapsed time, bytes re-sent after an induced part failure, peak memory, and time until the restore check passes. Try a worker restart immediately before completion. If the test only times the upload call, it hides the expensive failure mode: a fast object that nobody can restore. Keep concurrency bounded so a handful of large tenants do not exhaust sockets or memory for every other export. A useful comparison records the archive size and worker concurrency with each run, then repeats the same workload using one request and multipart transfer. Those results belong to that workload; changing the mix of tenant sizes can move the crossover point.
Measure the restore, too.
The operational contract should stay small enough to fit into an SDK: pending, verified, or failed, with a tenant-scoped snapshot ID. A download link is issued only for verified. Log the snapshot ID, upload attempt ID, expected size, observed size, and verification outcome; do not log the link itself. Alert on aging pending attempts and on failed restore checks. Retention rules should remove abandoned staging objects as well as completed backups whose retention period has ended. Neither cleanup path should silently delete a snapshot that is currently being restored.
What should the publication gate actually check?
This minimal TypeScript sketch assumes a storage adapter that reports a completed object's bytes and exposes a read stream. Its complete method accepts a persisted, ordered manifest. The archive producer must supply the expected size and SHA-256 digest for the exact ZIP bytes; those values are not inferred from multipart ETags. The database operation must atomically transition the same tenant and snapshot from pending to verified.
import { createHash } from "node:crypto";
import { Readable } from "node:stream";
type Part = { number: number; etag: string };
type Snapshot = {
tenantId: string;
snapshotId: string;
stagingKey: string;
uploadId: string;
expectedBytes: number;
sha256: string;
parts: Part[];
};
interface Storage {
complete(uploadId: string, parts: Part[]): Promise<void>;
size(key: string): Promise<number>;
read(key: string): Promise<Readable>;
}
interface Catalog {
markVerified(tenantId: string, snapshotId: string): Promise<void>;
}
async function verifyAndPublish(
snapshot: Snapshot,
storage: Storage,
catalog: Catalog,
): Promise<void> {
const parts = [...snapshot.parts].sort((a, b) => a.number - b.number);
if (parts.length === 0 || parts.some((p, i) => p.number !== i + 1)) {
throw new Error("Part manifest has a gap");
}
await storage.complete(snapshot.uploadId, parts);
if (await storage.size(snapshot.stagingKey) !== snapshot.expectedBytes) {
throw new Error("Stored archive size differs from producer output");
}
const hash = createHash("sha256");
let bytes = 0;
for await (const chunk of await storage.read(snapshot.stagingKey)) {
const data = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
bytes += data.length;
hash.update(data);
}
if (bytes !== snapshot.expectedBytes || hash.digest("hex") !== snapshot.sha256) {
throw new Error("Stored archive digest differs from producer output");
}
await catalog.markVerified(snapshot.tenantId, snapshot.snapshotId);
}
That function is deliberately narrower than a full export worker. It does not claim a failed completion is safe to retry blindly, and it does not implement restore validation. Put a conditional state transition in markVerified, so an older attempt cannot overwrite a newer snapshot's state. Keep the staging object private throughout. A failure leaves the catalog pending or failed, never downloadable; investigation can then distinguish missing parts from an invalid ZIP producer output.
When is the simpler upload better?
Multipart is not suitable for every backup. Choose a single-request upload when measured exports fit within the storage service's documented request limit, transfer times fit the job deadline with margin, and restarting a failed transfer is acceptable. Fewer moving pieces matter in a CLI and in an SDK: there is no persisted part ledger, no ambiguous completion retry, and less abandoned-upload cleanup. Still run the same post-upload size, digest, and restore checks. Simplicity does not excuse an untested backup.
Once verified, serve a tenant-authorized link to the immutable snapshot, not a mutable "latest" key that can change halfway through an operator's recovery. If a client reports a broken download, compare the bytes and digest of the stored object with those of a fresh download first. Then check ZIP extraction and restore in isolation. Cache policy matters for a reused URL: HTTP Cache-Control governs reuse of responses, and URI encoding rules matter when identifiers appear in a link. Neither repairs an incomplete archive. The decisive test is still whether the selected tenant snapshot can be restored.
Further reading
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpuoverview.html
- https://www.rfc-editor.org/rfc/rfc1952
- https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control
- https://www.rfc-editor.org/rfc/rfc3986
Top comments (0)