Short answer: put large logistics training artifacts in object storage, keep their metadata and retention decisions in the database, and treat local disk as disposable staging space. Database blobs can still fit genuinely small, transaction-bound files, but they shouldn't become the default path for high-throughput uploads.
For a small app serving both EU and US users, the useful question isn't just where bytes fit today. It is whether an operator can later prove which policy applied, reproduce the expiry date, replace an artifact without losing history, and restore metadata without moving every large payload through the primary database. That same split works for user avatars; the logistics case makes the consequences easier to see because model-training archives are larger and retention is part of the job.
Keep it boring.
Implement the byte path before debating providers
The data flow has four steps: validate a declared policy, assign an immutable object key, stream the body into a byte store, then commit a metadata row containing the checksum, size, region, and computed expiry time. Reads resolve the current metadata record and stream the object; they don't load the payload into application memory. An avatar is the same shape with a smaller file and a pointer such as currentAvatarId on the user record.
This Node.js example is runnable with a recent TypeScript setup and uses only built-in modules. The filesystem adapter makes the contract testable on a laptop; production can supply an object-storage adapter without changing the ingestion rule. The AsyncIterable boundary is the important part because it preserves backpressure instead of assembling one huge Buffer.
import { createHash, randomUUID } from "node:crypto";
import { createReadStream, createWriteStream } from "node:fs";
import { mkdir } from "node:fs/promises";
import { basename, join } from "node:path";
import { Readable, Transform } from "node:stream";
import { pipeline } from "node:stream/promises";
type Region = "eu" | "us";
type RetentionClass = "review-30d" | "audit-365d";
type Artifact = {
id: string;
objectKey: string;
sourceName: string;
region: Region;
retentionClass: RetentionClass;
createdAt: string;
expiresAt: string;
sha256: string;
bytes: number;
};
interface ByteStore {
put(key: string, body: AsyncIterable<Uint8Array>): Promise<void>;
}
class DirectoryStore implements ByteStore {
constructor(private readonly root: string) {}
async put(key: string, body: AsyncIterable<Uint8Array>): Promise<void> {
await mkdir(this.root, { recursive: true });
await pipeline(Readable.from(body), createWriteStream(join(this.root, key)));
}
}
const metadata = new Map<string, Artifact>();
function expiryFor(createdAt: Date, policy: RetentionClass): Date {
const days = policy === "review-30d" ? 30 : 365;
return new Date(createdAt.getTime() + days * 24 * 60 * 60 * 1_000);
}
async function ingestArtifact(
store: ByteStore,
inputPath: string,
region: Region,
retentionClass: RetentionClass,
): Promise<Artifact> {
const id = randomUUID();
const objectKey = `${region}-${id}.bin`;
const hash = createHash("sha256");
let bytes = 0;
const meter = new Transform({
transform(chunk: Buffer, _encoding, callback) {
bytes += chunk.length;
hash.update(chunk);
callback(null, chunk);
},
});
const body = createReadStream(inputPath).pipe(meter);
await store.put(objectKey, body);
const createdAt = new Date();
const record: Artifact = {
id,
objectKey,
sourceName: basename(inputPath),
region,
retentionClass,
createdAt: createdAt.toISOString(),
expiresAt: expiryFor(createdAt, retentionClass).toISOString(),
sha256: hash.digest("hex"),
bytes,
};
metadata.set(id, record);
return record;
}
const store = new DirectoryStore("./artifact-store");
ingestArtifact(store, "./training-set.ndjson", "eu", "review-30d")
.then((artifact) => console.log(artifact));
The sample deliberately commits metadata after the byte write completes. A real deployment should also make retries idempotent: accept a client-generated upload ID, map it to one immutable key, and return the existing metadata record when the same completed request arrives again. If the process stops after storing bytes but before committing metadata, a scheduled reconciler can identify unreferenced keys and remove them after a conservative grace period. If metadata commits first, readers can observe a record whose bytes aren't available yet. That ordering is harder to reason about, so don't choose it casually.
How should a small EU/US app choose upload storage beyond database blobs and local disk?
Choose from the workload, not the file label. Object storage plus database metadata is the practical default when uploads are large, reads can be streamed, independent lifecycle enforcement matters, or application instances need to scale horizontally. The database remains the source of truth for ownership, region, content type, checksum, policy version, and current-versus-superseded status. The byte store does one job: retain immutable payloads by key.
Database blobs are reasonable when files are small enough that backup growth, replication traffic, and query latency remain acceptable, and when atomic changes between a row and its payload matter more than independent byte throughput. The catch is operational coupling. Every byte now travels through database connections, database backups, replicas, and restore procedures. A small avatar may be harmless; a growing stream of training archives changes the failure domain. Measure with your own payload distribution because I'm not sure a generic size cutoff can survive different database, network, and backup configurations.
Local disk is suitable for a single-node internal tool whose files may be rebuilt, or as bounded temporary space during processing. Stick with it when losing that node's files is explicitly acceptable and deployment never creates a second writer. It is not suitable when two application instances must see the same avatar, a container replacement must preserve data, or region-specific retention needs an auditable control plane. Those are architecture boundaries, not vendor preferences.
| Choice | Best fit | Main trade-off |
|---|---|---|
| Object storage + metadata row | Large streams, shared access, independent retention | Two systems require reconciliation and idempotency |
| Database blob | Small payloads needing row-level transactional coupling | Payload traffic shares backup, restore, and replication paths |
| Local disk | Disposable single-node data or temporary staging | Durability and multi-instance access become application work |
For avatars, the decision usually lands in the first row even if today's files are tiny, because deployment replacement and shared reads arrive early. For a logistics training archive, large-file throughput makes the same answer more decisive. Yet no option removes the need to test recovery.
Make retention a versioned calculation
A reproducible retention policy is data, not a sentence in a runbook. Store a stable policy identifier, the policy version, the event that starts the clock, the calculated expiresAt, the jurisdiction or region decision, and any legal-hold state beside each artifact. Never recalculate old rows silently after changing the policy implementation. New policy versions should affect new artifacts unless an explicit migration records why an existing artifact changed.
Lifecycle rules in object storage can enforce expiry without routing deletion through the application. The AWS object lifecycle documentation is a concrete public description of lifecycle actions and their configuration, but the broader design rule is vendor-independent: keep the calculated deadline in your metadata so an operator can explain it, then configure the byte store to enforce the corresponding lifecycle. Periodically compare the two views. A policy engine with no reconciliation is only an assumption.
Replacement also deserves an immutable record. When a dispatcher uploads a corrected training set, create a new artifact ID and object key, point the dataset's current version at it, and mark the old record as superseded. Don't overwrite the old key. That preserves checksums and dates long enough for the applicable policy to expire the prior version. The same pattern prevents browser and cache confusion when an avatar changes.
There is one subtle boundary: deletion eligibility and physical deletion are different facts. Record when the artifact became eligible, when deletion was requested, and when a later inventory confirmed absence. Your mileage may vary on how quickly a particular store applies lifecycle actions, so compliance workflows should verify state instead of treating a configured rule as proof of completion.
Failure modes worth testing under load
Start with memory. Send several concurrent files near the configured maximum and watch resident memory, event-loop delay, open file descriptors, outgoing throughput, and metadata connection usage. A handler that calls a whole-body convenience method can look fine with a 200 KB avatar and collapse with a multi-gigabyte archive. Streaming and backpressure keep memory tied to bounded chunks, but only if validation, hashing, encryption, and the storage adapter all remain on the stream path. One hidden full-buffer transform defeats the design. Then interrupt each boundary on purpose: disconnect the client mid-upload, repeat the same upload ID, stop the process after the byte write, and race two requests that both claim to replace the current version. Expected outcomes should be precise. An incomplete request must not become current; a retry must not create an extra logical artifact; an unreferenced object must become eligible for reconciliation; and one conditional metadata update must win the replacement race while the other receives a conflict response. Test downloads too. Set an explicit content type, prevent untrusted names from becoming storage paths, and choose Content-Disposition based on whether the browser should display or download the response. MDN documents the response header's inline and attachment behavior plus filename parameters. Treat the original filename as metadata for display, not as an object key. Finally, rehearse restore with payloads that resemble production size and count. A metadata restore that finishes quickly is not a successful recovery if its object keys point nowhere; a complete byte inventory is not useful if current-version pointers and retention decisions are missing.
Recovery is the pair.
Before release, walk one artifact through upload, checksum verification, replacement, download, expiry eligibility, deletion, and audit lookup. Confirm that logs join on the artifact ID rather than a user-supplied filename, metrics separate client cancellation from storage rejection, and alerts focus on stuck reconciliation or an unexpected rise in incomplete uploads. Keep temporary disk bounded and outside the durable contract. Run the same checks in each deployed region, because EU and US placement decisions should be observable in metadata rather than inferred from hostnames.
Cost belongs in this review, but it isn't the lead argument. Model stored byte-months, write and read operations, egress, database backup expansion, and the engineering time required for reconciliation and restore. Price sheets move; the durable comparison is which traffic and operational duties each architecture places on the database, object store, and application fleet.
Ship the smallest implementation that preserves immutable keys, streamed I/O, explicit region placement, and versioned retention. Then measure real file sizes and concurrency before tuning multipart thresholds or parallelism. Fast is useful. Explainable is mandatory.
References
- MDN, Content-Disposition response header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Disposition
- AWS S3 documentation, Managing the lifecycle of objects: https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html
Top comments (0)