Search code examples
ruby-on-railsherokuamazon-s3thumbnailsamazon-cloudfront

Of the proper use of Heroku, Rails, Dragonfly, S3 and Cloudfront


There seems to be a lot of doubt as to how to properly handle image and thumbnails within a Heroku/Rails application.

In my last application, we tried to get rid of the S3 bucket, and have all our images generated from our Rails application, using Dragonfly, to Cloudfront's CDN. That seemed like a good idea, until we realized that Cloudfront would request each thumbnail to our Heroku application one time for each geographical location.

My question here is this: what is the best process, in such an environment (Heroku, Rails, Dragonfly, S3/Cloudfront), to generate thumbnails and have them served/cached from a Cloudfront CDN ?


Solution

  • Why remove S3?

    By pushing your thumbnails to S3 and putting CloudFront on top you remove that fetch for each endpoint.

    If the images you are serving have a short lifespan and it is likely to be served several times, then I see justification for your current setup. A request per CloudFront endpoint is a small price to pay when you are serving that image thousands of times.

    If the image has a longer lifespan then put it back in S3 and put CloudFront on top. This would remove the load on your Heroku instance that you are worried about.