Search code examples
ruby-on-railsassetsamazon-cloudfrontcloudinary

How to manage a large number of images in a Rails app?


I have to manage around 200 high quality images in my app. I am currently using Cloudinary to store these images.

But I've seen that many of apps uses a different domain name to store images and other assets (ex: "assets.example.com"). If I understand currently this is called asset_host in a Rails app. I've found documentation on what it is but not much on how to set it up or how the files are served.

How do they do something like that ? Do they pay an other domain name/server and just uses this server to store assets ?


Solution

  • 200 images is not that much, even at 100Mb/image (original+downsized variants) it's just 20Gb of storage, under moderate load can easily be handled by one server without any clouds, additional domains etc. And since you're already storing them in a cloud storage - you do not have to worry.

    asset_host is for asset pipeline (your css/js/images from app/assets which end up in public/assets), not app's managed data

    In the old days assets were served from other hosts to get around connection count limits in browsers(so that assets can be downloaded in parallel and site loaded faster), this is not relevant for modern HTTP/2 (and even the opposite - there's an overhead in establishing additional http connection), unless you're under a really high load or have a specific need for that(for example - when deploying in a container it may be useful to store assets separately).

    Second benefit is that browser will not send app's cookies to other host, which saves a little bandwidth. Many sites set up that domain to be handled by the same physical web server

    As for paying for domain - assets.example.com is a third-level domain for example.com, if you already own the latter - you own it too, just need to set up A(and optionally AAAA) DNS records and the server.