Expand my Community achievements bar.

SOLVED

Calling multiple Web Service on a single page

Avatar

Level 4

Hi,

We have a requirement wherein we have to call 3-4 REST Web Services on a single page. It's bound to hit by performance issue owning to the number of service calls. Is there any workaround possible for this situation ? 

Thanks in advance

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

As already written, you can move the problem to the clientside and do the calls from there. Otherwise you can try to execute these backend calls in parallel on the server side if they are not dependent on each other.

But this is not an AEM (not even Java) specific question, but a rather generic one.

kind regards,
Jörg

View solution in original post

10 Replies

Avatar

Level 10

You can code your own Restful service within an OSGi service. Make the 3-4 Restful calls and pass back to the client page. The client page can display the results. 

Avatar

Employee

You can cache the webservice responses either in AEM or use a reverse proxy like varnish for this. You can set ttls like every few hours clear the cache and refetch..

You can run these services in author once and push to publish as nodes. This depends on the type of data.

Avatar

Level 2

You can try below options to improve the performance.

  • Try  build the component as a angular widget to have client side rendering than server side .
  • Make use of lazy loading of the service data/paging instead of loading all data at one.
  • Consume data as a JSON so that the  dispatcher can cache the response and you can control your TTL as required.
  • Use local storage to store common data used by all services rather than getting it each time.But make sure to clear it off as required.

Avatar

Correct answer by
Employee Advisor

Hi,

As already written, you can move the problem to the clientside and do the calls from there. Otherwise you can try to execute these backend calls in parallel on the server side if they are not dependent on each other.

But this is not an AEM (not even Java) specific question, but a rather generic one.

kind regards,
Jörg

Avatar

Level 4

Thanks for your response Jörg and I agree with you that it is not AEM. But the reason why I put it into AEM was because the questions were being raised on AEM here at my workplace. People were of the opinion that AEM was not good for the dynamic stuff and I found that argument silly. I was wondering if there is a certain way that AEM community can show me and I can come up with the best possible solution. Just one quick question. How do I execute backend calls in parallel on server side ?

Avatar

Level 4

Thanks for your response. Unfortunately that's not an option since there is a separate back end team for this.

Avatar

Level 4

Interesting. Do you have any examples of this, any document or any tutorial.

Thanks.

Avatar

Employee Advisor

Hi,

Well, as said, this is a generic question, and my answer to it would be "use Java futures and an executor service"; on my first search I've found [1].

To the statement "AEM is not good for dynamic stuff": It highly depends, how you did "dynamic stuff" in the past. In the AEM world you don't have technologies like spring and hibernate in the first place, but different technologies. And in the developer training you are told how you leverage the AEM technology stack to implement an authorable site. You are not told in these trainings how to build a highly dynamic site, that's true. But it's totally possible and also not that hard. You still have Java, you have at least a servlet engine, an OSGI container, a content repository plus lot of other stuff. You still can build dynamic sites, just the technology piece might be a bit different from what you used to work with. But the architecture of AEM does not prevent you from doing it.

kind regards,
Jörg

[1] http://www.vogella.com/tutorials/JavaConcurrency/article.html#futures

Avatar

Level 4

I did some research on the whole Dynamic stuff and I found Single Page Application to be suitable for that. AngularJS looks like to be the most suitable JS framework but being a Java developer it is not something that I can be expert at. Are you able to provide any insights into SPA approach on AEM.

Thanks

Avatar

Level 2

Based on the suggestions if we consider even to have parallel processing on the server side still the client  has to wait for the process to complete and the page is not going to available until  then. Having the process in backend makes sense if there is more processing that needs to be done after the service response.The problem here is that the client should not wait or see a blank screen until the data is ready for display. In my opinion this needs to be done in a two step process using lazy loading from the client side. The same parallel processing can be done having each component making the calls via AngularJS or JQuery(ajax) to the services. The backend services servers should be capable of processing these requests in parallel and each component can start displaying the data without dependency on other services. As I have mentioned earlier the dispatcher can be used to cache these responses as needed to improve performance as required.