by stavros · 5y ago · 0 comments
EDIT: This is very odd, I'm not really doing any processing on the uploaded files, so it should definitely return the originals. I will have this fixed soon though.
EDIT2: Unfortunately, the saved image in the DB itself is corrupt, so you will need to reupload after I solve this.
EDIT3: Alright this should be fixed! Now I can start submitting animated GIFs there.
EDIT4: Ironically, now ONLY animated GIFs work, because 2am is when I do some of my best work. Stand by...
Whoa now... you're putting images in the database?
Most (all?) large-scale high-volume image storage architectures I'm aware of do not store billions of images as blobs in a database. Instead, they typically store the images as files. The database only holding metadata info and a pointer to the image filename location (or url if using AWS S3 or CDN).
E.g. Facebook is one of the largest MySQL sites (if not the largest) and they don't store photos directly in MySQL.
I've been meaning to investigate trying storing images in postgres on a hobby web project where it could be convenient; I'd still want to make sure I was streaming bytes from postgres to the client, not loading the whole image into memory and only once fully loaded sending it to the client. Looking at the pg API's for my language/platform of choice, it looked at least plausible to do this with a BLOB.
The problems relate mostly to backups/copies/reloads, that kind of thing, and copying an image doesn't cause anything to hiccup. A transaction that transferred 1MB over a modem line was a problem, that could block other commits for a long time, on today's networks 1MB doesn't take long.
Binary data in databases is usually not a great idea, but tolerable in low amounts.
I can't imagine storing images in a database, you're probably better off with a document store.
Relational Databases (well, the ones that I know the internals of) tend to have soft limits on row sizes, in PostgreSQL this is 8kb (which is very small for an image); to overcome this limitation Postgres uses what they call a TOAST table, which forces compression by default, which absolutely crumbles on binary data.
https://www.postgresql.org/docs/13/storage-toast.html
But, if it works, I'm not complaining- and I'm very certain that other such sites have worse architectural flaws in the beginning- this one is pretty easy to overcome if it becomes an issue and can be alleviated with aggressive caching of CDNs/varnish to buy you time if there's immediate issues. :)
But yes, there's probably time for that optimization later, if the service takes off.
and the uploaded image was a negative of it.
it resulted in https://imgz.org/i5Q2gzwB.png