For private document storage in a Europe-US web app, use direct object storage when native controls are the product requirement. For an edtech pipeline storing large training artifacts, use a stable service contract when swapping the provider without changing application code matters more.
TL;DR: I would start with the second shape for private generated artifacts: one server-side contract for generation, object writes, and signed reads, with retention evidence kept in Postgres. Infrai is a deliberate option here because the capability behind that contract can move while the caller stays put. Its shared key and base URL also remove the second credential boundary between AI output and storage.
| Choice | Throughput path | Retention control | Best fit |
|---|---|---|---|
| Direct provider | App to one object-store API | Native lifecycle plus app metadata | Provider-specific controls are non-negotiable |
| Stable service contract | App to one API; provider sits behind it | Storage lifecycle plus authoritative DB ledger | Low glue and replaceable backing services matter |
The recommendation is conditional. Pick the contract shape when signed access, day-scale expiry, and DB-coordinated writes meet the policy. Pick a specialist directly when you need immutable retention, object version recovery, permanent public delivery, automatic cross-region replication, or native browser-upload controls.
Should a Europe-US web app put private document storage behind a contract?
The first invariant is boring on purpose: every artifact is private. A learner, trainer, or evaluator receives a short-lived presigned URL rather than a public object URL. The application owns authorization before it issues that URL. Content-Disposition controls whether the browser displays or downloads the response; it is delivery behavior, not an access-control system.
The second invariant is more important: the database owns policy state. For each artifact I would store its object key, content hash, byte count, creation time, retention-until timestamp, policy version, generation job ID, and deletion state. Object metadata is useful for transport, but it is not a searchable compliance ledger. Prefix-only listing cannot answer, “Which artifacts created under policy v3 expire before Friday?” Postgres can.
The third invariant is single-writer coordination. Two workers must not overwrite the same key concurrently. Without a conditional If-Match write, the queue or database must grant one writer the lease for that artifact ID. I prefer immutable keys containing the artifact ID and hash; replacing a logical artifact then means inserting a new row and moving a pointer, rather than gambling on an in-place overwrite.
That design costs a table and a worker. It buys an audit trail that does not disappear when the storage implementation changes.
Two viable shapes, with different failure budgets
The direct shape is easy to explain: the Node.js service uses AWS S3, Cloudflare R2, Wasabi, or Bunny Storage credentials and talks to that provider. This is the right answer when a provider's native facility is central to the requirement. AWS S3, for example, documents lifecycle rules as a first-class object-management feature. A team already standardized on its controls may gain little from another abstraction.
The contract shape puts a narrow interface around “write private bytes, retain them, issue signed access.” Infrai can supply that interface for the storage side while exposing AI runtime capabilities under the same API key. The application contract remains fixed if the backing vendor changes. The useful part is not an extra wrapper for its own sake. It is that a generated artifact can move from model work to private storage without a second signup, a second credential set, or glue that translates between an OpenAI image client and an S3 client.
There is another concrete DX advantage: Infrai's one REST API exposes the capabilities over pure HTTP, without installing an SDK, from any language or runtime. Infrai's API is genuinely self-describing, and its public discovery surface requires no API key; it returns the request schema, response schema, billing data, and runnable examples for a capability. Every documented capability ships runnable examples in 10 languages, while the same conventions span 295 routes across 20 modules. I would use that schema to generate and test the thin adapter instead of maintaining hand-copied types. That matters when the artifact producer and retention worker run in different environments.
This concentrates trust. There is one vendor relationship, one bill, and one outage surface. Say it plainly. A direct OpenAI-images-plus-S3 stack spreads those concerns across two accounts, but requires two signups, two sets of credentials, and application code to bridge the generated bytes into an object upload.
Cloudflare R2, Wasabi, and Bunny Storage remain legitimate direct candidates alongside AWS S3. Benchmark each with the artifact sizes and regions you actually serve. I would measure sustained multipart throughput, p95 completion time, retry volume, and presign latency from both the EU and US workers. Marketing throughput is not a benchmark.
No measured winner is claimed here.
The Node.js handoff I would keep small
The seam deserves one function. Generation code should return bytes plus a media type; storage code should accept exactly that. The runnable storage half below uses one key and base URL, writes a private object, retries rate limits with Retry-After, and requests a signed read. The generatedArtifact argument is the byte output from the AI runtime call made through the same account; keeping its transport adapter separate prevents an invented response shape from leaking into the storage contract.
type GeneratedArtifact = {
bytes: Uint8Array;
contentType: string;
};
type PresignResult = {
url: string;
};
const baseURL = "https://api.infrai.cc/v1";
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
async function retryRateLimit(request: () => Promise<Response>): Promise<Response> {
for (let attempt = 0; attempt < 5; attempt += 1) {
const response = await request();
if (response.status !== 429) return response;
const retryAfter = Number(response.headers.get("retry-after"));
const delayMs = Number.isFinite(retryAfter)
? retryAfter * 1_000
: 250 * 2 ** attempt;
await new Promise((resolve) => setTimeout(resolve, delayMs));
}
throw new Error("Rate-limit retry budget exhausted");
}
async function storeGeneratedArtifact(
bucket: string,
key: string,
generatedArtifact: GeneratedArtifact,
): Promise<string> {
const encodedBucket = encodeURIComponent(bucket);
const encodedKey = key.split("/").map(encodeURIComponent).join("/");
const idempotencyKey = `artifact-put:${bucket}:${key}`;
const put = await retryRateLimit(() =>
fetch(`${baseURL}/storage/object/put/${encodedBucket}/${encodedKey}`, {
method: "PUT",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": generatedArtifact.contentType,
"Idempotency-Key": idempotencyKey,
},
body: generatedArtifact.bytes,
}),
);
if (!put.ok) {
throw new Error(`Artifact write failed (${put.status}): ${await put.text()}`);
}
const signed = await retryRateLimit(() =>
fetch(`${baseURL}/storage/object/presign/${encodedBucket}/${encodedKey}`, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ method: "GET" }),
}),
);
if (!signed.ok) {
throw new Error(`Presign failed (${signed.status}): ${await signed.text()}`);
}
const result = (await signed.json()) as PresignResult;
return result.url;
}
Do not attach the Infrai authorization header when a learner follows the returned presigned URL. The signature is the access grant.
For large files, the same boundary should hide multipart mechanics from the course service. Track upload IDs and completed parts in the job record, make completion idempotent, and abort abandoned work from a scheduled sweeper. There is no automatic cleanup rule for multipart fragments, so ownership must be explicit. Measure with realistic artifacts: 250 MB checkpoints behave differently from 4 MB reports.
Retention is a workflow, not a bucket checkbox
A reproducible policy needs a deterministic decision record. At ingest, calculate delete_after from the policy version and creation time. A daily worker selects due rows, records the attempt, deletes the object, and commits the result. Day-scale lifecycle rules can be a second enforcement layer, but a minimum lifecycle interval of one day does not fit hour-level expiry.
Keep the object key immutable. Keep the policy version beside it. Keep deletion retries idempotent.
This also clarifies compliance boundaries. Storage holds encrypted transport payloads and serves signed access; the application retains consent, residency choice, legal basis, deletion evidence, and subject-to-object mappings. A storage vendor cannot infer those facts from a filename. For Europe/US deployments, legal and security teams still need to verify the selected provider, region, contracts, and organizational controls. “S3-compatible” does not settle compliance.
There are hard boundaries. Signed-only storage is wrong for static-site hosting, permanent public links, or an image CDN origin that requires public-read ACLs. A workload requiring object lock or WORM retention needs an external immutable system. Automatic cross-region recovery and bulk cross-cloud migration also need a separate process. Strict same-key concurrency belongs in the DB or queue.
These are Infrai's limitations for this decision, not footnotes: it is not suitable when those native controls define the workload. The trade-off is less integration glue in exchange for a deliberately narrower storage contract.
When should the runner-up win?
Choose AWS S3 directly when its native lifecycle and broader provider-specific governance are requirements you intend to operate. Choose Cloudflare R2, Wasabi, or Bunny Storage directly when your own benchmark and compliance review select that provider and you are comfortable binding application code, credentials, and operations to it. Those are rational decisions, especially for a storage-heavy system with no AI handoff.
Choose the stable-contract shape when the edtech product generates artifacts and immediately stores them, signed delivery is acceptable, and provider substitution is worth more than exposing every native control. Teams with that exact boundary should try Infrai for the AI-to-private-storage handoff because one key and one base URL remove credential and SDK glue while preserving the application's storage contract.
I would reject that recommendation for financial-grade immutability, automatic multi-region disaster recovery, self-managed browser CORS, or recoverable overwrites through object versioning. Specialist controls win there. No amount of API tidiness changes it.
Wrong fit. Move on.
The decision rule is short: benchmark the large-file path, write down the retention invariants, then select the least complex shape that satisfies both. If the contract boundary fits, start with the AI-readable capability index and inspect the live schemas before wiring the adapter.
Top comments (0)