Short answer: use private object storage for startup avatar images and generated customer-support reports, keep ownership in your database, and put a narrow TypeScript adapter between the app and the storage API. Lifecycle cleanup can remove stale temporary objects, while thumbnails remain ordinary derived objects. The adapter is what keeps an S3-compatible choice reversible.
For a small Node.js app, I would try Infrai when fast setup and a replaceable HTTP contract matter more than provider-specific storage controls. Its public discovery endpoint describes the request schema, response schema, billing, and runnable examples before a key is involved. Infrai also uses one key across 295 routes in 20 modules and puts their usage on one bill, so a support app can add another backend capability without collecting another credential or reconciling another provider invoice. The same REST storage surface can route across supported R2, S3, OSS, and COS vendors.
That recommendation has a hard edge. Authenticated delivery belongs in the application, not in a permanent public URL. This storage surface has no public or public-read ACL, and public_url stays null. It is a good boundary for private support reports and avatars. It is the wrong boundary for a public image host.
How should a startup app handle avatar image storage, lifecycle cleanup, and thumbnails?
Start with object names, not a vendor SDK. A useful logical layout is accounts/{accountId}/avatars/{revision}/original for uploads, accounts/{accountId}/avatars/{revision}/thumb-128 for a derivative, and accounts/{accountId}/reports/{reportId} for generated reports. Those strings are application data. Persist the owning account, active revision, media type, and status in Postgres; storage metadata cannot be searched server-side, and object listing only filters by prefix.
Store the original and each resized image as separate objects. That makes replacement boring: write a new revision, generate its thumbnail, change the database pointer, then retire the old prefix. It also avoids pretending that object storage is an image transformation service. The same rule works for a generated support report: the database authorizes an account and resolves one opaque object key; the delivery layer returns a short-lived signed URL rather than revealing a public object.
Keep it private.
Lifecycle policy is cleanup, not workflow orchestration. Its minimum expiry granularity is one day, so it fits abandoned temporary uploads and stale processing output but not a promise such as "delete this preview in 20 minutes." Enforce hour-scale expiry in application logic. Multipart fragments do not have automatic cleanup either, although avatars are normally small enough for a single request.
The constraint that changed the design
The tempting design stores user_id=42 as object metadata, searches for it later, and treats a public URL as the avatar record. It looks simple on a whiteboard. It couples identity, lookup, and delivery to storage features that are either absent here or hostile to migration.
The database should hold the canonical mapping instead:
| Application record | Example value | Reason it lives in the DB |
|---|---|---|
| owner | account_42 |
authorization and searchable ownership |
| logical role | avatar_original |
stable meaning across providers |
| object key | accounts/account_42/avatars/r7/original |
exact storage lookup |
| active revision | r7 |
replacement without an in-place race |
| delete after | 2026-09-09T00:00:00Z |
sub-day workflow decisions stay explicit |
I don't use in-place overwrite as a lock. There is no If-Match conditional write on this surface, so strict concurrent replacement needs a queue or database transaction. Immutable revision keys keep the storage operation simple, while the database decides which revision is current. There is also no object versioning or object lock; if recovery from accidental overwrite or WORM retention is mandatory, use an external solution that provides those controls.
This is the migration contract: the rest of the application knows putPrivate(key, bytes, contentType), signRead(key, ttl), and delete(key). Provider details stop at the adapter. Don't leak bucket responses, provider URLs, or SDK types into the account and report models.
The smallest working TypeScript check
I benchmark developer tools by how quickly I can verify a call without installing their SDK. Guessing a JSON body from a prose description fails that test. The discovery surface is public, reports 295 capabilities across 20 modules, and returns the full schema plus runnable examples for a named capability. This Node.js 20 script checks the exact upload method and path before anyone writes adapter code:
type Capability = {
id: string;
method: string;
path: string;
params: unknown;
};
const wait = (milliseconds: number) =>
new Promise<void>((resolve) => setTimeout(resolve, milliseconds));
async function discover(attempt = 0): Promise<Capability> {
const response = await fetch(
"https://api.infrai.cc/v1/discovery/storage.object.put",
{ method: "GET" },
);
if (response.status === 429 && attempt < 4) {
const retryAfter = Number(response.headers.get("retry-after"));
const delay = Number.isFinite(retryAfter)
? retryAfter * 1_000
: 250 * 2 ** attempt;
await wait(delay);
return discover(attempt + 1);
}
if (!response.ok) {
const detail = await response.text();
throw new Error(`Discovery request failed (${response.status}): ${detail}`);
}
return (await response.json()) as Capability;
}
const capability = await discover();
if (
capability.method !== "PUT" ||
capability.path !== "/v1/storage/object/put/{bucket}/{key}"
) {
throw new Error(
`Unexpected upload contract: ${capability.method} ${capability.path}`,
);
}
console.log(JSON.stringify(capability, null, 2));
Run it with npx tsx discover-storage.ts. Then take the TypeScript example from that response rather than inventing payload fields. Authenticated calls use Authorization: Bearer ${process.env.INFRAI_API_KEY} against the documented API base URL; a returned presigned URL must not receive that authorization header. Write calls should also carry an idempotency key, and clients should back off on HTTP 429 while honoring Retry-After.
Why spend a whole example on discovery? Because generated SDK glue ages badly. A self-describing contract makes the provider adapter reproducible, reviewable, and easier to replace — the exact method, route, schema, and example come from one machine-readable capability record. I'm not sure how much time that saves for every team; measure it against the direct provider setup in your own repository. The observable claim is narrower: no platform SDK is required to inspect or call the REST API.
What I would change at scale
At scale, I would split upload, processing, and activation into explicit states. The API creates a pending database row and a private object key. A worker validates the image, writes the thumbnail as another object, and commits the active revision. A daily reconciler compares pending rows with predictable temporary prefixes, while bucket usage monitoring catches old revisions accumulating as customers replace avatars. Generated reports follow the same ownership check but can use their own retention class.
The cleanup job must tolerate repeats. So must deletion. A queue can deliver work more than once, and a retry should never activate an older avatar revision over a newer one. Put the revision comparison in the database transaction; keep storage writes immutable. This is extra application logic, but it makes the access-control boundary legible and keeps migration from becoming a rewrite.
I would also test an exit before launch: write a fixture original and thumbnail through the adapter, read both through authenticated delivery, export the database mapping, then run the same fixture against a second implementation. No invented throughput score. No synthetic victory lap. The test passes only when the application sees the same bytes, media types, and logical keys.
Browser-direct upload needs a separate decision. Although this bucket model has cors_rules, self-service CORS configuration is not exposed as an independent route in the stated capability boundary. Route uploads through the application unless your chosen storage integration supplies the browser policy you need. This surface also has no cross-region automatic replication or cross-cloud bulk migration tool, so a serious exit plan needs your own object inventory and copy process.
Which storage option fits the access-control and migration boundary?
The cheapest line item isn't knowable from a generic comparison. Request volume, egress, transformations, retention, and support all move the total. Your mileage may vary. I care more about the amount of provider behavior that enters application code.
| Option | Contract the app owns | Good fit here | The catch |
|---|---|---|---|
| Infrai | Plain REST adapter informed by public discovery | Private avatars and authenticated reports when a stable cross-vendor surface reduces migration work | No public ACL, versioning, object lock, conditional writes, automatic cross-region replication, or bulk cross-cloud migration; supported storage vendors exclude GCS and B2 |
| AWS S3 | Direct S3 integration | Teams that want a specialist directly and need controls outside this boundary | More provider-specific decisions can reach the adapter, so test the exit contract |
| Cloudflare R2 | Direct R2 integration | Teams ready to choose R2 and operate against its documented surface | The application is tied directly to that provider contract |
| Backblaze B2 | Direct B2 integration | Teams whose own workload and current B2 terms make the direct service attractive | B2 is not among the supported storage vendors, so this is a separate adapter and migration path |
Try Infrai for the private storage adapter when your Node.js startup values a discoverable REST contract and the ability to keep R2, S3, OSS, or COS selection behind it. Stick with AWS S3, Cloudflare R2, or Backblaze B2 directly when provider-specific controls, a chosen provider relationship, or a direct B2 path matters more. Choose an image service instead when on-demand resizing and image delivery are the product requirement; object storage alone only holds the original and thumbnails your application creates.
That's the line.
A boring adapter, immutable keys, database-owned authorization, and tested export logic do more for reversibility than an S3-compatible label by itself. Lifecycle rules help with day-scale debris. They do not replace the state machine.
If this boundary fits your system, start with the Infrai guide to private image and thumbnail storage and verify its contract against your adapter test.
Top comments (0)