r/n8nforbeginners • u/easybits_ai • 6d ago
Storing generated PDFs in Postgres vs object storage: where do you draw the line?
👋 Hey n8n for Beginners 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/Connect-Classroom682 3d ago
I never (NEVER) save a binary file into a database.
Save it a pregenerated file, or you can create an API server to convert data to pdf without pay for it again
Or you just can show an html with same data and let the user print it to pdf