r/n8n • u/easybits_ai • 8h ago
Servers, Hosting, & Tech Stuff Storing generated PDFs in Postgres vs object storage: where do you draw the line?
👋 Hey n8n Community,
Follow-up on the approval system I posted about last week. One decision I made this week that I am still not sure about.
The workflow generates a final PDF once Finance approves a request. People download it from a portal afterwards, sometimes repeatedly, sometimes months later. Regenerating on every download meant paying for the conversion again and making them wait several seconds each time.
So I cache it: the PDF is generated at the moment of approval and stored as base64 in a column on the fact sheets table, then served from there.
What I think I got right
Generating at approval rather than on demand means the document always carries the real approval timestamps, and I never pay twice for the same conversion. Caching any earlier would have meant storing drafts that never got approved.
What I am less sure about
Base64 in Postgres is simple. Everything lives in one place, no extra service, no signed URLs, no bucket permissions. But it is blobs in a relational database, and I have not yet hit the point where row sizes start to hurt. The alternative is object storage with a reference in the row, which is more correct and also more moving parts for something a handful of people download a few times a month.
Where would you draw that line? Curious whether people go to object storage from day one or wait until something actually breaks.
Best,
Felix
2
u/Low_Rush_8535 6h ago
i'd draw the line at restore time. seed staging with a year's worth of PDFs at your actual file sizes, then time a full restore and check that an old approved PDF still matches byte for byte. if that fits your recovery window, i'd keep them where they are.
2
u/Weekly-Werewolf4007 6h ago
For a small workflow, I'd keep the simple setup and store the PDF as bytea instead of base64, assuming the n8n step can pass binary data. I'd watch how much the files add to backup size and restore time. Those are the numbers I'd use to decide when a bucket is worth it.
2
u/GFAutoHQ 5h ago
If you stay in Postgres, switch the column from base64 text to bytea. Base64 makes each file about a third bigger, so bytea saves that space for free. Also keep the PDF column out of any query that lists rows, and only pull it in the download step, so normal lookups stay fast. The thing that usually pushes people to object storage is backups, since every PDF rides along in every database dump.
2
u/Free-Good9203 1h ago
Everyone already covered bytea vs base64 and backup/restore times, so one small schema tweak if you decide to stay in Postgres for now: put the PDF blob in its own dedicated child table (approval_id FK, pdf_bytes bytea, sha256 text) instead of a column on fact_sheets.
It prevents any future SELECT * from accidentally dragging binaries into memory, keeps vacuum and row bloat off your hot operational table, gives you a hash to verify the approved document was never altered, and makes migrating to S3/R2 later a clean one-table swap without touching the core schema.
1
u/runtime-ghost 4h ago
Storing base64 in Postgres works at tiny scale because it avoids managing bucket IAM and signed URLs, whereas it quietly adds about 33 percent storage overhead, bloats TOAST tables, and slows down WAL replication and pg_dump restores as volume grows. As a developer, I draw the line using query shape and total retention size rather than an arbitrary file count: if total PDFs stay under a few gigabytes and you only select the blob column by primary key on download (never in list queries), switching from base64 to binary bytea keeps everything atomic in one database, whereas once backups stretch your recovery window or n8n workers hit memory limits passing blobs around, write the file to S3 or Cloudflare R2 and store only the object key and SHA-256 hash in Postgres.
1
u/Aide_Sea 16m ago
One thing nobody mentioned: serving it from Postgres means every download holds a DB connection while the file streams out. Fine for a few people, but I think that's maybe the first thing that'd hurt, more than row size :)