November 08, 2009

Posted by John

Tagged heroku, mongodb, and mongohq

Older: Know When to Fold 'Em

Newer: Config So Simple Your Mama Could Use It

You're An Idiot For Not Using Heroku

It is true. You are. Go try it now. That is an order. I can wait for you to come back and finish reading this post. I could end the post now, but I suppose I’ll go on and tell you a bit about my experience with Heroku yesterday.

Formerly a Toy in the Cloud

Wynn and I were talking yesterday about how, back in the day, Heroku seemed like a toy in the cloud. They had a rich code editor and you could magically create and deploy applications that sometimes worked. It was neat, but nothing you would use for anything serious.

A toy they are no more. So what is Heroku? According to their site, Heroku is “fast, frictionless, and maintenance free.” After giving it another look yesterday, I would have to agree.

Heroku

The App

I have a tiny note application that my wife and I use. I use it to mark things to read later and save plain text notes. She uses it to keep track of recipes, tagged with ingredients and whether or not she has made the recipe before. It is nothing fancy, but it serves a purpose for both of us.

Textual

The app formerly ran on Dreamhost (how to deploy rails on DH) and used MySQL. Since I decided not to attend the Notre Dame game yesterday, I had some free time, so I watched football on TV all day and worked on converting this project from MySQL to MongoDB (which is awesome).

Once I finished the conversion, which didn’t take long, I exported the MySQL database as XML using PHPMyAdmin (shudder) and then wrote an import rake task that reconnected the xml in MongoDB (which is awesome).

MongoHQ

I have had a MongoHQ invite for a while now, but hadn’t kicked the tired so I decided now was as good a time as any. Then it occurred to me. Why use Dreamhost when Heroku has a free account and I’m already hosting my database in the sky? Why not go cloud to the max and see how things end up?

Heroku

I logged in with my old Heroku account and did some reading through their amazing docs.

  • I gem installed heroku.
  • heroku created my app using the command line tool.
  • git pushed to heroku remote.

Boom. In less than a minute my app was created and deployed on Heroku. Impressive. Now that isn’t where the story ended. Hosting on Heroku is a bit different.

Config Vars

The first thing I ran into was some config file issues. I found Heroku’s article on config vars and switched my app to work like that. git push and my app was deployed again.

Gems

Now I was missing gems. Back to the docs I went, this time to read about managing gems. I created my .gems manifest and git pushed again. Just like that my app was up and running in the sky.

Conclusion

I made a few more changes to my app over the next few hours and deployed after each one with a simple git push heroku master. Each time, I almost giggled as the normal git messages happened and then out of nowhere, Heroku stepped in and informed me that it was deploying my app and…wait for it…wait for it…that the deploy was finished.

Now that I’ve used it for a tiny app, I’m curious to see what it can do with something larger. I’ll definitely be using Heroku a lot in the future, that much I know for sure. Combined with a hosted MongoDB service, it is absolute glory. MongoDB having their GridFS file store, means that not having write access to a file system on Heroku is no big deal. You don’t even have to setup S3.

I’ll leave you with my tweet from yesterday, summing up my experience.

Created and deployed a MongoDB backed Rails app to Heroku and MongoHQ today. I have witnessed the future.

Anyone else out there using Heroku? What kind of apps have you deployed on it? What have your experiences been? Curious to hear from others.

47 Comments

  1. I’ve had a great time using Heroku, and I’ve moved almost all of my applications there. I don’t care for the way they recommend setting up your config vars, though, so I use this strategy instead.

  2. I generally don’t have many config vars so I’ll probably just stick with the env stuff. That said, if I ever end up with a few, that idea looks handy.

  3. I tried Heroku a couple of months ago and I agree, it totally rocks.

  4. I’ve had mongo hq for a while myself, and there was a question I was dying to ask you: how do I connect mongomapper to the mongohq database? Do I use the provided connection string as the driver connection? It just doesn’t seem right to me. Thanks.

  5. @Joel – Just setup a connection like normal. The connection string they give you is host/database.

    MongoMapper.connection = Mongo::Connection.new('db.mongohq.com', 27017, :auto_reconnect => true)
    MongoMapper.database = 'database_name'
    MongoMapper.database.authenticate('username', 'password')

    Hope that helps.

  6. Beautiful, thanks! I didn’t know about the authenticate method. By the way, I noticed your fancy live comments! Very nice!

  7. I’d also add: if your ruby web-based OSS project doesn’t easily deploy to Heroku, it should!

  8. I have a live Demo: ERB Abstract Tag Generator for RAILS http://w2tags.heroku.com

  9. @rick – Good call. Hadn’t thought about that.

  10. Heroku is incredible. What I’m wondering now is, why would anyone choose EngineYard?

  11. I, myself also had a great experience with Heroku.
    As far as I know, it’s the only black box Rails solution out there and it’s so great not to have to maintain the web stack :) (for instance having varnish already setup and maintained will save you hours). Also, what I love is that you don’t pay for hosting until you get enough traffic to justify paying for it :)

    Furthermore, what I really like with Heroku is the fact that you have true redundancy, your dynos run on different instances and every time you start a new one, it’s run from yet another instance.

    Finally, if you have something heavily customized that you want to maintain yourself, just run your own ec2 instance and only manage that.

    Ohh.. and if you want to use couchdb with heroku, use http://couch.io ;)

    Ohh.. and if you want to use couchdb with heroku, use http://couch.io ;)- Matt

  12. @Justin Engine Yard provides lot more visibility and customization options. I’ve used Heroku for some projects (our website is running Radiant on Heroku) and it has been working great, but I’m unsure how easy it’s to fix problems if there is any.

  13. I have three or four apps running in a similar configuration to what you describe and agree that it couldn’t be any easier to set up, and the performance has been awesome. MongoHQ is surprisingly fast as well!

  14. I’ve got a couple sites running on Heroku and I agree, it’s incredibly easy. The second one was written and deployed during a boston.rb hackfest (the entire app was written and done in about 2 hours time, total). They are definitely doing a lot of things right and I can’t wait to see what they’re going to add next.

  15. I agree wholeheartedly: Heroku is awesome.I also have a MongoHQ account but haven’t used it yet. Just curious, are you noticing any speed/latency issues accessing the database across the network? I’m sure it’s slower, I’m just wondering if it’s noticeably slower.

  16. I just got my new company site up on Heroku and it was pretty much the same experience. git push; error about missing gems; create .gems file and push; app up; add Heroku config for Google Analytics; git push; all done! Can’t have taken more than 10 minutes to get the app running.

    I ran managed servers for several years, but after this experience, I’ll do everything I can to adapt an app to work on Heroku before resorting to self-hosting again.

  17. @Matt – Great comment. Thanks for all those thoughts and the couch.io link.

    @mrb – Yeah, I’ve been surprised how fast MongoHQ is too (and Heroku for that matter).

    @Josh – Fun! Glad to hear you’ve had a good experience too.

    @TJ – I haven’t noticed any latency. I actually have been shocked at how fast Heroku/MongoHQ are performing as of now. Granted the app gets hardly any usage and doesn’t have a lot of data, but it is working great for me.

    @Ashley – Agreed. So simple and easy. No headaches.

  18. I’ll second that suggestion for making your open source Rails/Sinatra/Rack apps easy to deploy on Heroku.

    It’s just good manners :)

    @TJ and @John – one thing to keep in mind is that Heroku is running on EC2, so that means that using other tools/services that are on EC2 should cut down any latency by quite a bit. I’m not an expert on this, but my limited experience has been very positive so far.

    Speaking of which, and @Matt – I believe Cloudant is running CouchDB via EC2, so that’s a good combo, too. Also, I suppose anything custom could be run on Engine Yard if necessary, because they’re also on EC2 with their newer cloud products.

    I think it makes a lot of sense to user Heroku to cut down on sysadmin work, even if you need to use other services in conjunction with it. I even created a Google App Engine app so that I could use Python’s Pygments syntax highlighting library from Heroku, and it’s been working great.

  19. infoinfo infoinfo

    Nov 09, 2009

    Heroku is so good that for our next project we are leaving Python/Django/Pylons behind so that we can have the worry-free, scalable hosting their platform offers. They have done an incredible job. Heroku is to the hosting industry what the iPhone is to the phone industry.

  20. Teaching:

    For work, we have students deploy to Heroku during thoughtbot training . Our training application itself is also on Heroku. We are also using Heroku for our most recent client app.

    Prototyping

    For play, I keep a notebook of grid paper where I paper wireframe ideas. On the weekends lately I’ve been taking those paper prototypes to deployed proof-of-concepts using Sinatra and Heroku (usually while watching football, too, albeit the Patriots instead of the Irish).

    This weekend, it was an in-browser, vim-like editor called Ed Friendly I wrote to teach myself more jQuery and use Effigy for the first time.

    The weekend before, it was Shorty , a Sinatra app that’s also using MongoHQ for the backend. (the code is open source for that one).

    Rumbling:

    During the Rails Rumble, I was deploying Pockets to Heroku from the opening bell while another teammate set up our Linode slice. We also wrote a quick Sinatra app as a Twilio proof of concept .

    Splash pages:

    I’ve also been using Sinatra and Heroku lately for splash pages such as Shortbord , National Gazette , and Project Blue Book .

  21. If you got system dependencies Heroku will mostly hurl, as far as my experience of Herouk is…don’t seems to be possible to install your own except for gems. Had issues with this, so gave up.

  22. You mean shudder, to shiver, bro.

  23. We’re running http://www.horizonleaguenetwork.tv/ on 4 app instances. Once basketball seasons gets in full swing I imagine that will go up to 10-12. Based on last years numbers we’re expecting 5000 concurrent users during big games.

    I did a 15 minute meeting to build a CMS tool and deploy it too Heroku at the last IndyRB meeting. It was fun to see how amazed people were.

  24. I think Google App Engine is looking very large on the horizon.

    Maybe you’d be an idiot for only considering Heroku? :)

  25. I’m definitely excited about the direction Heroku is going. I briefly used them for a production site a year ago, when they were still in the “Toy in the cloud” phase. It seemed very promising back then, but ultimately it was too slow and limited for us.

    I’ve played with it recently and am very impressed with their improvements. Especially their new support for addons is great (background jobs, memcached, etc.) and should make it a feasible solution for many sites.

    I wouldn’t go quite as far as saying that you’re an idiot for not using them (there are cases where a managed hosting service like EngineYard makes more sense, and others where a fully customizable cloud environment on EC2 does). But for any new site I would definitely evaluate whether I can get away with deploying it on Heroku, since it’s just so much easier.

    Hadn’t heard of MongoHQ before and haven’t had a chance to play with MongoDB yet, but it’s on my list. I’ll definitely check it out. I’d be slightly concerned about latency, but from your experience it doesn’t sound like it’s that bad. Do you know if they’re on EC2 as well (like Heroku)? I would assume that that would result in reasonably low latency, at least if they’re in the same data center.

  26. I have a snippet app on there right now, it’s a little slow on the initial load, but works great for my needs. I keep trying to think of a way that I could make one of their paid options profitable, but am having a hard time. That being said, I still think that Heroku is pretty fantastic.

  27. What those who don’t like / use Git. I’m a big fan of Mercurial and I really don’t want to switch to Git. I’m reallly lost when I have to use Git. So am I an idiot because of that?

  28. infoinfo infoinfo

    Nov 10, 2009

    Google App Engine has no clear product focus.

    It does not address the needs of developers who are building production web applications for paying users; the issues with GAE are too many to mention. Try evaluating it for a a SaaS web app and you will see it is not a platform you will trust to earn your living.

    Heroku has a clear product focus: How can we better help developers deploy production web applications? How can we make it reliable, fast, easy? What can we give them to support a paying user base?

    GAE as with many Google products is a bunch of engineers tinkering left and right without having a clear vision of who their users are and what their needs are, or more important, what the needs of the clients of their clients are.

    Just evaluate it for a production app and you will see what I mean.

  29. Maybe that’s why he said it Google App Engine was on the horizon?

    GAE is definitely production ready as is. Rails 3 will make it accessible to our community (or begin that process)

    It’s a platform you need to adjust to and it does not compromise. But if you are willing to invest it can be very beneficial. And comparatively cheap.

  30. We deployed our personal/family expenses tracking product, Dough on Heroku, after previously using Joyent. To contrast, deploying to Joyent took me about a day to fully understand and get going. Heroku took about 20 minutes, including similar problems to the ones you found.

    I’m really excited about Heroku’s new plugin stuff. It was OK before, but now it’s amazing.

  31. you’re the idiot for giving away your data and becoming dependant on a commercial/proprietary crap provider!!

  32. I’m using Heroku and mongoHQ like you do for a little sinatra app for saving images and documents (binary) with metadata tags, with a small rest frontend, very few codelines. And i also use http://wasitup.com/ for monitoring that the site is up. All in the cloud :)

    I definetely feel this is the future of app deployment and development..

  33. For work, we have students deploy to Heroku during thoughtbot training . Our training application itself is also on Heroku. We are also using Heroku for our most recent client app.

    For play, I keep a notebook of grid paper where I paper wireframe ideas. On the weekends lately I’ve been taking those paper prototypes to deployed proof-of-concepts using Sinatra and Heroku (usually while watching football, too, albeit the Patriots instead of the Irish).

    This weekend, it was an in-browser, vim-like editor called Ed Friendly I wrote to teach myself more jQuery and use Effigy for the first time.

    The weekend before, it was Shorty , a Sinatra app that’s also using MongoHQ for the backend. (the code is open source for that one).

    During the Rails Rumble, I was deploying our app to Heroku from the opening bell while another teammate set up our Linode slice. We also wrote a quick Sinatra app as a Twilio proof of concept .

    I’ve also been using Sinatra and Heroku lately for splash pages (something pretty in production while a staging app, also on Heroku, is developed elsewhere).

  34. @Mirko

    Yes, MongoHQ is on EC2 (low latency from Heroku).

    I think it would be interesting to see Engine Yard promote the “utility servers” (as I believe they call them) on their cloud offering with chef recipes for MongoDB.

    I would be interested in playing with my own MongoDB server via Engine Yard (with their support) while running multiple apps on Heroku that connects to it.

    I’d vastly prefer a hosted cloud service like MongoHQ but it would at least be good for learning purposes and EY’s support team could sway me that this approach makes sense. I believe they have lots of NoSQL-experienced people.

  35. @Bjørn – wasitup looks really cool! Thanks for the link. Trying it out on the app I talked about in this post.

    @Dan – Wow, looks like you are using it to its full potential. Freakin sweet! Also, I think that would be a great idea re:EY. I’d love to have one simple cloud server for all my mongodb apps and not have to rely on someone else and then use Heroku for the app part.

  36. Hey John… Heroku deployment is amazing, wish we had a general purpose capistrano/vlad-like tool that was anywhere near as simple, and designed with Git in mind.

    My first Heroku experience is a little Sinatra app for single-page sites. It’s way faster to heroku domains:add than go through the conventional control panels. I have yet to build out a “parked” page for each domain. http://gist.github.com/207983

  37. While the ease of deployment on heroku is attractive, some of the pricing for add-ons is not: $100/mo for SSL that doesn’t give errors? Seems pretty ridiculous to me.

  38. I’m super-impressed with Heroku. I wrote a tiny Sinatra URL-shortening app for my blog and deployment was about as simple as it could get.

    The live preview in your comments system is awesome BTW!

  39. Well I am interested in Heroku

    But I think they could go a long way by representing the service better.

    It’s not clear how much bandwidth is provided by Heroku. I’ve heard people say there is no limit, but I doubt that somehow.

    Also there is no user forum promoted on their website. Forums do expose issues, but if you run a solid platform people appreciate the honesty. Slicehost runs a forum and promotes it.

    Also I’m not clear on how it scales. Do you stick with your initial database and add Dynos? Or can you upgrade the database too?

    (PS: I did discover this: http://groups.google.com/group/heroku)

  40. Just adding to the chorus: Heroku rocks. I’ve got several CommunityEngine apps running on it (including Curbly and Uncooped ). There’s a page on the CE wiki about getting up and running on Heroku in no time. I’m also planning on doing a Rails template to automate some of those steps. Thanks for the great article!

  41. Heroku is awesome. One-step deploy with git push. Wow! When deployment is a one-liner, and takes little time, it not only helps you develop faster, but it changes your thinking on what constitutes a deployable unit of functionality.

    They also have a remote script/console that lets you twiddle the application. I ran into an issue in my Heroku-hosted application with orphaned rows in a table that gave my app some grief. (Nil pointers on a view page. I know, I know, I should have had a :dependent=>:destroy on a has_many relationship). I just ran “heroku console”, to console in and then found and deleted the orphans. The app was fine again.

    I still haven’t figured out file uploads and using S3 for storage, but that will come eventually.

    All I can say is, “Wow”.

    I have worked on deployment in an ASP.Net environment, a Perl/MySQL environment (loooong ago), and a non-Heroku Rails environment. Nothing comes close to the ease of deployment with Heroku.

  42. @john:

    as heroku and mongohq are both running in amazons cloud (the do, or?), you can probably change the host to the following:

    aws.mongohq.com

    maybe this speeds up the communication between these both as the request is handled internally without leaving the amazon cloud.

  43. Is it possible to have more than one domain hosted on your Heroku account?

    Also….. if I started out on a shared cluster, is the move to dedicated seamless? How would you know when the time was right to do this? Would your service just start dying, or would you be given the opportunity to let it grow as needed?

  44. Also

    If people are starting to use MongoDB… or even Amazon RDS (as promopted by Heroku)…. then isn’t Heroku’s focus on buying a “database” on the pricing page an unnecessary expense?

  45. @marc – Yep, I noticed that the other day and changed my app.

    @doko – Not sure this article is the place for your questions. Why don’t you just contact heroku? I’m sure they will know how to respond.

  46. Heroku is powering the Train Brain public website and API backend Rails apps for 2 months now, can only think of one short outage. Heroku is super awesome.

  47. How is it, if i want rails-hosting but dont wanna set up an email-server by myself. Can i have Webmail, POP or IMAP Folders for an domain i registered at Heroku?

Sorry, comments are closed for this article to ease the burden of pruning spam.

About

Authored by John Nunemaker (Noo-neh-maker), a web developer and programmer who has fallen deeply in love with Ruby. More about John.

Syndication

Feed IconRailsTips Articles - An assortment of howto's and thoughts on Ruby and Rails.

Feed IconRails Quick Tips - Ruby and Rails related links.