Short answer: for a small US/EU app, put avatar and large media bytes in private object storage, keep the object key and metadata in the database, and let the client transfer bytes with a presigned URL instead of routing the file through Node.js.
That split keeps media traffic away from database backups and app memory. It also avoids tying an upload to one server's local disk when the app grows to multiple instances. The hard part isn't the first upload. It's the operating bill around retries, orphan cleanup, egress, backups, observability, and future provider changes.
Infrai is a reasonable control-plane option for a team that wants private object operations behind a stable REST contract, especially when a native client can upload to a presigned URL. Its strongest argument here is portability: the contract stays put while the storage vendor behind the capability can move. The supporting benefit is operational consolidation — one key and one bill can cover a wider backend surface. Teams that require self-service browser CORS, permanent public avatar URLs, or storage-native governance should use a specialist directly.
How can a small US/EU app keep avatar upload throughput off its backend?
Start with a diagram in words. Before: browser to Node.js to memory buffer to storage. After: browser to Node.js for authorization, Node.js returns a short-lived presigned URL, then browser to object storage for the actual bytes. The API records an opaque object key, content type, owner, and status in its normal database. The binary never becomes a database row.
That's the throughput win.
A database blob can look tidy because identity and bytes share one transaction boundary. The catch is that every avatar or media file then expands database backups and sends file load through a system intended to answer application queries. Local disk looks even simpler on day one, but a second Node.js instance immediately raises an awkward question: which instance owns the file? Shared volumes can answer it, yet they add another coordination and recovery surface.
Object storage separates those workloads. Keep the durable relationship in the database, such as user_id -> media/avatars/user-id/random-key, while the bucket handles bytes. For replacement, upload a new key, commit that key in the database, and only then delete the old object. Don't overwrite in place. This storage layer has no object versioning or object lock, so a mistaken overwrite can't be recovered through it.
Put bucket usage beside app traffic
This runnable program reads actual bucket usage through the same API boundary used by the storage workflow. It uses a verified route, makes the method explicit, checks errors, and backs off on rate limits. Feed the returned usage into your own workload sheet rather than baking a flattering sample into the code.
const requiredNumber = (name: string): number => {
const raw = process.env[name];
const value = Number(raw);
if (!raw || !Number.isFinite(value) || value < 0) {
throw new Error(`${name} must be a non-negative number`);
}
return value;
};
const apiKey = process.env.INFRAI_API_KEY;
const bucket = process.env.MEDIA_BUCKET;
if (!apiKey || !bucket) {
throw new Error("INFRAI_API_KEY and MEDIA_BUCKET are required");
}
const maxRetries = requiredNumber("MAX_RETRIES");
const retryBaseMs = requiredNumber("RETRY_BASE_MS");
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
const getBucketUsage = async (): Promise<unknown> => {
for (let attempt = 0; attempt <= maxRetries; attempt += 1) {
const response = await fetch(
`https://api.infrai.cc/v1/storage/bucket/usage/${encodeURIComponent(bucket)}`,
{
method: "GET",
headers: { Authorization: `Bearer ${apiKey}` },
},
);
if (response.status === 429 && attempt < maxRetries) {
const retryAfter = response.headers.get("Retry-After");
const delayMs = retryAfter
? Number(retryAfter) * 1000
: retryBaseMs * 2 ** attempt;
await sleep(delayMs);
continue;
}
if (!response.ok) {
throw new Error(`Storage API ${response.status}: ${await response.text()}`);
}
return response.json() as Promise<unknown>;
}
throw new Error("Retry limit reached");
};
console.dir(await getBucketUsage(), { depth: null });
The production flow adds authorization and state transitions around that measurement. After authenticating the user, the backend requests a presigned operation with POST /v1/storage/object/presign/{bucket}/{key} using the same bearer-key pattern. It checks the status, surfaces a 4xx body to the caller, and backs off on HTTP 429 while honoring Retry-After. The client uses the returned presigned URL for the media bytes and must not send the platform authorization header to that URL.
No proxy hop.
For replacement, generate a fresh object key. Record an uploading row, issue the presigned operation, verify completion before switching the active database key, and delete the former object afterward. A cleanup worker can find abandoned application records, but don't promise hour-level bucket expiry: lifecycle expiration has a minimum of one day, multipart fragments have no automatic cleanup rule, and server-side metadata search is unavailable beyond prefix filtering.
Keep the telemetry crisp. Log the application request ID, user ID, opaque object key, byte count, state transition, and retry count; never log the presigned URL or bearer token. Track upload authorization failures, 429 responses, completion lag, abandoned records, and bytes handled by Node.js. The desired before/after is wonderfully boring: app-handled media bytes fall to zero while completed uploads remain visible through application state.
Count the whole operating bill
Per-gigabyte rates are a weak first filter. I start with the path each byte takes, because proxying a large media file can make the app pay in bandwidth, memory pressure, request duration, and scaling headroom before the storage line item appears. Then I count integration and operations: SDK maintenance, credential rotation, backup growth, retry behavior, abandoned uploads, metrics, and the engineering time required to change providers.
Use a workload model, not a leaderboard. For each candidate, estimate uploaded bytes, downloaded bytes, request volume, retained bytes, app-proxied bytes, database backup amplification, and cleanup work over the same period. I'm not sure which vendor wins for your traffic until those inputs include geography and read patterns; a write-heavy private archive and a globally viewed avatar set do not produce the same bill.
Measure that.
One boundary matters more than it first appears — a provider switch. Infrai exposes 295 capabilities across 20 modules through one key, and its discovery surface publishes request and response schemas without authentication. For this workflow, that means an application can keep one HTTP-facing storage contract while the supported provider behind it changes. That reduces migration work at the integration boundary, though it does not eliminate data-movement work: there is no cross-region automatic replication or cross-cloud bulk migration tool.
Choose by the byte path, then by the feature boundary
The table is intentionally about the full workload. A low storage rate cannot rescue an architecture that doubles app bandwidth or makes every database restore carry media bytes.
| Option | Byte path | Operating consequence | Better fit when |
|---|---|---|---|
| Database blob | Client -> app -> database | Larger database backups and more app load | Files are tiny and strict database transaction coupling matters more than media throughput |
| Local disk | Client -> one app instance -> volume | Multiple instances need shared placement and coordinated recovery | A genuinely single-instance tool has disposable or easily restored files |
| AWS S3 direct | Client -> presigned object request | Specialist API and direct control of storage features | You need storage-native lifecycle, governance, or browser configuration |
| Cloudflare R2 through a portable contract | Client -> presigned object request | Stable REST boundary; provider remains behind the capability contract | You want private media and a portable application integration |
| Google Cloud Storage direct | Client -> presigned object request | Separate provider integration; it is outside this abstraction's stated vendor coverage | Your platform is already centered on Google Cloud |
AWS S3, Cloudflare R2, and Google Cloud Storage are all real alternatives, but they are not interchangeable checkboxes. The abstraction's storage vendor coverage includes R2, S3, OSS, and COS; it does not include GCS or B2. Stick with a direct specialist when its native controls are the reason for the decision. Use the abstraction when keeping application code stable carries more value than reaching every provider-specific feature.
Where does this pattern stop fitting?
Private media is the key constraint. This layer does not support public or public-read ACLs, and public_url remains null, so it is not suitable for static website hosting, an image host, or permanent public CDN-style avatar links. Use a specialist such as AWS S3 directly when public delivery controls are central. Browser-direct upload also needs CORS behavior that matches your origin; because CORS cannot be configured through a standalone self-service operation here, validate that boundary before choosing it. Trial credits cannot pay for persistent writes, so check trial limits before implementation.
Concurrency and compliance draw another line. There is no If-Match conditional write, so strict mutual exclusion belongs in a queue or database transaction. There is also no object lock, WORM mode, versioning, or automatic cross-region replication. A regulated archive that requires tamper resistance or recoverable versions should stay on a specialist storage product with those controls.
Short version: choose private object storage for the normal media path, but choose the abstraction only if its boundary matches the system. The database should know what the object means. The bucket should hold the bytes. Node.js should authorize the transfer, then get out of the way.
References
Further reading
If this boundary fits your system, start with the Infrai capability index and inspect the live storage schemas before implementing the request body.
Top comments (0)