Best way to add asynchronous execution for already implemented synchronous process

I have a complex process implemented in Java Spring microservice. Currently this process is triggered on user request and it is synchronously executed. This often results in a gateway timeout. Execution can last from 30s to 10min, also I does not want to increase gateway timeout. So I want to execute it asynchronously on a user request and immediately return status 202. There are few options: On the controller side spawn a new thread and execute this process in a spawned thread. Change the process implementation so it is always executed in a new thread. Add a new component like AsyncProcessExecutor which executes process in a new thread. AsyncProcessExecutor seems like a best option it does not clutter the controller nor already complex process. AsyncProcessExecutor could be extended easly to send slack notification on process completion.

May 2, 2025 - 11:39
 0
Best way to add asynchronous execution for already implemented synchronous process

I have a complex process implemented in Java Spring microservice. Currently this process is triggered on user request and it is synchronously executed. This often results in a gateway timeout. Execution can last from 30s to 10min, also I does not want to increase gateway timeout. So I want to execute it asynchronously on a user request and immediately return status 202. There are few options:

  • On the controller side spawn a new thread and execute this process in a spawned thread.
  • Change the process implementation so it is always executed in a new thread.
  • Add a new component like AsyncProcessExecutor which executes process in a new thread.

AsyncProcessExecutor seems like a best option it does not clutter the controller nor already complex process. AsyncProcessExecutor could be extended easly to send slack notification on process completion.