RMI vs. Web Services. What's best for Java2Java remoting?

The web services do allow a loosely coupled architecture. With RMI, you have to make sure that the class definitions stay in sync in all application instances, which means that you always have to deploy all of them at the same time even if only one of them is changed (not necessarily, but it is required quite often because of serial UUIDs and whatnot)

Also it is not very scalable, which might be an issue if you want to have load balancers.

In my mind RMI works best for smaller, local applications, that are not internet-related but still need to be decoupled. I've used it to have a java application that handles electronic communications and I was quite satisfied with the results. For other applications that require more complex deployment and work across the internet, I rather use web services.

Whether you use Web Services or a more "native" approach depends on the environment as well. If you have to pass through a proxy or some corporate firewall(s), Web Services are more likely to work since they are relying on HTTP only. RMI requires you to open another port for your application which may be difficult (not technically, though) in some environments...

If you know that this issue is not a problem, you should consider using RMI. SOA does not depend on technology so much as on good service design. If you have an EJB container, you can call session beans via RMI and additionally expose them as web services, if you really need to, by the way.

The performance depends on the data that you are planning to exchange. If you want to send complex object nets from one application to another, it's probably faster with RMI, since it's transfered in a binary format (usually). If you have some kind of textual/XML content anyway, web services may be equivalent or even faster, since then you would not need to convert anything at all (for communication).


One thing that favors WS over RMI is that WS works over HTTP port 80/443 which are normally not blocked at firewalls , can work behind NAT etc. RMI has a much complex underlying network protocol which requires you to open up RMI ports, and also might not work if the client is NATTED. Secondly with RMI you are limiting your slef to JAVA-JAVA communication, while with Webservies there is no such limitation. It is much easier to debug Webservices over the wire as the data is SOAP/HTTP , which can be easily captured via sniffing tools for debugging. I don't know of an easy way to do this over RMI. Besides RMI is really very old and hasn't received much attention for last few years. It was big back in the days when CORBA was big , and both RMI CORBA are really antiquated technologies. The best option is REST style Webservices.