Let's Play! (...for free!)
This is a little story about Play Framework, Google App Engine and Heroku. And it’s also a story about this very web page, because it is written in Play, was hosted on GAE, and is now being hosted on Heroku.
A long, long time ago…
…this site was written in Ruby on Rails. But after I had been forced to change my old hosting to something new, I was looking for cheap hosting options and I decided to try out Google App Engine (which is basically for free and is a well-tested major platform).
The main problem was that it looked like a no-go for Ruby on Rails apps. There is JRuby, but appengine-jruby doesn’t seem to support Rails 3 yet (“We plan to support Rails 3 soon.”).
But I still wanted to try out GAE, so I looked for some other framework. And since I had planned to test Play Framework for quite a long time, the choice wasn’t very hard.
Play Framework
What is Play Framework, you may ask?
I’ll allow myself to answer this question with a quote from the framework’s web page:
Finally a Java Web framework made by Web developers. Discover a clean alternative to bloated enterprise Java stacks. Play focuses on developer productivity and targets RESTful architectures.
And I must say - it’s true.
So what’s so good about this framework?
- it’s MVC, of course; and it’s stateless
- it has convenient RESTful routes
- it has integrated test runner supporting JUnit4 and Selenium (yes, Selenium!)
- built-in Hibernate, with JPA by default (changeable with modules)
- easy deployment (also on GAE, and many Java application servers)
- great templating engine (using Groovy)
- automatic source reloading (so no need for redeployment after a little change in code)
- support for Memcached, OpenID, WebSockets, etc.
- easy admin panel creation with CRUD module
- good IDE support (it is, after all, Java)
- it’s extendable with modules (and there’s official module repository)
Everything is described in detail on http://www.playframework.org/, so I encourage you to check it out. And let’s move to hosting options.
On Google App Engine
It is certainly possible, it’s not very hard, but it’s not as straightforward as I would like it to be.
One thing was to add gae module in order to make Play work on GAE, but when I started coding the newest version supported only API version 1.4 (currently it supports 1.6). But it worked. And deployment with this module is quite easy:
play gae:deploy --gae=/path/to/appengine-java-sdk-1.6.0/
The other thing I decided to do, was to use siena module, which is a very nice persistence API with support for GAE (also MySQL, PostgreSQL, H2, etc.).
And this arrangement (Play with these two modules) allows to quite easily write apps for Google App Engine. However, I got frustrated a few times over lacking parts of documentation for Siena and some limitations of GAE (e.g. asynchronous jobs are disabled and you have to use GAE’s cron). File upload also has to be handled differently than in non-GAE applications, because files have to be uploaded to the Blobstore.
But all in all, GAE is a great platform and the website was running on it quite successfully.
On Heroku
So why Heroku?
I was recently enlightened by my friend, that Heroku offers free 750 hours per month per application. And a 5MB PostreSQL database (which is more than enough for my needs and allows me to use JPA and all the features that go with it in Play). And official support for Play Framework.
And also, very easy deployment - no special modules, just correct Procfile, like this one:
web: play run --http.port=$PORT $PLAY_OPTS
In addition, I can use SSL on *.herokuapp.com which, for instance, allows me to access website’s admin panel without sending my data all over the world.
The only problem I have encountered so far is the read-only filesystem, which forces me to use external storage for files. But it’s not a painful problem if you only don’t mind storing your files on Amazon S3 or some something similar (but since Heroku is hosted on Amazon EC2, Amazon S3 may be a good choice).
So, for the time being, I’m staying on Heroku. And waiting for Play 2.0 to come out. Then I’ll see - I believe that Play support for GAE will be becoming better with time - and maybe I’ll come back to GAE.