TLDR; scroll down to “The Ultimate Loophole”
Several months ago I was deploying my apps exclusively to Heroku, but quickly realized how costly it could get. What if I had 6 apps, which each have a frontend and a backend. That would be 12 dynos x $7/month which comes to $84/month or $1,008/year.
I would happily pay the $$$ if people were actively visiting the sites, but there’s practically zero traffic because all of my apps are either practice apps or portfolio pieces. For a while, I would just let them hibernate; but when there were visitors, people would think my apps were broken when it was just sleepy.
That‘s not a good look, but I’m also not made of gold so I turned to Google for a better way to go about life.
I found Kaffeine when I only had 2 apps (4 dynos) that I wanted to deploy. It does exactly as promised so I was happy with it until it used up all 1,000 free hours halfway into the month. I thought, “Well that’s not sustainable, back to Google.”
Introduce Netlify, the alternative app deployment service. They also offer a free tier and the app doesn’t go to sleep! The only downside is that it only hosts frontend repos. I can work with that though, so I moved my frontends to Netlify and kept my backends on Heroku to relieve half of the Kaffeine shots. This was an okay solution, but then I got creative and this is where the magic really happens.
- Let’s stop the Kaffeine shots for Heroku because we’re wasting a lot of free hours there.
- Since Netlify doesn’t go to sleep, make the frontend wake the Heroku backend up only when your site is being visited.
- We can do this with some clever coding.
Now that your Netlify frontends and Heroku backends are talking to each other, you get the best of both worlds.
- Netlify frontend never sleeps, so when a visitor comes to your site, you won’t get that awkward “Application error” page that Heroku displays. Static information and images render within 2 seconds (Netlify is fast), so it looks like your site loads quickly.
- But your site isn’t actually done loading because the data isn’t coming in for another 2–3 seconds (Heroku dyno is still spinning up in the background unless it’s already awake).
- Heroku backend goes to sleep only when your sites are idle, conserving your free 1,000 hours.
- It just works between the two services’ free tiers. With this method, you can host lots of apps (depending on site traffic) without burning through your 1,000 free Heroku hours.
I checked. While this is hacky, it’s not violating anything listed in Heroku ToS or Netlify ToS. Although both hold final authority if they want to terminate an account for any reason mentioned in ToS or not. Read both ToS and decide for yourself if this is something that you would want to do. If yes, then remember the objective is to build apps where there would be so much traffic that this trick would be obsolete. At that time, I 100% recommend paying for Heroku and/or Netlify, they are incredible at what they do.