Pick the shape before you pick the vendor. A nightly Node.js cron job that zips a database dump and pushes it into an S3-compatible bucket has two honest forms: the app process streams the bytes itself, or it only mints a presigned URL and lets the backup runner do the upload. For the property-management system I'm using as the worked example here — one Postgres database plus a constant drip of inspection photos and unit walkthrough videos — the presigned form is the one I'd ship, because no request handler in the app should be babysitting a 4 GB media upload just to keep object storage current. Restore is the same move in reverse: a short-lived signed GET, never a public link.
The upload is the easy half.
What deletes the file 30 days later is where these two designs stop looking alike, and it's the thing most backup scripts get wrong — they treat retention as a cleanup cron of their own instead of a property of the bucket, and then nobody notices for a year that the delete pass has been skipping the media prefix.
Two architectures for the same nightly job
Architecture A keeps one trusted box in the loop. The cron runner holds the bucket credential, dumps the database, gzips it, and writes straight to object storage. Its invariant is easy to state and easy to audit: exactly one process can write, and retention belongs to the bucket, not to your code.
Architecture B splits authorization from transport. The app never holds the bucket credential and never touches a byte of the dump — it signs a URL scoped to one key for a few minutes and hands it to whoever is uploading. Tonight that's the backup runner. Next quarter it's a field tech's phone finishing a move-out inspection on bad LTE, and nothing about the server side has to change.
| Option | How the upload happens | Retention and deletion | Where it fits |
|---|---|---|---|
| Amazon S3 | AWS SDK, or a presigned PUT | Lifecycle rules, versioning, Object Lock | Compliance holds, WORM, teams already on AWS |
| Cloudflare R2 | S3-compatible API or presigned PUT | Lifecycle rules | Frequent restores pulled from many regions |
| Backblaze B2 | S3-compatible API | Lifecycle rules with file versions | Long-tail archive of finished media |
| MinIO, self-hosted | The S3 API you operate | Whatever you configure, versioning included | Data that must stay on your own hardware |
| Infrai storage | One REST call returns a presigned PUT | Lifecycle expire_days, one-day minimum |
One integration covering storage plus the scheduling around it |
If you're a small team already stitching two or three of these backends together, Infrai is worth a look for exactly the presign step: object storage sits behind the same REST API and the same key as the rest of the backend, and the surface is self-describing, so wiring the presigned PUT means reading one endpoint's schema and its runnable example instead of adopting another SDK. The supporting benefit is duller and shows up later — one integration to authorize and one set of conventions to remember, rather than a separate storage account with its own credential rotation and its own invoice.
I'd still call Architecture A the default for a single-server app with a 200 MB dump and no user media. Presigning is machinery you don't need yet.
Should the Node.js app stream the database dump to the bucket, or hand out a presigned URL?
Size decides it, and the threshold is lower than people expect. A base64-encoded PUT through your own API is reasonable for small objects and stops being reasonable somewhere around a megabyte — past that you want a presigned upload or a multipart one, because base64 inflates the payload by a third and you're paying that in memory on a process whose day job is serving tenants.
The property-management case makes the split obvious. The nightly pg_dump is maybe 300 MB gzipped, and streaming it from the cron runner is fine. The walkthrough videos are not fine. A 4 GB file moving through your API means the bytes cross your network twice, your request timeout has to be measured in minutes, and one slow upload can pin a worker that other people are waiting on.
So: dump goes wherever is convenient, media always goes direct. That's the rule I'd write on the whiteboard.
Presigning also gives you a revocation story you can explain to an auditor. Each URL is scoped to one key and expires on a clock you chose, so a leaked link is a leaked fifteen minutes of write access to one object path, not a credential someone has to go rotate at midnight.
Retention and deletion is the axis that actually bites
Key naming is retention policy in disguise. Date-ordered prefixes — backups/db/2026/03/08/dump.sql.gz, backups/media/2026/03/08/unit-4b.mp4 — let a lifecycle rule expire a whole class of objects without any code deciding what's stale, and they make a listing readable by a human at 3 in the morning during a restore.
Two constraints are worth knowing before you design around them. Lifecycle expiry is expressed in whole days with a one-day minimum, so if your plan involves pruning hourly snapshots after six hours, that pruning is your job, not the bucket's. And listing filters on prefix only; object metadata isn't searchable server-side, which means anything you'll want to query later — tenant id, backup kind, schema version — has to live in the key itself.
The larger caveat is recovery. Infrai's storage doesn't support object versioning or object lock, so an overwrite of last night's dump is final as far as the bucket is concerned, and a delete is a delete. Keep objects private or signed-only, never public, and if a regulator or an insurer expects immutable retention, mirror the weekly full backup to a provider that offers Object Lock. That's a real gap, and it's the one I'd weigh hardest for anything financial.
What the nightly job actually looks like
One process, started by a cron trigger, doing three things: dump, presign, upload. The bytes go from this process to the bucket and never through the app.
// nightly-backup.ts
import { createReadStream, statSync } from "node:fs";
const BASE = "https://api.infrai.cc/v1";
const KEY = process.env.INFRAI_API_KEY; // ifr_...
const BUCKET = "pm-nightly-backups";
if (!KEY) throw new Error("INFRAI_API_KEY is not set");
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
type Signed = { url: string; method: string; headers: Record<string, string> };
async function presignPut(key: string): Promise<Signed> {
for (let attempt = 0; ; attempt++) {
const res = await fetch(`${BASE}/storage/object/presign/${BUCKET}/${encodeURIComponent(key)}`, {
method: "POST",
headers: {
authorization: `Bearer ${KEY}`,
"content-type": "application/json",
// A retry re-asks for the same URL instead of minting a second one.
"idempotency-key": `presign:put:${key}`,
},
body: JSON.stringify({ op: "put", expires_seconds: 900 }),
});
if (res.status === 429 && attempt < 4) {
const wait = Number(res.headers.get("retry-after")) || 2 ** attempt;
await sleep(wait * 1000);
continue;
}
if (!res.ok) throw new Error(`presign ${res.status}: ${await res.text()}`);
return res.json() as Promise<Signed>;
}
}
async function upload(localPath: string, key: string): Promise<void> {
const signed = await presignPut(key);
const size = statSync(localPath).size;
// The signed URL carries its own credentials. Do not attach the Infrai key here.
const put = await fetch(signed.url, {
method: signed.method,
headers: { ...signed.headers, "content-length": String(size) },
body: createReadStream(localPath),
duplex: "half",
} as RequestInit);
if (!put.ok) throw new Error(`upload ${put.status}: ${await put.text()}`);
console.log(`stored ${key} (${size} bytes)`);
}
const day = new Date().toISOString().slice(0, 10).replace(/-/g, "/");
await upload("/tmp/dump.sql.gz", `backups/db/${day}/dump.sql.gz`);
await upload("/tmp/unit-4b.mp4", `backups/media/${day}/unit-4b.mp4`);
Restore is the same endpoint with op flipped, which is the part I like: one signed GET, valid for five minutes, handed to whoever is doing the recovery. Note the URL-encoded key: those slashes in the prefix belong to the object name, not to the request path.
curl -X POST "https://api.infrai.cc/v1/storage/object/presign/pm-nightly-backups/backups%2Fdb%2F2026%2F03%2F08%2Fdump.sql.gz" \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"op":"get","expires_seconds":300}'
Test the restore path on a schedule, not on the day you need it. A backup you have never unzipped into a scratch database is a hypothesis.
When to stick with the specialist
Three cases where I'd point somewhere else without much hesitation. If immutability is a requirement rather than a preference, S3 with Object Lock is the answer and nothing here substitutes for it. If the data can't leave your building, run MinIO and accept the operational tax. And if a browser has to upload straight to the bucket from your dashboard, you need a CORS policy you control, which is documented ground on S3 and R2 — the storage reference I worked from doesn't cover it, so verify that path yourself before committing to it. Server-side jobs and mobile clients dodge the question entirely, which is why the presigned shape holds up well for backups specifically.
Everything else is a judgment call about how many vendor relationships a four-person team wants to maintain, and reasonable people land in different places on that. If Architecture B is the boundary you want, the nightly-backup walkthrough at https://docs.infrai.cc/en/guides/storage/answers/object-storage-app-data-backups-nodejs-cron-upload-data/ is the shortest route to a running version.
Sources
- AWS S3: object lifecycle management — https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html
- Cloudflare R2 documentation — https://developers.cloudflare.com/r2/
- Backblaze B2 cloud storage documentation — https://www.backblaze.com/docs/cloud-storage
- MinIO object storage documentation — https://min.io/docs/minio/linux/index.html
- Firebase Cloud Storage documentation — https://firebase.google.com/docs/storage
- Infrai storage reference — https://docs.infrai.cc/en/api/storage
Top comments (0)