You have the latest and greatest idea for a web application. You tell your friends and colleagues, and put together a small team to get the idea rolling. Your programmer, a Ruby on Rails guy, develops a prototype of the web application that works on his machine. You want access to it to show it off, and put it in front of users to get feedback.
Even though you believe in your idea, there's a part of you that's not "all in". You don't want to dig into your wallet and pay to host it. Not yet anyway. Fortunately there are many options.
A popular solution for systems built using Ruby on Rails is Heroku, which is a cloud application platform with a plethora of add-ons. You can start off with a single web "dyno", a virtual Unix container, for free. You can even add a PostgreSQL database to your app for free.
In fact, there are many add-ons that you can use -- all for free.
Other than the add-ons, a nice thing about using Heroku is that it acts as a remote backup of your web application files. Not only of your most recently uploaded files, but since you need to use Git to deploy your code, Heroku has your entire history. So if you have a catastrophe or your dog eats your code, you can git clone your web application from Heroku and your file versions will all be there.
Heroku also provides Releases, a feature that allows you to easily rollback to previous deploys. So if you check-in and commit bad code that breaks the web app (which shouldn't happen if you're testing, but I digress), you can rollback to a working state of your web application with a simple command.
Yes, there is a downside. According to Heroku's documentation a single web dyno will idle out after one hour of inactivity. This means your web application will be resting quietly (and not using precious resources, which is a good thing and probably one of the reasons why it's free). After the web dyno has idled out, the next request to access your web application will "wake up" your dyno. There is a noticeable delay for the first request, but once it's back up subsequent requests should perform normally. This should be fine if you're just demoing your web application, have only a few users, and don't have paying customers.
To prevent idling you need to increase the number of web dynos. Unfortunately this is not free. An additional web dyno will cost $35 and a basic database is $9, so that comes out to $44 per month. Not bad for all the functionality you get -- essentially an environment that includes a round-robin load balancer, two app servers, and a database server. Plus all the free add-on services such as backup and monitoring.
Once your web application gains traction and needs more performance you can:
The first thing you might consider to help scale your web application is to increase concurrency. Usually Ruby on Rails applications use a single threaded server like Thin, which processes only one request at a time. The easiest and free way to add concurrency is to replace Thin with Unicorn. The number of Unicorn worker processes that you can run on a single dyno will vary depending on the web application's memory footprint, but typically you can run 2-4 concurrently.
Another way to improve concurrency is to increase the connection pool to the database. It's a balancing game and takes some time to get right, but might be worth it and it's free.
The next step is to look at scaling dynos out horizontally and up vertically. By scaling out horizontally we mean adding additional dynos. And scaling up vertically means increasing each dyno's capacity: CPU and memory. Each web dyno comes with 512MB of memory and 1x CPU share. The 2x dynos are double that, so 1GB of memory and twice the CPU share. Scaling out and up both have their use cases, which we can't cover in the blog post due to the size of the topic. To find out more please refer to Heroku's blog post announcing 2x Dynos, and their documentation on Dyno Size and Scaling.
Finally, look at upgrading add-ons. Most of the add-ons have a free plan. This is so that you can kick the tires and test out their services. Once your web application reaches a certain level, the quotas put into place for the free plans might be too restrictive. Each add-on has multiple plans with different price points, and depending on your needs the plans can be upgraded or downgraded at any time.
For a couple of hobby projects, I started off with a single dyno and some of the add-ons mentioned above. Although the web apps go to sleep when I'm not using them, it doesn't really bother me. Actually I feel like I'm saving electricity, like turning off the lights when I leave the room. And if any of the projects do get traction, I have the option to scale out and up.
If you have any experience with Heroku or have stories about scaling I'd love to hear them.
Aloha Friday all!