Saving images on heroku DB versus Amazon S3: Pros Cons?

amazon-s3, database, heroku, image

Solution

Save them on S3. Performance wise, it's leagues ahead of storing on a database - if you store on a database, the request has to go through your web application, then make a DB request (or hit varnish right away, but that is true in any case). Further, unless you have a lot of dynos, this means that users are only be going to getting images one at a time (thin is single threaded except under special configuration for long running requests). With S3 (or any cloud storage solution), it's as simple as another HTTP request to a static resource - your app doesn't even have to know about it!

Problem

Ive searched everywhere on the internet for a comparison of saving images in a Heroku PG-SQL db versus saving them on Amazon S3. Im currently trying to make a design decision. However, this is the first time Im writing a web app. So far this is what I know to make the decision: - Saving images on DB slows the performance of the app - Saving images on Db is expensive versus the filesystem - You cannot access the file system in Heroku - You can save images in Amazon S3 for a very cheap rate - Images stored on Amazon S3 cannot be processed before saving if they donot pass through the application on Heroku - Retrieving and saving images on Amazon S3 costs money for each call - If the browser is retrieving an object that has an image, then the browser makes 2 requests per object, 1 for the data from heroku and another from S3 for the image. This can be problematic since the browser can only make certain >m.unt of requests per unit time. - Saving images on DB if the images are small in size doesnt deteriorate performance a lot. - Deleting images from Database can cause fragmentation These are the fact I know about the topic. As things stand right now, Im leaning towards saving images in the Heroku DB. Since they are mostly thumbnails/small images and their size is less that 250MB I was wondering if someone could let me know if these facts are erroneous or if there are other consideration I need to make in making this design decision. Also, I would really appreciate it if someone could point me to some good discussions on the web on this topic. I couldn't find any that exactly were on this discusssion.

Original source