Skip to content
← Back to all posts

Host everything for free! (almost)

12 December 2014

Written by 


A photograph of Richard Gubby

Richard Gubby


Working on a side project? Ready to launch but don’t have / don’t want to spend money on hosting it?

freeThere is certainly no shortage of tools to help you host, build and deploy your software, but most of it doesn’t come for free. If you’re working on your own project and need to integrate a bunch of different technologies it can become expensive quickly. I have a side project that has lots of moving parts and I thought it’d be a useful exercise to see if I could host, test, continuously deploy, monitor and log it for zero cost - here are my findings.


Code

GitHub lets you host open source projects for free, but I wanted a private repo so had to look for something else. I chose to use Bitbucket but there are a few other free alternatives such as GitLab and Assembla that you might want to look at. Bitbucket was/is pretty good for my use, it even lets you add an issue tracker if you’re that way inclined - I didn’t as I was using something else (see And Finally)

Continuous Integration / Deployment

ship itOnce my app was created and ready to ship, I needed to build, test and deploy it. Travis CI was out of the window as it doesn’t support Bitbucket repos, so I took a look at Magnum CI. Not only does it have an amazing product name, it’s also a really nice tool. When you trigger a build (manually or via a commit hook in Bitbucket), Magnum builds a VM for you and creates it to the specification you want - a Ruby / Node (or whatever) application and services you want running on it. Once an environment is provisioned, Magnum clones/checks out the version of code from the commit and starts running the build script. That could be as simple as installing application dependencies but could be as complicated as a full set of tests. I went for the complicated option and had a mixture of unit + integration tests with Mocha / Supertest on my API and browser tests via SauceLabs (SauceLabs has a very generous free tier with plenty of testing minutes).

When the tests pass and the build succeeds you can hook Magnum into external tools such as Heroku or Capistrano that deploy your newly built package to a live environment. This brings me to… hosting…

Hosting

My app is a single page app (SPA) that communicates with a back end API for data. Rather than front load processing of data in the API routes, I’ve moved a lot of the heavy lifting into background jobs that process as and when a new task arrives. Part of this is because wherever the API was going to be hosted, it wasn’t going to have much computing power so I’d rather see jobs process asynchronously and give the public facing routes a chance to keep up.

The API and job processing are both hosted in Heroku, each in a separate app, each with a single dyno. Splitting them up into micro services makes sense anyway and a nice by-product is that I can keep inside the free tier in Heroku.

5pThe front end is hosted out of AWS S3 and although Magnum CI doesn’t have the option to deploy automatically, you can add a post-build command line hook that lets you do an s3cmd sync. It doesn’t strictly adhere to the “free” mantra, but in a couple of months of hosting, it’s only cost 5 pence so that seems pretty reasonable. A totally free alternative could be to use Firebase Hosting - the deployment is as easy as the s3 sync tool but has the added benefit that it stores versions of your deployments. This makes code roll backs easy, however the free tier doesn’t let you have too many concurrent users - definitely one to check out.

This leaves database / search hosting and I used a combination of MongoLab, Compose (nee MongoHQ), RedisLabs and Searchly. All of them are pretty restrictive on the free tier with the number of concurrent connections and if you don’t mind all of the alert emails you get when you are nearing your limits this can be a good solution.

Monitoring

5pWith all of these pieces of the hosting Jigsaw carefully slotted together, you need to be able to monitor it and alert you if anything goes wrong.

StatusCake have a free service that lets you ping public facing URLs and send alerts if anything isn’t working. If a service is down, I have configured StatusCake to alert into BigPanda (another free service), which co-ordinates your alerts and presents them in one place. BigPanda also has the added benefit in that it has an additional section for recording when a code deploy happened, so you can quickly determine if issues are related to a new release or not.

Access & Error logging

Things often go wrong and when they do, you’ll want to find out who has been accessing your site and what they’ve been doing. Loggly (with their free tier) turned out to be useful for both the back end API and the front end SPA. I’m using the Sammy.js framework for routing and every time a route changes, I fire off an event to Loggly with the relevant data. Node + Loggly is easy enough to implement and as expected there is a guide on the Loggly support center to do just this.

Error messages in the browser are always a bit more difficult to track down, but I found an excellent tool called Qbaka that came to the rescue. Every time an error occurs, an event is sent to Qbaka with a full stack trace and browser information so that you can debug JS errors much more easily.

And Finally …

That covers the main aspects of my app and how it’s put together for free (with the exception of 5p). But there are a couple of other tools that I’ve made use of:

  • Trello - great for managing features / issues when a fully blown issue tracker might be overkill.
  • Pusher - helps you make your app work in real time by sending messages between back and front end.
  • Redis To Go - alternative to Redis Labs
  • Codeship Swag - a free t-shirt and stickers. Doesn’t help your app, but can help your wardrobe.

Comments on HN