If you are building a B2B SaaS that generates AI training images, you are likely making a critical architectural mistake: proxying every image byte through your API. A new technical breakdown on DEV.to argues that this approach cripples throughput and complicates retention. The recommended pattern is stark: store image bytes in object storage, retrieve them via tenant-authorized short-lived URLs, and keep only searchable metadata plus an absolute retention deadline in your database.

The Metadata Boundary and Provenance

A filename is not provenance, and a URL is not a retention policy. The article emphasizes that your database record must contain an opaque, server-generated key, tenant identity, content type, byte length, SHA-256 digest, prompt hash, and generator model. Do not derive keys from prompts or user filenames, as these can contain personal data or characters that break URL and filesystem boundaries. Instead, use a stable key structure like tenant-id/artifact-id/original to ensure retries are idempotent without leaking sensitive prompt data. Retention must be an absolute timestamp, not a sliding window based on last access. Sliding retention silently turns popular artifacts into indefinite storage costs. By using an absolute retainUntil field, a cleanup worker can deterministically delete objects where retainUntil <= now. The metadata should also include an explicit state field (pending, ready, quarantined, deleted) to prevent race conditions during upload verification.

Throughput Is About Bytes, Not Queries

The throughput bottleneck is almost entirely about moving large files, not database queries. For large images, authenticate the intent and create a short-lived upload capability, then let the storage client or browser transfer bytes directly to object storage. Your API should only receive completion information and verify it. This split prevents the database from having to handle every image download competing with tenant queries. Multipart or resumable uploads are preferred for large files to handle network interruptions, but part size must be measured against your worker concurrency to avoid memory bloat. Retrieval follows the same split. Check tenant ownership and artifact state, then return a short-lived download URL. Never store public object URLs in the database, as this turns a temporary access decision into a durable security leak. The article provides a minimal Node.js boundary where the application owns tenant checks, while a small adapter handles provider-specific signing mechanics.

Testing Retention and Failure Modes

You cannot trust a completion callback alone. You must fetch object metadata, compare content type and length, and calculate a digest at a boundary where bytes are available. The source material warns that a readable stream consumed while hashing cannot normally be uploaded afterward; you must tee the stream or spool it to a bounded temporary file. Testing should involve a matrix of image sizes and concurrent workers, interrupting transfers and retrying completions to record p95 completion times and orphaned-object counts.

Key Takeaways

  • Store bytes in object storage and metadata in the database to decouple throughput from query performance.
  • Use absolute timestamps for retention deadlines to avoid indefinite storage of popular artifacts.
  • Never proxy large file bytes through your API; use short-lived signed URLs for direct client-to-storage transfers.
  • Implement strict verification steps, including SHA-256 digests, before marking an artifact as 'ready'.
  • Keep provider-specific upload mechanics (multipart, resumable) behind an adapter interface for portability.

The Bottom Line

Stop treating your database as a file server. The contracts between your API, the database, and object storage are the product; the specific cloud provider is just a replaceable implementation detail.