Background: At work I was tasked with developing a new demo web client to replace our Windows Form application in the future. Our back-end is developed in Java and works stateless as REST services. The demo client should be based on Angular as we want to try out some things first. Both I and other developers already have expertise there. Whereby other web future oriented frameworks are also welcome.

Problem: The migration to a new client is no problem and no challenge. However, there are one or two problems and challenges. We have a couple of functions that require a lot of processing power but these functions are executed on the client side. In the future this should no longer be the case but happen in the backend. So far so good BUT these algorithms start with various start parameters and execute certain logic. In the course via. Dialogs various new input parameters are needed or information messages are displayed. So the program or these function(s) wait for the user input before continuing. (These do not run in their own thread btw). The whole thing should now be outsourced to the backend. Here the question arises how something like this could be implemented. Since our current architecture does not allow such a thing (REST).

We have already briefly looked at WebSockets as this seems to be the way-to-go to realize something like this. Just a fixed connection between client and server to communicate and not as currently stateless within closed requests and responses.

Is this even possible? We don't really know where to start right now, because every online example for WebSockets implementation (in Java) do not really seem to fit our needs.

So basically we need something like this:


Any help, feedback and ideas are welcome.


WebSockets examples, is this even the right technology for this

1 Answer 1


The real problem lies typically in the part you forgot to draw in your image:

enter image description here

Such requirements can typically be solved by doing some preprocessing on the server (a small part of the "heavy calculation") in the first request/reponse step to determine which input from the user is required. Then, after the user provided that data, the second request/reponse starts the "heavy calculation" in full, now with all missing data available, so no interrupt will be necessary.

Technically, this will also work when the preprocessing is a heavy calculation by itself. The user experience and performance might not be optimal in such a case, since the preprocessing might have to be done twice. You need to look at your specific case if that is really an issue, or if that is acceptable.

This strategy avoids the need for keeping intermediate results in a stateful manner on the server. If that really becomes too slow, you could try to cache the intermediate results from the preprocessing on the server for a certain period of time, indexed by some hash value derived from the input parameters, and try to lookup those results in the cache when it comes to do the final calculation.

For displaying information messages during the calculation, or displaying the final results, use standard AJAX techniques, or maybe Websockets (you may have a look into Why use AJAX when WebSockets is available?).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.