Best practice to proceed request processing AFTER response has been sent

Hi,

currently the very last step in our request processing with ServiceStack is actually sending out the response (via returning from the service implementation).

We want to speed up request processing, so we’re thinking about starting tasks asynchronously and responding to the request, without having to wait for the task’s response.

Is this possible at all, and if yes, is there something like a best practice / pattern do realize that?

Thanks!

You can fire a new thread to process the request but keep in mind that the Request/Response instances aren’t thread-safe and likely be disposed of when accessed in your thread, so it shouldn’t be accessed in a background thread.

You can fire and forget a task in the background, but as it’s easy to lose visibility of the Request, whether it completed or why it failed, so it’s common to use a MQ or a Job Queue for offloading and executing tasks in the background. So something like ServiceStack’s Messaging support or a 3rd party solution like http://hangfire.io

Otherwise if it’s not important that the task is completed before the client receives the response, your client could just be making async non-blocking requests, that way it can continue without needing to block on waiting for the response.

1 Like