Tuesday, April 14, 2009

Heroku, Why Haven't I Been Using You Till Now?

Last night, I finally got around to deploying something on Heroku, an interesting service founded by my formerly LA-based Ruby programming chums Adam Wiggins, James Lindenbaum, and Orion Henry. I had played with their previous incarnation of the service, now known as "Heroku Garden" but only recently have I gotten to know a little bit more about the incredible offering they have evolved into.

Basically, the Heroku crew have addressed the question "how can I deploy my Ruby on Rails, Sinatra, or other Rack-based web application into a dynamic cloud of servers with ridiculous ease?" They have done this with an ingenious architecture that takes advantage of Amazon's EC2 to provide their internal infrastructure. This allows Heroku to concentrate on their most important core value proposition, of a simple way to take your Ruby code and just push it into the cloud.

Notice I said "push". Heroku requires that you use git for source control of your application. You are using git for everything now, right? If not, git with it! Sorry, could not resist that. Anyhow, by simply adding a remote master to your existing git repo that points to Heroku, along with a few Ruby gems that they provide, you can deploy your app just by pushing your current branch to the Heroku master.

Doing this, causes your app to get packaged up into "slug". Once you have an active slug, it will be be deployed to a "dyno" within the Heruku grid, which is what a virtual node within their architecture is called. As your app requires more resources, the slug can be deployed to more dynos within "less than 2 seconds for most apps". That is way faster than starting up a new Amazon EC2 instance yourself, and having this extra layer has a number of other interesting benefits as well.

Heroku has a quick start guide, which pretty much runs down what you need to do. I had found a slightly more simplified quickstart here. I already had an existing Sinatra-based app that I wanted to test on Heroku, so here were my steps:

1. Install heroku gem
sudo gem install heroku

2. Setup Heroku account info, and upload public key
heroku keys:add 

This will prompt you for your Heroku account info. If you have not created one yet, better jump over to http://heroku.com/signup and create one

3. Create Heroku app from my existing app
I just changed so my current directory was the app I wanted to add to Heroku, then entered:
heroku create myappname

This creates the new app on Heroku, and creates a remote branch so you can deploy just by pushing the code.

4. Deploy my code
git push heroku master

That's it! If you have a really simple app, with no database access, you are done. What, you are deploying a Ruby on Rails app and need a database setup? OK, then...

5. Run database migrations
heroku rake db:migrate


NOW, you are fully deployed and running on Heroku. Unless you are not. I still had a minor problem with my app. I was writing my log file into "logs/production.log" but Heroku does not normally allow write access to disk. The two exceptions to this are the "tmp" directory and "log" directory (notice singular). They do provide an easy way to view your most recent log entries, by typing
heroku logs
which is how I figured out my problem with the log directory.

So, here is my total time required to deploy this app on Heroku:
- Reading quickstart = 3 minutes
- Installing gem and entering account info = 2 minutes
- Making my app a Heroku app = 1 minute
- Deploying my app for the first time to Heroku = 2 minutes
- Figuring out what I had done wrong from the Heroku documentation = 10 minutes
TOTAL = 18 minutes

Here were my bonus steps:
- Reading Heroku docs on using a custom domain with Heroku = 1 minute
- Realize I need to rename my app using Heroku command line = 1 minute
- Rename my app using Heroku command line = 1 minute
- Setting my DNS settings to point to Heroku = 5 minutes
- Telling Heroku about my custom domain = 1 minute
TOTAL = 9 minutes

So there you have it... a fully deployed app, living in the Heroku grid and consequently the Amazon EC2 cloud, in less than 30 minutes, having never used their tools before, including troubleshooting a minor configuration problem. That may seem unfair... and it is. That is exactly the kind of unfair I like on my side!

Much credit should go to the Heroku team for creating something extremely cool and functional. Important details are still not available, like pricing etc., but at least for now Heroku, is a great way to easily get your app up into the cloud within literally minutes.

What is the future for Heroku? Funded by Y Combinator, they have been quietly working away, and now with Sinatra team leads Blake Mizerany and Ryan Tomayko onboard as well, I think we will be hearing a lot from this exciting little company.

8 comments:

Nick said...

Heroku is definitely a cool idea, both for deployment of small somewhat trivial apps as well as for either a cloud based development model or for someone working on Windows, but in my opinion it is definitely not ready for prime time.

When I was kicking the tires of Heroku last November, I ran into a few showstopping problems with their database support. I wasn't able to add database records via migrations and doing an export of the data that is saved in their database didn't work at all. Heroku is a great service until you run into a problem that doesn't have a work around. I don't know if these issues ever got fixed because I stopped playing with Heroku and went back to just writing code on my Mac.

The issue here is similar to what happens when you use shared hosting, the burden falls on Heroku (or shared hosting provider) to fix these sorts of issues rather than being able to fix it yourself.

Alien Fisch said...

My two reasons for not using it yet:

1) Don't want to be burdened on a pricing model that has no ballpark what so ever.

2) Being unable to write to disk scares me because I've never had to deal with that yet.

Unknown said...

Ron,

Great article and thank you!

---

@Nick We've added features/tools for these problems. Please see our docs at http://docs.heroku.com. New, great features constantly. Watch our blog at http://blog.heroku.com/ for all the latest news.

@Big Fisch, fear not. A read-only file-system is rather liberating. It's a constraint that forces you to think in a way to enables scaling with ease. There are so many great services available that will solve most of the "problems" you may have and scale out better.

Alien Fisch said...

I can definitely see that Blake.

The thing that still bothers me is the pricing model.

I'm thinking about utilizing heroku for a side project that I am developing, however, it's completely a side project and I rather pay something around $20 a month with Slicehost while developing it rather than some fee that I have no ballpark on that may come into play at any given time.

If I had a ballpark estimate on what you guys were planning to charge, or at least a minimum; would definitely let me know whether I should use the service or not.

Unknown said...

Thanks for the write-up Ron!

@Big Fisch Pricing will be released next week, and you will definitely be able to run an app of that type in your cost ballpark.

Eric said...

Found out about Heroku this morning , but before giving it a try I wanted to see some feedback about it. Thanks for posting. I'll let you know how it goes.

Unknown said...

I've been using Heroku's free service to develop an app for a client. I had a problem with SSL and Heroku's customer support looked at it right away and gave me a solution (I just needed to include an additional gem). Deployment, once I solved a problem with ssh keys, is ridiculously easy. So, so far, I've been very impressed.

Wojciech said...

Heroku wasn't a viable option for me until about now.

I host a dozen or so smaller apps, each of them with a SSL encrypted user/admin panel. Unfortunately Heroku charges $100 for one Custom SSL addon.

But there's a workaround now.

In a nutshell - host multiple apps under one Custom SSL addon and one multi-domain certificate.

For me it's a game changer.