Using MongoDB for a Java Web App’s HttpSession

Since the web’s inception we’ve been using it as a glorified green screen. In this model all web application interactions and the state associated with those interactions, is handled by the server. This model is a real pain to scale. Luckily the model is shifting to more of a Client/Server approach where the UI state moves to the client (where it should be). But for many of today’s applications we still have to deal with server-side state. Typically that state is just stored in memory. It’s fast but if we need more than one server (for failover or load-balancing) then we usually need to replicate that state across our servers. To keep web clients talking to the same server (usually for performance and consistency) our load-balancers have implemented sticky sessions. Session replication and sticky sessions are really just a by-product of putting client state information in memory. Until we all move to stateless web architectures we need to find more scalable and maintainable ways to handle session state.

Heroku Preso from Devoxx 2011

As expected… Devoxx 2011 rocked! Such a fun conference with top notch sessions and people. I presented a session on how to deploy Java, Play Framework, and Scala apps on Heroku. Matt Raible did a great (and very thorough) write-up on my session. Thanks Matt! Here are my slides:

There was also some hot news at Devoxx… Play Framework 2 is the official web framework in the Typesafe Stack! And Heroku already supports Play 2! Awesome stuff.

Using Apache Tomcat on Heroku

One great thing about Heroku is the freedom to use any APIs and any application server. On Heroku you bring your application server with you. The easiest way to do this is by specifying your app server as a dependency of your application. This allows for maximum control and avoids the pain associated with developer and production environments using different versions of the container.

Most of the articles that have been written about running Java on Heroku use embedded Jetty since it’s lightweight and easy to specify as a dependency. But you can also use Apache Tomcat in the same way. There is now a great article on the Heroku Dev Center that walks you through how to do it. Check it out:

Akka, Heroku, sbt and BlueEyes at the SF Scala UG

Next Monday at the San Francisco Scala User Group I will be co-presenting about Akka, Heroku, sbt and BlueEyes with Mike Slinn - a long time friend and mentor. In the presentation we will be talking about a building client/server apps with HTML5 on the client and Scala & JSON services on the server. We will also show how to deploy these applications on the cloud with Heroku. Hope to see you there!