Run your POC app for free on Heroku
In this blog I am going to walk you through how to run a production (non mission-critical) application on Heroku for free. I will point out some gotchas which got me the first time I was setting it up, so you don’t have to make those mistakes as well.
I am recommending Heroku from the perspective of a software engineer and entrepreneur. Heroku might be the wrong tool for established business or for hosting your WordPress blog, but I found it to be particularly powerful for proof of concept (POC) apps, written using modern technologies, such as node or ruby + angular.js.
I have tried shared hosting, AWS, Azure and reviewed multiple other PAAS, but so far Heroku solves my problems really well. So if you are a developer looking for a hosting provider which accelerates building your solution and and allows you to focus on proving your business model, rather than infrastructure, Heroku is a good choice.
First thing you need is to register a free Heroku account to get going.
Next follow the Heroku guide on how to deploy your first app. Follow the guide but don’t scale to 2 instances though, we want to keep it free at this stage.
Now point your DNS entry to heroku, again follow their detailed guide. After you finished you should have something which already looks like a working website, but you are not done yet.
The setup you have at the moment is recommended to be used for development or for your non-production environments. There are 2 reasons Heroku doesn’t recommend that:
- With 1 dyno you have no redundancy, so if 1 dyno fails you will have some down time, that said the downtime isn’t massive (for me it took about 15 minutes to restart). Also this this is something which happens very rarely (at least to me).
- Heroku will put the dyno to sleep after certain time of inactivity. This is quite important and I will explain how to fix that next.
So again, don’t run your mission critical apps, only proof of concept ones.
Setup periodic pinging
One of the ways Heroku minimises waste is by putting idle dynos (dyno is their name for virtual instances) to sleep, so if your website isn’t being used for long period of time the dyno gets bored and will drift into the sleeping mode. So the next time customer comes along it will take around 20–30 seconds to load the first page, all subsequent requests will be served quickly though.
That’s not ideal, isn’t it!?
So to solve the problem with dyno drifting away into sleep you will need to setup a pinging service, which periodically request the page and will make your dyno always up and ready process requests.
A good and free service is Pingdom. Register with Pingdom and add a monitor which points to your URL. It is a good idea to setup notifications so if your website is down you will receive an email or sms.
Tip: use your domain URL rather than Heroku, so point Pingdom monitor to www.yourwebsite.com, rather than yourwebsite.herokuapp.com) this will make sure that if you have some problems with your DNS provider you will be first who will know that.
Run Production Check
Heroku has a great tool to check if you are production ready, called Production Check, select your app and it will be located in the top right corner.
Heroku will give you pretty good details of what is still missing if you run your production check. The only red thing which we will accept is Dyno Redundancy, all other items should be either grayed out or green.
So after you have completed the checklist you are ready to go.
Read the next section to get a bit more understanding why these services are necessary and how you can benefit from using them.
New Relic (Application Monitoring)
While Pingdom does a great job of telling you if your website is down. You might want to know if you website is slow or if the backend is throwing some errors or if few for few customers website is very slow, but everyone else if fine. The great and free tool is New Relic. So navigate to Heroku addons and install it with one click.
New relic will also draw a vertical line on all metrics to indicate when deployment was made. I use this to monitor if my new deployment hasn’t broken any user flows, if RPM (requests per minute) is the same as before and conversion rate hasn’t been affected, you have most likely not broken anything. I find this very useful if you follow Continuos Integration principles.
That said don’t only rely on those metrics to test for regression, always add tests to cover your code ☺
Papertrail (Log Analysis)
As for error logging, Heroku makes it super to start logging and analysing logs, just use the standard print to console and Heroku will pick it up.
The only caveat is that Heroku doesn’t store those logs forever, but for very short period of time. What you will need is to use a third party addon which will persist your logs, I personally like Papertrail as it’s simple and fast.
Papertrail gives an easy to use web interface where you can search for errors or other events in your logs. You can also setup monitoring for specific keywords and send yourself a report weekly, for example you could find all errors in the logs and send a weekly digest.
These days running a startup is become less and less difficult as amount of time you need to spend to setup different logging and monitoring tools, as well as hosting has dropped dramatically with PAAS (Platform As A Service) such as Heroku. And thanks to those tools you no longer feel like a mole in the hole, hoping your website is running fine after latest deployment.
Also it is very important to note that this whole setup cost us 0.0£ or any other local currency you are using.