DEV Community

Cover image for How to Use Heroku For Free
Adam McCrea
Adam McCrea

Posted on • Originally published at railsautoscale.com

How to Use Heroku For Free

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, each increasing in price and performance characteristics. At the lowest tier are the free dynos.

Heroku dyno types & pricing

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.
  • Free dynos do not support Heroku 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. 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 and UptimeRobot.

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. 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:

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, but this is no longer the case. 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, 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.

Heroku account billing page

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 are generally more powerful as they get more expensive, but that's not the case for cheapest three.

Heroku dyno types

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 (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.

Some background work could also be performed on a periodic basis with Heroku 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 is only available on paid plans, check out Librato's free add-on for similar metrics and alerting.

Librato metrics

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 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

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 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

Ouch. Heroku's free Postgresis 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.

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 — 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 — Monitor and diagnose app performance issues. I install this on every app.
  • 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 — Fantastic error monitoring service with generous free plan.
  • Redis Cloud – Heroku has their own Redis service, but you'll get more for your money (or for free) with Redis Cloud.
  • 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.

Top comments (1)

Collapse
 
goodevilgenius profile image
Dan Jones

It's sad that they got rid of this.