TechHui

Hawaiʻi's Technology Community

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.

  • PG Backups - automated or manual PostgreSQL backups
  • New Relic - monitor, troubleshoot, and tune web applications
  • Zerigo DNS - automatic DNS management for your custom domains
  • Sengrid- email delivery
  • "We want more, we want more" - And they heard you, MOAR Heroku add-ons

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.

Downside - Zzz

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.

Scaling and Getting Ready for Production

Once your web application gains traction and needs more performance you can:

  • Increase concurrency
  • Scale the dynos horizontally and vertically
  • Upgrade add-on plans.

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.

Side Projects

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!

Views: 326

Comment

You need to be a member of TechHui to add comments!

Join TechHui

Comment by Christopher Kobayashi on June 5, 2013 at 9:24pm
Hey Doug,
I agree, it's so easy to work with. A single command and you've got your Rails app up on the cloud. See you Friday :-)
Comment by Christopher Kobayashi on June 5, 2013 at 9:21pm
Hi John,
I haven't gotten into the details about the RapGenius ordeal, but from what I've experienced personally and based on feedback from people around me who've used Heroku, it is a viable option for most projects. I suspect once you grow to a certain extent you might want more control of your environment, but until then I'm more than happy with the ease of use.

Chris
Comment by Douglas Ching on June 3, 2013 at 7:37am

I like Heroku.  It is really easy to deploy to and manage.  I've used other hosts that are similiar, but none as good as Heroku.

Coming from a .net background I've also used Azure a lot.  It shares some similarities to Heroku, but doesn't have as many free services.

Comment by John on June 2, 2013 at 1:31pm

We use Rackspace (prior to that Slicehost, who they acquired) and am fine with that though we are open to switching. I've looked at Heroku but the who RapGenius / Heroku / dyno scandal has been unsettling.

Sponsors

web design, web development, localization

© 2020   Created by Daniel Leuck.   Powered by

Badges  |  Report an Issue  |  Terms of Service