2 Replies Latest reply on Mar 15, 2017 4:25 AM by Dmitri Zamysloff

    REST vs EJB inside of the server

    Dmitri Zamysloff Newbie

      Hi Together Wildfly friends,

       

      I would like to discuss following topic. Which technology shall be used for communication between applications in Wildfly container? Actually, in this concrete topic I would like to discuss REST vs EJB.

      The good old school tell us to use enterprise beans to communicate between applications/components. On other hand REST services show now very good performance and they can be used instead.

       

      For discussion I provide following picture:

       

      An enterprise has several applications. These applications are delivered as EARs or WARs and going to run in Wildfly container. So far cluster and farming scenarios are not considered. But these will probably once to be addressed. Some of the applications deliver services to other applications. I speak here not about libraries which can be included to access some data or what ever. I speak really about services, which sit on their data and provide some interface to do something. And we do not speak about services for clients & UI. There are several options which can be considered:

      1. EJB call -> so the providing application registers EJB. The consuming application has interfaces and needs to know the right JNDI name of the service to access it.

      2. REST call -> the providing application implements JAX-RS (probably with JSON as content type). Consuming application needs to know where end point is and then access it using JAX-RS api.

       

      So which way would you go and why? Have any body measured the performance difference?

       

      Thank you for your answers and thoughts in advance!

        • 1. Re: REST vs EJB inside of the server
          kRyszard Zklanu Newbie

          Hello, in my opinion the EJBs have a few more advantages over REST inside a server environment:

          • easier "server" side configuration, no need to annotate every method
          • easier usage on the "client" side - you're just injecting a bean and using it just as it was in the same jvm, no need to use a rest api to call every method (unless you're using sth as resteasy's proxy)
          • ejbs can be distributed out of the box. If you have redundant REST endpoints you have to handle it yourself e.g. with an apache or in your code
          • with REST there are "always" problems with configuration of the mapping of the domain objects to/from json ; with ejbs there's simple serialization

          I even start thinking that for a desktop java client the ejb-client would be better than rest access that we currently use (because of high availability and proxy).

           

          And what solution in your environment have you chosen since the original post?

          1 of 1 people found this helpful
          • 2. Re: REST vs EJB inside of the server
            Dmitri Zamysloff Newbie

            Hi kRyszard Zklanu ,

             

            the question is a bit old. But still thank you very much for the answer.

            And actually I did not have any influence on that project and decisions. As I think there are two main strategies, both of which are legal:

             

            - clustering - and then off course you use EJB and all goodies of J2EE like caches etc.

             

            - farming/microservices - in this case you have to rely on web services. Having overhead in different infrastructural issues and integration you gain flexibility.

             

            IMHO the decision one or another have to be made pretty early. But again IMHO in huge software development projects/companies very important to implement governance, service architecture. In other case you will have a mess.