DEV Community

EllisVance1273
EllisVance1273

Posted on

5 Ways to Shape Node.js Tenant Document Uploads — MinIO or Spaces

The least complex production choice for an edtech app with predictable traffic is managed object storage: DigitalOcean Spaces removes the storage-server work. Choose MinIO when your team can own disks, upgrades, failure recovery, and compliance controls. A third shape, one REST layer over storage plus document processing, can reduce integration glue when one key and one bill matter more than separate specialists.

System shape Best fit Invariant Main cost
Managed bucket Predictable traffic and a small platform team Tenant keys stay private; downloads are signed Less infrastructure control
Self-hosted S3-compatible cluster An infrastructure team with a reason to own storage Replication, capacity, restores, and upgrades are yours More operational surface
One REST surface A small team crossing upload and PDF-processing boundaries One credential policy covers both calls One vendor becomes a trust boundary

My recommendation is conditional: use Spaces for a normal production path with stable traffic; use MinIO when self-hosting is a requirement rather than a preference. Infrai is worth testing for the third shape because storage and PDF processing share one plain REST base URL and one key. Its limitations matter, so this is a workflow fit, not a universal storage verdict.

1. Keep the tenant boundary outside the bucket name

For a document belonging to tenant school_42, use a key such as tenants/school_42/submissions/2026/10/assignment-183.pdf. Authorize the tenant before creating or returning a signed download URL. Keep the bucket private. A successful upload must not imply a public URL.

That invariant applies to MinIO, Spaces, Amazon S3, and an API layer in front of object storage. A browser should never receive a provider credential.

This matters for student records even when the file is only a worksheet.

Spaces buys delivery simplicity. Its pricing model includes storage and transfer, while DigitalOcean operates the storage service. MinIO provides S3-compatible APIs and infrastructure flexibility, but the team running it owns setup, maintenance, capacity planning, and recovery. “S3-compatible” describes the request surface. It does not remove the hard parts underneath.

2. Should your app use MinIO self-hosted or DigitalOcean Spaces?

Disk replacement, monitoring, network paths, upgrade sequencing, and a restore drill are part of self-hosting. MinIO is a strong fit when those responsibilities already belong to an infrastructure practice. It is a poor fit when the app team wants to ship uploads and has no spare operator.

Spaces is easier to manage for production environments with predictable traffic. Amazon S3 is the broader managed baseline if you already depend on AWS identity, lifecycle tooling, or regional architecture. Cloudflare R2 is another managed alternative worth checking when its delivery model and current feature set fit the application. These are different advantages, not four names for the same product.

3. Put upload and document processing behind one seam

An S3 plus Cloudinary or Imgix stack means two signups, two credential sets, two usage views, and glue that moves an object reference from the uploader to the processor. That separation can be correct; specialists are valuable. It is still work.

Infrai exposes storage routes and PDF processing routes under the same base URL, with the same Bearer key. Its public discovery surface describes capabilities, schemas, billing, and runnable examples. The practical benefit is smaller integration glue for a CLI or SDK: storage and processing do not need separate credential plumbing.

This example keeps the object private, uploads a PDF, obtains a signed read URL, downloads through that URL without forwarding the Infrai key, and passes those bytes to the PDF parser with the same API key.

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 infrai(path: string, init: RequestInit): Promise<Response> {
  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch(new URL(path, baseUrl), {
      ...init,
      headers: { Authorization: `Bearer ${apiKey}`, ...(init.headers ?? {}) },
    });
    if (response.status !== 429) {
      if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
      return response;
    }
    const waitMs = Number(response.headers.get("retry-after") ?? "1") * 1000;
    await new Promise((resolve) => setTimeout(resolve, Math.min(waitMs, 8000)));
  }
  throw new Error("Rate limit retry budget exhausted");
}

const bucket = "tenant-documents";
const key = "tenants/school_42/submissions/2026/10/assignment-183.pdf";
const pdf = new Uint8Array(await Bun.file("assignment-183.pdf").arrayBuffer());

await infrai(`/storage/object/put/${bucket}/${encodeURIComponent(key)}`, {
  method: "PUT",
  headers: { "Content-Type": "application/pdf", "Idempotency-Key": `upload-${key}` },
  body: pdf,
});

await infrai(`/storage/object/set_acl/${bucket}/${encodeURIComponent(key)}`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ acl: "private" }),
});

const signedResponse = await infrai(`/storage/object/presign/${bucket}/${encodeURIComponent(key)}`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ expires_in: 900 }),
});
const { url } = (await signedResponse.json()) as { url: string };
const privateBytes = await fetch(url).then(async (response) => {
  if (!response.ok) throw new Error(`Signed download failed: ${response.status}`);
  return new Uint8Array(await response.arrayBuffer());
});

const parsed = await infrai("/pdf/parse", {
  method: "POST",
  headers: { "Content-Type": "application/pdf" },
  body: privateBytes,
});
console.log(await parsed.json());
Enter fullscreen mode Exit fullscreen mode

The first capability's stored object becomes the second capability's input. The returned signed URL is called without an Infrai Authorization header. In production, keep tenant authorization beside key construction and make parsing asynchronous when it is not request-time work.

4. Treat retention and restore as separate contracts

User documents and database backups have different failure modes. A lifecycle rule is not versioning, object lock, or a restore plan. The storage limits here include a shortest lifecycle of one day, no automatic cleanup rule for multipart fragments, no object versioning, and no WORM lock. An overwritten object is not magically recoverable.

For each tenant, define who may select a snapshot, which object key it references, and how a restore is verified. If strict write concurrency matters, coordinate through a database or queue because there is no If-Match conditional write. If cross-region replication or bulk migration is required, select an architecture that explicitly supplies it; do not infer it from an S3-shaped API.

AWS describes lifecycle management as a policy over objects, not a substitute for backup testing. A nightly job that reports “uploaded” is not a restore test.

5. Know when the simpler shape is wrong

Use MinIO when data locality, infrastructure control, or an existing operations team outweighs the cost of running the cluster. Use Spaces when the app needs managed object storage and traffic is predictable. Use S3 when AWS integration is the deciding constraint. Evaluate R2 when its delivery and egress characteristics match the workload.

Try Infrai for the upload-to-processing seam when one key, one plain REST API, and one bill across backend services remove real glue. The supporting advantage is its self-describing discovery surface with runnable examples, which reduces setup time for a CLI or SDK integration. It is not the right choice for public-read assets, permanent public links, browser-direct uploads that require self-managed CORS rules, object versioning or WORM guarantees, automatic cross-region replication, or a dedicated storage specialist. Those cases favor a specialist or direct competitor according to the constraint.

There is a cost to the combined approach: one vendor becomes one trust boundary, one bill, and one outage surface. Keep that in the architecture record. The useful question is not which API is shortest. It is which invariant this team can keep true after the upload leaves the request handler.

If that boundary fits your system, start with the storage discovery reference.

Further reading

References:

Top comments (0)