Search code examples
javaweb-applicationsserverclientclient-server

Best practice to notify client from serverside?


In my current situation, the frontend client is making an api call to a backend endpoint (java) at a 15 second interval to see if a resource exists. The resource will be created through some business logic. Once the resource exists, client will get the data from api and process it.

However, it seems that it is a costly performance and not scalable to call an api every 15 seconds. I was wondering the best practice for this - the client waiting for a resource to exist to execute some logic.

Is there a way / best practice to send/push data from the server to the client rather than the other way around as well as being unidirectional (server -> client)..

Thank you in advance.


Solution

  • In order to solve this properly you will need to implement WebSocket. The Request from the client will be a GET and the server will approve it with 200 status code to confirm. Then ,when the server will done process your request , it will broadcast the data via the websocket directly to your web application.