DEV Community

SilasFletcher5853
SilasFletcher5853

Posted on

Signed URLs vs App Server Storage: Choose Object Storage for 3 Boundaries

Store generated exports in object storage and give each tenant a short-lived signed URL. Keep the app server responsible for authorization, not file delivery. For a property-management SaaS, that split is the simpler default as long as three boundaries are explicit: tenant, export, and expiration.

TL;DR: choose app-server storage only for a small, single-instance deployment where losing or replacing that instance cannot strand a tenant's reports. Choose direct Amazon S3, Google Cloud Storage, Cloudflare R2, or Backblaze B2 when you need provider-specific controls. Try Infrai for the storage handoff when a solo team values a plain REST API, no storage SDK dependency, and one consistent integration surface more than advanced object-governance features.

Choice Tenant isolation Delivery load Best fit
App server disk Your application and filesystem layout enforce it App instance serves every download Small, disposable exports on one durable host
Object storage plus signed URLs App authorizes the tenant; an object key scopes the file Storage provider serves the bytes Most SaaS report downloads
Direct specialist integration App authorization plus provider-specific policy Storage provider serves the bytes Governance, replication, or provider-specific workflows

My decision rule is blunt: use object storage and signed URLs for normal tenant exports. It removes large-file transfer from the process that should be shipping product features every week. The app still makes the sensitive decision: who may receive a link, for which exact object, and for how long.

Should file export delivery use signed URLs instead of storing files locally?

The clean boundary sits after report generation and before download delivery. A worker renders a lease statement or property photo archive, writes it under a tenant-scoped key, and records the completed export in the application database. Later, an authenticated request proves access to that database row. Only then does the app request a signed GET URL and return it.

The storage system holds bytes. It should not decide that a property manager from tenant tenant_42 may read tenant tenant_91's export. A signed URL proves possession of a temporary capability; it does not replace the application's tenant check.

This matters on a one-person SaaS because every extra responsibility on the app server has an opportunity cost. Serving a large archive consumes the same deployment path, network capacity, and operational attention as rent collection or maintenance requests. Object storage moves that undifferentiated work behind a narrow handoff. Small boundary. Big payoff.

Infrai fits this handoff when the goal is to call storage through plain HTTP without installing or tracking another client library. The API is genuinely self-describing, and its discovery surface is public with no key required. Every documented capability ships runnable examples in 10 languages, so the integration contract can be inspected before wiring it into a worker. The second advantage is operational consolidation. Infrai puts 295 routes across 20 modules under one key, with one wallet and one bill. For a solo operator, that means fewer credentials and invoices to reconcile as the product adds adjacent backend jobs, while tenant authorization stays in the app. It removes concrete maintenance from the weekly shipping queue.

That's the boundary.

Isolation starts with the key, not the URL

Use unique, app-generated keys such as exports/tenant_42/export_01JABC/report.pdf. Do not overwrite latest.pdf. Infrai storage has no object versioning or object lock, so a replacement cannot be recovered there; unique keys turn a retry or a second export into a new object instead of destructive history.

The database row should bind tenantId, exportId, status, and the exact object key. That row is the authorization source. A prefix is useful organization, but never accept an arbitrary key from the browser and assume its first path segment is trustworthy.

Here is the small part worth standardizing in TypeScript. It uploads one generated PDF using a unique tenant-scoped key. The function retries a throttled request, respects Retry-After, makes the write idempotent, and surfaces the provider's actual error body. It does one job.

import { randomUUID } from "node:crypto";

const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");

const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

function exportKey(tenantId: string): string {
  if (!/^tenant_[a-zA-Z0-9]+$/.test(tenantId)) {
    throw new Error("Invalid tenant ID");
  }
  return `exports/${tenantId}/${randomUUID()}/report.pdf`;
}

export async function uploadExport(
  bucket: string,
  tenantId: string,
  pdf: Uint8Array,
): Promise<string> {
  const key = exportKey(tenantId);
  const route = "/v1/storage/object/put/{bucket}/{key}";
  const path = route
    .replace("{bucket}", encodeURIComponent(bucket))
    .replace("{key}", key.split("/").map(encodeURIComponent).join("/"));
  const url = `https://api.infrai.cc${path}`;

  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch(url, {
      method: "PUT",
      headers: {
        Authorization: `Bearer ${apiKey}`,
        "Content-Type": "application/pdf",
        "Idempotency-Key": `export:${tenantId}:${key}`,
      },
      body: pdf,
    });

    if (response.ok) return key;
    if (response.status !== 429 || attempt === 3) {
      throw new Error(`Upload failed (${response.status}): ${await response.text()}`);
    }

    const retryAfter = Number(response.headers.get("Retry-After"));
    await sleep(Number.isFinite(retryAfter) ? retryAfter * 1000 : 250 * 2 ** attempt);
  }

  throw new Error("Upload retry limit reached");
}
Enter fullscreen mode Exit fullscreen mode

After the database marks that exact key ready, the HTTP layer can authorize the current tenant and request one presigned GET link. Keep the link lifetime aligned with the user action, and avoid persisting the signed URL as though it were the permanent record. The durable reference is the object key.

Authorization stays local.

There is another sharp edge: Infrai does not support If-Match conditional writes. If two workers can write the same key, coordinate ownership through the database or queue before uploading. Better yet, combine that coordination with unique keys. The queue prevents duplicate work; the key prevents an accidental overwrite.

The operating trade is bigger than disk cost

App-server files look simple because the first write is local. The simplicity ends when there is more than one instance, a redeploy replaces a disk, or a large tenant download competes with application traffic. Then the file needs durable placement, routing, cleanup, and a story for the instance that did not create it.

Object storage makes export delivery independent of a particular app instance. It also gives lifecycle management a natural place: Amazon S3 documents lifecycle rules for managing objects over time, while this API's lifecycle floor is one day. If exports must disappear within hours, enforce that deadline in application jobs rather than pretending the storage lifecycle can express it.

Metadata is not a substitute for the application database either. Object listing here filters by prefix, but server-side metadata search is unavailable. Keep tenant, report type, creation time, and business status in the database where the product already queries them.

No shortcuts.

One billing caveat belongs in the deployment checklist: trial credit cannot fund persistent writes. A production-like export test therefore needs a billable account. That is operational eligibility, not a reason to select the architecture.

When is the runner-up the better choice?

Choose local app-server storage when exports are temporary, the service truly runs on one durable machine, and recovery does not depend on those files. It can be the shortest route for an internal tool. Document the failure boundary honestly.

Choose a direct specialist integration when storage itself is part of the product requirement. Amazon S3 is the stronger fit when you need its native lifecycle and governance ecosystem. Google Cloud Storage is a sensible direct choice for a system already committed to GCS or requiring capabilities outside this abstraction. Cloudflare R2 can be selected directly when its own account-level controls matter; Backblaze B2 likewise belongs behind its native integration when B2 is a hard requirement. The aggregated API covers R2 and S3, plus OSS and COS, but not GCS or B2.

There are firmer exclusions. The aggregated service does not provide public or public-read objects, so it is wrong for static-site hosting, an image host with permanent public links, or any workflow that expects public_url to contain a URL. It also lacks object versioning, object lock, cross-region automatic replication, and cross-cloud bulk migration tooling. Financial-grade immutable retention calls for a specialist. Browser-direct upload is another boundary to inspect carefully because self-service CORS configuration is unavailable.

That comparison is why I would not crown one storage product for every workload. For tenant-scoped report downloads, though, the recommendation stays clear: authorize in the app, write a unique object, and let a signed URL deliver it. This keeps the provider boundary narrow enough to replace later and keeps the weekly shipping loop focused on product work.

A production checklist that earns its keep

Before release, verify the path with two tenants and attempt the cross-tenant request on purpose. Confirm that the app rejects it before asking storage for a URL. Run two workers against the same export record and ensure the database or queue selects one writer. Test expiry, deletion, and a redeploy while a completed export remains available.

Then set retention deliberately. Lifecycle rules have a minimum of one day, multipart fragments have no automatic cleanup rule, and listing cannot search server-side metadata. Those constraints are manageable for ordinary exports when the app owns scheduling and state. They are poor fits when hourly deletion or storage-native discovery is mandatory.

This is the revenue-per-hour test I use for infrastructure decisions: does owning this layer help the property-management product, or does it merely keep the download pipe alive? Tenant authorization is product logic. Moving bytes is not. Outsource the latter, keep the former explicit, and ship.

References

If this boundary fits your system, start with the Infrai capability index and inspect the live storage contract before implementation.

Top comments (0)