Recommended Viewing : JRuby at Square

Xavier Shay from Square gave a talk about how they use JRuby.  You can watch the video :

He described the initial use of only Ruby on Rails and the eventual move to multiple programming languages and frameworks Ruby, Rails, Java, Rack and Sinatra. This lead them to move their Ruby stuff to move to JRuby. In the talk he covers Java integration, deployment, Rails and development and developer environments.  The Java integration was not used as much as initially they thought it would be.  JRuby allowed them to integrate with Neo4J libraries (graph database).  There is a gem call RubyNeo4J which wraps the Java classes into Rubyisms.


They ended up not using the gem but using the Java classes directly.  Worked really well.  He mentioned that the shared JVM experience is a win.  In talking about deployment he mentioned that they deployed Java on Jetty and they started deploying their Ruby code on Jetty as well – and it is paying dividends being able to share the same app engine.  He asked the question how to deploy Ruby web apps in a JRuby framework.  One way, is to package up the Ruby stuff into a war file and deploy it on a Java app server. Works – but they didn’t have a Java app server.  Also by packaging into a war-file – this is very unRuby like.  A second way, is to use Trinidad which allows you to use Rails or Rackup apps within an embedded Tomcat Container.They didn’t use this approach because they were using Jetty. 


trinidad02The third approach they initially used was Kirk which wrapped around Jetty and wraps your Rack app.  They had issues with it within an embedded Tomcat Container.  They didn’t use this approach because they were using Jetty. The third approach they initially used was Kirk which wrapped around Jetty and wraps your Rack app. They had issues with it. A fourth option, Mizuno also did not fit their efforts very well.   So, they wrote a tool called Jetpack.


Jetpack provides a way to package your JRuby webapp for Jetty.  It creates a little self-contained JRuby/Jetty/vendored-gem world around your project.  Jetpack gives you a script to start and stop your service.

The philosophy behind Jetpack is to let “Jetty be Jetty” and “Ruby be Ruby”. It worked for them.  They deploy to n servers and coordinate with haproxy and use capistrano to orchestrate it.  HAProxy is an open source TCP/HTTP load balancer, commonly used to improve the performance of web sites and services by spreading requests across multiple servers.


Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH. They have one process with real threads and girl_fridaythey can start/stop the service on the fly.  He also talked about Rails. They use girl_friday for doing asynchronous tasks. Rails thread-safe mode is not widely tested. He also touched on development. He mentioned that between jRuby and the JVM it does have a long start-up time. They develop on 1.9.3 and deploy on jRuby.  They are using jRuby for apps that do analytics, transaction viewing (anti-fraud), settlement and reconciliation, interact with graph database and some other apps.