r/PostgreSQL • u/easybits_ai • 4d ago
Projects Storing generated PDFs in Postgres vs object storage: where do you draw the line?
/r/n8n/comments/1y6s8tp/storing_generated_pdfs_in_postgres_vs_object/
26
Upvotes
View all comments
29
u/yvrelna 4d ago edited 4d ago •
If you want to do blobs in the database, at least do them properly and use the proper blob/bytea type instead of base64-encoded varchar.
Unless you needed the blob to be part of a transaction, it's a bad idea to be storing a blob in the most expensive and hard to scale part of the system which is the relational database.
An object storage are much cheaper and easier to scale horizontally. A CDN can cache frequently downloaded blobs.
Even if you run your own file server, the OS and the web server can serve downloaded file from disk extremely efficiently with zero copy syscall like sendfile or copy_file_range.
By storing and serving a blob in the database, it means you're tying a database server connection, an application server worker, and the RAM needed to cache the file in-memory while the file is being downloaded and base64-decoded. All of which are unnecessarily expensive components when simpler, cheaper, and much more easily scalable solutions exists for not too much extra effort.