views:

15

answers:

1

Are there any best practices that dictate the maximum time between an asynchronous call and its corresponding response.

Basically I have a process that takes a long time to run (eg: 5 minutes). Option 1: I could expose the process as an asynchronous call. In which case the user calls my service and then at some later time, I respond with a process status.

Option 2 The other way I could implement it is to setup the system such that there is a one-way operation on my web-service that begins the process and immediately returns an id for the process. I could then mandate that the consumer provide a one-way operation, that I can call and report back when the process is done.

The first option is easier as I dont have to mandate anything from the caller. The second seems better as I can report back at anytime (5 minutes to years later).

As I have complete control over the caller and its an internally available service, I am leaning towards option 2.

So I am wondering if there are any time limits imposed on async calls (can they span days? if not what is the best practice). Is option 2 a standard pattern employed?

References would be extremely useful.

+2  A: 

Option #2 is better as it's more event driven.

However, there exists an Option #3. Client issues request to server. Server queues request and responds with the id. Client checks back every so often, passing the request id, to see if it's completed.

This way you don't have to depend on the client being available when the request is completed.

I'd probably mix options #2 and #3 and let the client choose if they want an event fired on their side or if they just want to check back later.

UPDATE
Rajah has asked about the maximum time between async request and response. For a WEB application, this is typically measured in seconds. Most servers have timeout values that are typically defaulted in the 30 second range. Personally, I think this is too long.

Consider that an Async call requires the communications channel between the client and server to be open for the duration. How many of those channels can a single server handle? More to the point, how many channels will you have to maintain as requests are made? This can become quite outrageous even if you do control both ends.

Whatever is hosting your services is going to determine the maximum amount of time to keep a request open. Again, every server I've seen measures this in seconds.

Chris Lively
Option 3 would have my vote for any process that can possibly take more then a couple of seconds.
Wrikken
This is a good answer. And I would mark it answered - but the one part that hasnt been answered is: what is the max time between async request and response.
Rajah