How to Use Heroku For Free
Tags: heroku, rails, devops
Published: 2021-05-21 16:12:59

Heroku is the easiest way to deploy and host a server-rendered web app, and it doesn't have to cost an arm and a leg. In fact, **for some apps you can do it for free**.

This guide covers everything you need to know about using Heroku for free, including free dynos, the free Postgres database plan, and free add-ons.

How does Heroku work?
---------------------

Heroku runs your app on "dynos". This is just Heroku's word for "container" or "server". For your app to run and serve requests, you need at least one web dyno running. Adding more web dynos will increase your capacity to handle a higher volume of requests.

Heroku offers [six dyno types](https://www.heroku.com/pricing#containers), each increasing in price and performance characteristics. At the lowest tier are the free dynos.

![Heroku dyno types & pricing](https://rails-autoscale.ghost.io/content/images/2021/05/CleanShot-2021-05-13-at-14.46.09@2x.png)

Running a free dyno literally costs you nothing, and it will always cost you nothing.  No matter how many hours they run or what you have remaining in your free dyno quota (more on this below), **you will never be charged for running free dynos.**

Free dyno limitations
---------------------

Naturally, "free" comes with some limitations.

*   Free web dynos will idle (sleep) after a period of inactivity. The next request will wake it up, but users will notice a delay while the app is started.
*   You have a limited number of "free dyno hours" each month. When you've exhausted your quota, your app shuts down.
*   Free dynos are [not available for Heroku Teams](https://devcenter.heroku.com/articles/heroku-teams#pricing-and-limits).
*   Free dynos do not support [Heroku SSL](https://devcenter.heroku.com/articles/ssl) for custom domains.
*   Heroku metrics are not available for free dynos.

Those limitations might seem like dealbreakers, but fear not! We have workarounds for many of them.

How to prevent free dynos from sleeping/idling
----------------------------------------------

Free dynos will [sleep (shut down) after 30 minutes of inactivity](https://devcenter.heroku.com/articles/free-dyno-hours#dyno-sleeping). This is actually a _feature_ to avoid using up your free dyno hours. **This makes free dynos great for staging/test environments that don't have constant usage.**

If you want your free web dynos to run 24/7, you'll need to ensure they receive at least one request every 30 minutes. **The easiest way to prevent your dynos from sleeping is using an uptime monitor that pings your app all day long.**

There are _lots_ of uptime monitor services, and there's a good chance you're already using one. If you need a free one (you're reading about free dynos, right?), I've had success with free plans from [Freshping](https://www.freshworks.com/website-monitoring/) and [UptimeRobot](https://uptimerobot.com/).

Note that **dyno sleeping** ****only applies to web dynos****. If you're running a "worker" dyno (asynchronous/background job processing), it will not go to sleep. It's _very_ easy to consume your free dyno hours quota with worker dynos.

How are free dyno hours calculated?
-----------------------------------

Heroku [prorates dyno usage to the second](https://devcenter.heroku.com/articles/usage-and-billing#cost). If you run a free dyno for 30 minutes, that'll use 0.5 hours from your free dyno hours quota. If you run an app with single free dyno 24/7 for 31 days, that'll use 744 (24 x 31) of your free dyno hours.

****So how many free dyno hours do you get?****

From the [official docs](https://devcenter.heroku.com/articles/free-dyno-hours):

> Accounts are given a base of 550 free dyno hours each month. In addition to these base hours, accounts which verify with a credit card will receive an additional 450 hours added to the monthly free dyno quota. This means you can receive a total of 1000 free dyno hours per month, if you verify your account with a credit card.

Pretty simple. Add a credit card, and you'll have 1,000 free dyno hours each month. Since a full month is at most 744 hours, this means **you can run a single web dyno 24/7 for free**.

* * *

### Heroku trivia

In 2015-2016 there was a time when free dynos could [only run 18 hours a day](https://blog.heroku.com/heroku-free-dynos), but this is [no longer the case](https://devcenter.heroku.com/changelog-items/907). Free dynos will run 24 hours a day as long as you have sufficient hours available in your quota.

If you had a free app running when these new rules [launched in 2016](https://blog.heroku.com/announcing_heroku_free_ssl_beta_and_flexible_dyno_hours#flexible-free-dyno-hours), you may have been grandfathered in with more than 1000 free dyno hours available to you. Lucky you!

* * *

Check your free dyno usage
--------------------------

So how many free dyno hours do ****you**** have available? Check out your [Heroku billing page](https://dashboard.heroku.com/account/billing).

![Heroku account billing page](https://rails-autoscale.ghost.io/content/images/2021/05/CleanShot-2021-05-13-at-15.06.42@2x.png)

This is a great way to check up on any forgotten apps that are consuming your free dynos quota!

Free vs. Hobby vs. Standard-1x dynos
------------------------------------

Heroku's [six dyno types](https://devcenter.heroku.com/articles/dyno-types) are _generally_ more powerful as they get more expensive, but that's not the case for cheapest three.

![Heroku dyno types](https://rails-autoscale.ghost.io/content/images/2021/05/CleanShot-2021-05-13-at-15.07.56@2x.png)

**Free, Hobby, and Standard-1X dynos are exactly the same hardware with the same performance characteristics.** Hobby dynos only lift a few of the feature limitations of Free dynos:

*   Hobby dynos do not go to sleep.
*   Hobby dynos support Heroku SSL for custom domains.
*   There's no "hours quota" for Hobby dynos.

One shared limitation between Free and Hobby dynos is that you cannot scale to more than one dyno per process. If you need to scale up to two web dynos, for example, you must use standard or performance dynos.

SSL for free dynos
------------------

SSL is no longer optional these days—you must serve your web app via HTTPS. On free dynos, you have two options:

*   Serve your app from the default Heroku URL. Every Heroku app is available by default at \[app-name\].herokuapp.com, and all of these URLs include SSL support out of the box.
*   If you need a custom domain, you'll need to use a service like [Cloudflare's Flexible SSL](https://support.cloudflare.com/hc/en-us/articles/200170416-End-to-end-HTTPS-with-Cloudflare-Part-3-SSL-options#h_4e0d1a7c-eb71-4204-9e22-9d3ef9ef7fef) (also free). Your users will connect via HTTPS to Cloudflare, and Cloudflare will connect via HTTP to your Heroku app.

If neither of these options are acceptable to you, you'll need to use one of the paid dyno types.

Running a production app on free dynos
--------------------------------------

Since you can run a free dyno (which is _equivalent to a standard-1x dyno_) for 1,000 hours per month, ****that means you can run your production app 24/7 on Heroku for free, right?****

Well, that depends.

Most production apps need at least a web process and a background worker process for things like sending email and communicating with third-party services. This requires a "worker dyno" in addition to your "web dyno", which exceeds your 1,000 hour allotment if you run them both all month. And free worker dynos do not automatically sleep like free web dynos do, so they'll be running 24/7 unless you manually scale them down.

This is where you need to decide just how "production-scale" your app needs to be right now. You could perform this work synchronously within your web process instead of backgrounding it, or you could find a way to [run async jobs within your web process](https://github.com/brandonhilkert/sucker_punch).

Some background work could also be performed on a periodic basis with [Heroku Scheduler](https://devcenter.heroku.com/articles/scheduler), which creates a "one-off dyno" and only uses dyno hours for the time it's running.

**If you really do need a separate worker process (and most full-stack production apps do), then you've probably outgrown free dynos.**

When to upgrade your free dynos
-------------------------------

If you're already running your app on free dynos, how will you know when you've outgrown them? If your app is a successful product with growing traffic, you will certainly hit a point where a single free dyno is insufficient.

You can't scale free dynos horizontally—in other words, you can't add more than one free web dyno to your app. If one dyno is not enough for you, you'll need to upgrade to standard dynos.

The best way to know when you're outgrowing free dynos is by watching your metrics. Since [Heroku's metrics tab](https://devcenter.heroku.com/articles/metrics) is only available on paid plans, check out [Librato's free add-on](https://elements.heroku.com/addons/librato) for similar metrics and alerting.

![Librato metrics](https://rails-autoscale.ghost.io/content/images/2021/05/CleanShot-2021-05-13-at-16.20.18@2x.png)

If you're seeing high request times and/or HTTP errors, there's a good chance you're outgrowing free dynos.

It's also possible your app is just slow. An APM tool like [Scout](https://elements.heroku.com/addons/scout) will help you drill down into specific bottlenecks. A full tour of Scout is beyond the scope of this article, but generally speaking, high request queue time indicates a capacity issue (need more dynos).

![Scout APM screenshot](https://rails-autoscale.ghost.io/content/images/2021/05/CleanShot-2021-05-13-at-16.25.38@2x.png)

If you're seeing lots of time spent in other parts of your stack (Ruby, Postgres, etc.) then adding more dynos will not help. You'll need to investigate your app code to resolve the performance issue.

* * *

_✉️ Want notified when I write more articles like this one? Sign up for my_ [_Mastering Heroku_](https://masteringheroku.substack.com/) _mailing list! Very infrequent, very relevant, no sales pitches._

* * *

Heroku's free Postgres database
-------------------------------

Whew! All that and we haven't even talked about your database yet. Much like dynos, Heroku offers multiple tiers of Postgres.

![Heroku Postgres options screenshot](https://rails-autoscale.ghost.io/content/images/2021/05/CleanShot-2021-05-13-at-16.31.50@2x.png)

Ouch. **Heroku's [free Postgres](https://elements.heroku.com/addons/heroku-postgresql)is limited to 10,000 records**.

Even the smallest production apps are likely going to exceed this limitation. Here are your options:

*   Upgrade to a paid Heroku database plan, starting at $9/month for 10,000,000 records.
*   Use a third-party hosted database provider with a more generous (but still quite limited) free plan, like [ElephantSQL](https://www.elephantsql.com/plans.html).

There's really no way around it. Your database will eventually be the most expensive layer of your stack, so be prepared to pay for it early.

Free Heroku add-ons
-------------------

One of the best parts of Heroku is the add-on ecosystem, and many add-ons have excellent free plans. Here are some of my favorites:

*   [Librato](https://elements.heroku.com/addons/librato) — As mentioned this earlier, Librato gives you visibility into your app metrics above and beyond what Heroku provides (and Heroku provides no metrics for free dynos).
*   [Scout APM](https://elements.heroku.com/addons/scout) — Monitor and diagnose app performance issues. I install this on every app.
*   [Logentries](https://elements.heroku.com/addons/logentries) — You'll need a way to view your application logs. Logentries isn't the best option, but it has the most generous free plan.
*   [Sentry](https://elements.heroku.com/addons/sentry) — Fantastic error monitoring service with generous free plan.
*   [Redis Cloud](https://elements.heroku.com/addons/rediscloud) – Heroku has their own Redis service, but you'll get more for your money (or for free) with Redis Cloud.
*   [AutoIdle](https://elements.heroku.com/addons/autoidle) — This one isn't a free option, but it's super useful if you've upgraded to paid dynos and you want to save money when your app isn't being used. It essentially replicates the "sleeping" behavior of free dynos. Very nice for staging/QA apps.

Putting it all together
-----------------------

So with all this in mind, when do Heroku's free offerings make sense for _you_?

*   **Launching a side project.** There's a good chance the side project won't get much traction at first, so throw it on free dynos and a free Postgres DB and see what happens! You won't have enough free hours to run worker dynos, but who cares... until you have real users and revenue, you can do everything in your web process.
*   **Running a staging or QA app.** These are perfect for free dynos because they don't need to run all the time. Your staging data might even fit within a free Postgres DB.

Beyond those use cases, you're probably going to have to pay for Heroku. The free options exist to try out the service, play with an idea, and run experiments. Once you're running a "real app", you're hopefully at a point where you can spend a few dollars on hosting.

Questions or thoughts on this article? Let's chat [on Twitter](https://twitter.com/adamlogic).