Stop Treating Your Object Storage Like a Database
Adil Sher
Author
I realized my mistake six months into a SaaS project when our support team asked me to filter reports by retention date. I had been uploading files directly to S3, storing metadata in Postgres, and treating the bucket like it was a searchable datastore. It wasn't. Every time someone needed to query reports, I was doing bucket listings, parsing prefixes, and reconstructing state from object metadata that was never meant to be comprehensive. The system worked until it didn't, and by then I'd already built the wrong mental model into my entire architecture.
This is exactly the problem I see addressed in a piece about SaaS file retention that made me stop and reconsider how I'm handling uploads in my current project. The core insight is simple but profound: your object storage and your database are doing fundamentally different jobs, and trying to blur those lines creates chaos in production.
The Architecture That Actually Works
The pattern here is elegant in its separation of concerns. When a user wants to upload a report, you don't just hand them S3 credentials and hope. Instead, you create a database record first, marking it as "pending"-with all the metadata that matters: tenant ID, owner ID, revision number, deletion deadline. Then you generate a short-lived signed upload URL and let the browser upload directly to object storage without touching your application server.
This matters because it means your database is always the source of truth. It's not scrambling to reconstruct what's in the bucket. When someone requests a download, you don't list objects; you query the database, check that the requesting user actually owns that report, and only then mint a signed URL for that specific key.
I love this approach because it respects the constraints of each system. Postgres is good at ownership, access control, and state transitions. Object storage is good at holding bytes cheaply. Neither system is pretending to do the other's job.
The Parts That Actually Hurt in Practice
What struck me most about this framework is the emphasis on treating deletion as a database state transition, not a bucket operation. Instead of actually deleting objects, you mark them for deletion, set an expiration timestamp, and have a background job handle cleanup later. This sounds like extra work until you've debugged a production incident where your retention policy and your actual bucket state were out of sync.
The example code uses a new object key for every revision. That's deliberate, it means you can't accidentally overwrite a report someone is downloading. It also means your revision history is implicit in the object store structure, which feels right to me.
Where I'd push back slightly: the article mentions using Infrai as an all-in-one backend service, which is pragmatic for solo builders but raises questions if you're already locked into AWS or GCP. The core principles, signed URLs, database-driven access control, stateful pending uploads, work perfectly fine with standard S3 or Google Cloud Storage. Don't let the specific provider distract from the architecture.
My Take: This Solves a Real Pain
I've spent too many hours debugging edge cases around file access in SaaS products. The pattern described here eliminates most of them by making the database the single source of truth for "who can see what." Your support team can filter reports by any dimension they want. Your billing system knows exactly when files should expire. Your audit logs reflect actual business decisions, not bucket side effects.
The signed URL approach is particularly smart. It's time-scoped, tenant-scoped, and doesn't require your application server to stream bytes for every download. Users get a direct link, your infrastructure doesn't melt, and you're not exposing raw S3 URLs that could be shared or leaked.
One thing I'd add: test your retention policy ruthlessly. Write a job that actually deletes expired objects and verify it works in staging first. I've seen teams set deletion deadlines they never actually enforced because nobody owned the cleanup task.
What You Should Actually Do
If you're building a SaaS product that handles files, reports, documents, exports, anything, this is worth implementing correctly from the start. Create that database record before you generate the upload URL. Make deletion a scheduled background job. Query your database, not your bucket, when users request their files.
The mental model shift is worth the effort: your database knows about files, your storage holds them. That's it. That's the whole system.
What's your current approach to file retention? Are you already separating access control from storage, or are you discovering the hard way like I did?
Source: This post was inspired by "SaaS Report Retention: 4 Rules for Private Browser Upload and Signed Object URLs" by Dev.to. Read the original article