views:

152

answers:

5

I have a startup considering building a Java backend and a Rails frontend. The Java backend will take care of creating a caching layer for the database and offer other additional services. The Rails frontend will mostly be for creating the webapp and monitoring tools.

What startups/companies out there are using this kind of setup? What are some gotchas in terms of development speed, deployment, scalability, and integration?

(What would be helpful for me is personal experience or informal case studies. I'd like to de-priorities answers addressing alternatives like Grails or JRuby unless it turns out to be a big part of the equation)

Thanks!

+1  A: 

Perhaps I'm stating the obvious here, but the biggest gotcha here is the actual fact you're combining two technologies. Not only will development be slower - Rails and all Java frameworks are expecting to have a full Ruby/Java application - but for the other issues you mention (deployment, scalability, integration), the existing tools and solutions will not work, or at least not very well.

If you have a compelling reason to combine the two, go ahead but expect to spend more time on these issues than with a single technology solution. If you don't, pick either Rails or Java.

Jeroen Heijmans
Might be obvious but it does help that you're giving it an extra emphasis, thanks. My thinking is that each language is probably better at doing certain tasks than the other. For example, at least personally, Rails is much faster at prototyping a webapp. How do I quantify/qualify the tradeoff like that between time gained there and time lost with deployment, scalability, and integration.
Ian
A: 

I have used similar pair for one of my projects, but instead of RoR I used Python. I don't think there's large difference.

In general, there's nothing specific in this kind of programming. Two most important things you must care about:

  • good modularity;
  • well thought-out protocol between RoR and Java.

First is about exact functionality decomposition between parts of the system. We've got some troubles because of not understanding what part of a job must be done by Java, and what part by Python. In general, you must tie together all functions that are close to each other, and thing that are far must be connected in a very few places. I guess you know rules of good modularity, but in case of composing different languages this must be thought-out much more carefully. You can also be interested in creating several distinct Java services (e.g. one for database caching and another one for all the rest) to be able freely combine them or even use in other projects later.

Second is about communication between your parts. I can see two ways to communicate: through database and through pure network protocol. The former need some network communication anyway, so we used pure network protocol, without any other way to connect parts.
We had experimented a lot with SOAP, but it gave hundreds of errors: this protocol is quite ok to connect services written in one language (i.d. Java to Java), but terrible for connecting services in different languages - automatic tools for generating WSDLs gave different results for Java and Python, and manual creating of scheme was hard and labor-intensive.
So we used to REST. It uses all the features of HTTP protocol such as all four main HTTP methods (POST, GET, PUT, DELETE), error codes and many other things, so it covers almost everything you may want. The only restriction with REST is that it can't hold state, so you may need to implement your own sessions mechanism.
If you're not very comfortable with REST and seek some real example, see Facebook Graph API and for implementing REST services in Java you can use Restlets.

Andrei
Great comment about modularity and communication, thanks. Did you make a conscious decision to use REST over JSON alternatives? If so, what was your train of thought there?
Ian
Do you mean why we used REST _instead of_ JSON? We didn't. REST is just an architecture, you can use any representation to transfer data. We had to use XML (we needed to make our service available for another developers team), but in general it is good practice to use REST model with JSON as main representation. For example, to work with `Foo` table in DB make url `/foo/<foo-id>`, use method `PUT` to add new `Foo` instance, `POST` to update, `DELETE` to remove and `GET` to retrieve - that is REST. And actual data to all this urls may be represented as JSON string. Read some info about REST ;)
Andrei
And again, see Facebook Graph API - they use REST architecture and JSON-represented objects.
Andrei
+1  A: 

I would strongly urge you to consider having the frontend and backend in the same JVM for performance reasons.

For Rails, JRuby can run Rails, and you can have it in a Java EE container providing fast communication between components.

Having multiple architechtures which do not run in the same process requires you to do network based communication which takes much, much longer than just passing a reference to an object (I do not expect you to want to use shared memory).

Thorbjørn Ravn Andersen
Communication and the associated performance hit is definitely a big part of the decision. How do I qualify/quantify this performance hit? A webapp already has network calls to things like memcached and, perhaps, solr. The performance hit there hasn't been noticeable to me. Will it be different for making calls to other Java services?
Ian
As far as JRuby, I'm seeing the integration with Spring 3 isn't too smooth from looking at the documentation. Also, community support like plugins for JRuby isn't as fleshed out. Nothing I can quantify, but just a feeling. Do you have experiences with this?
Ian
@Thorbjørn Ravn Anderse: every time you select data from DB, you do network communication, think about it. Yeah, it is slower then passing a reference, but not so crucially.
Andrei
@Andrei, depends on the implementation. For instance Embedder Derby does not require network to do JDBC.
Thorbjørn Ravn Andersen
@Thorbjørn Ravn Anderse: in general, it is. And in general it is fast enough to work with most of web applications. Moreover, I made some benchmarks. The results: simple select of 100 records in MySQL db - ~40 msec., recursive factorial(1000) - ~8 msec., network request to localhost - ~1.2 msec. (Jetty web server, not the fastest one), network request to google.com - ~0.3 msec. Think about it.
Andrei
+2  A: 

I've never done any rails development but here are my thoughts. Why not just use Grails? I've done a fair amount of Grails development and it works well for rapid prototyping. It also offers all the power of Java, Spring, and Hibernate. Instead of dealing with communication between two different technologies you could take advantage of the fact that Grails uses Spring and Hibernate under the covers to deal with cashing as well as any other requirements these technologies support. If you have Java developers Grails should not be to hard to pick up. The grails plugin story is decent. All of them are stored in a central place and are easy to obtain but quality differs depending on the plugin author. You also have to remember that since Grails uses Groovy which is syntactically similar to Java and runs on the JVM it is very easy to use existing java code including the multitude of available Java libraries. I don't know this for certain but I assume there are a lot more libraries out there for use with Java and there for with Grails then are available for the Ruby language and Rails. I can't make a resource usage call for you but my question would be how many people do you have with experience designing Rails systems that use Java on the back end with all the gotchas that will go along with that? You may find that you have no one who is proficient at debugging when something goes wrong in communication between the two technologies.

Jared
Grails definitely makes sense as an alternative. It's more of a human resources dilemma to me at that point. We have some Java experts and some Rails experts. Using Grails would cause both parties to need to ramp up. At least on either side, some people will know the little gotchas rather than have everyone in new territory.Solution makes perfect sense. I just haven't convinced myself about the tradeoff. Thoughts?
Ian
Another aspect that I don't have enough experience to make a call on is plugin/gem support for Grails. What percent of plugins/gems that I can find in Rails will I also be able to find in Grails? Roughly speaking of course.
Ian
@lan, what percent of Rails plugins are still compatible with the last version of Rails ? almost none...
Kedare
@Kedare: Noted. I personally haven't had too much trouble with that, http://www.railsplugins.org/plugins. Do you have anything to add about Grails plugins though?
Ian
I've updated my answer with responses to your question since it was to long to fit in a comment.
Jared