I already have REST API (for System-to-System communication) which takes lot of time to process.
I want to have asynchronous processing. I see two options here:
To make the API itself as asynchronous, where it returns a LOCATION header giving another URI to fetch result.
To make the client asynchronous - using asynchronous HTTP Client or AsyncRestTemplate etc.
I was wondering what is better way in such scenarios, as both seems to solve the issue.
There are some pros and cons to each of the options you mentioned that you may want to consider when making a decision.
This approach has a lot of benefits, such as allowing the API to process requests in parallel and improving the overall performance and scalability of the system. However, this approach can also add some complexity to the API, as it requires the API to implement asynchronous processing and provide a mechanism for clients to fetch the result of a request.
This approach can provide a simpler and more straightforward solution, as it does not require any changes to the API itself. This approach can also improve the performance and scalability of the system, as it allows the client to process multiple requests in parallel and handle responses asynchronously. However, this approach may require the client to implement additional logic to handle asynchronous processing and fetching results, which can add some complexity to the client.
Making the API asynchronous can provide better performance and scalability, but may require more complex implementation, while making the client asynchronous can provide a simpler solution, but may not provide the same level of performance and scalability. You will need to weigh the pros and cons of each approach and decide which is best for your specific system based on your requirements and constraints.