Saving costs on Heroku for Ruby on Rails apps


These are some tips to save your costs when running Ruby on Rails apps on Heroku.com. These tips were mainly for developers. You may send those to them though you can do some of the tips by yourself.


Verify your Heroku account with credit card to get 1000 free dyno hours per month

If you're not verified account, you only got 650 dyno hours. Assuming your app is not yet going to live, it's better to usethose 1000 free dyno hours. With 1000 hours of wall-clock time, even if your app did not sleep, you won't run out of hours since there is only 730 hours per month, more or less.


Ensure, that all unused test/staging apps were put in sleep.

Because that free 1000 dyno hour is for an account, not for each app you had in your account. You can do this through Heroku dashboard and just switch off the web dyno for unused apps there.


Reduce the number of your dyno.

For a web app which had less than 200 unique visitors per day, based on my own experience, it is enough to choose the "Hobby" plan with 1 dyno and 512MB RAM. It costs you $7 per month. 


Ask your developers to find out the bottle neck on your app.

This is important. You can use New Relic add on ( available for free plan, as long as you had verified your account ). Once you and your tech teams found out the bottle neck, ask them to optimize it. For heavier processing, it's better to move it on a background job and utilize Heroku Scheduler add on. There is no additional cost for utilizing Heroku Scheduler add ons, and it can run every 10 minutes.


Again, ask your developers to use the available resource as much as possible.

You can advice them to use Rails server which support multi-threads like Puma or Unicorn, instead of Webrick and Thin -- for your production app. Puma can improve the ability of your apps to serve more concurrent users though in many cases, Puma will slowly eats your memory (RAM) over the time. One of workaround is installing puma-worker-killer gem to kill and restart one of Puma workers when the memory is almost exhausted.


Reduce the number of paid add ons.

Ask your tech team to think more whether it's really needed to use those paid add ons. Ask them to think for alternatives or build their own solution instead of relying too much on paid add ons. Based on my experience, this can save your costs considerably.


For staging app or test app, always aim for free dyno.

If possible, never had any more costs on those staging app or test app except those apps need important function where paid add ons is mandatory. Example case is if your Rails app depends on "thinking-sphinx" gem for the searching function. On Heroku, you need "flying-sphinx" add ons to make it works.


Maximize your team ability.

If your team had capability to set up, maintain, scale, and optmize the infrastructure, then it may make sense to move your entire project out of Heroku. As an alternative, Digital Oceandroplet cost you $5 per month and you get a one droplet ( similar to a VPS ). If you had a guy or team with sufficient capability handling it, why not move it there? Another alternative is moving to AWS EC2, but here you pay as you go. You may ask your team to help you calculating each cost for your project, including the risk and consequences among them: Heroku, AWS, or Digital Ocean.


P.S. I am not affiliated or work for any of them. I just had some experiences to work on all of those services.


Follow me


Related Links


  1. Recommended services to host Ruby on Rails apps
  2. Why Hosting Your App On Heroku Is A Winning Choice
  3. Comparison Shared Hosting and Heroku for beginners