Web service method can be either syncronous or asyncronous. A high quality web service should be very clear about whether each end point is syncronous or asyncronous.
What are syncrhonous operations?
Syncronous operations completes the operation at the time of completion of sending response. It is suitable for operations that can be completed at milliseconds level. Operations only involve database reading operation typically can be completed at this time frame. Syncronous operation returns result in the response to the client.
What is asyncronous operation?
Asyncronous operations completes the operation after the completion of sending response. It is suitable for operations that may last longer than a typical http request timeout. Examples include async Blob copy method of Azure Storage service, create job method of Azure media services. Both method operate on Gigabyte level of data, it may take hours to complete those operations depending on the job size and work load on server side. The response of these operations typically contain a unique id to identify the submitted request, and client can check the status of the operation using the ID given.
What are the common pitfalls?
There are two possible types of error. Among them, type I error is much more common than type II error.
I. Asyncronous operation was implemented as syncronous.
Type I error occurs when the response is returned prior to the completion of the operation. Upon receiving the response, the client may take action based on the assumption that the prior operation had already been completed. This type of error basically breaks the atomicity of the web service operation.
The fix of the operation can be either delay the response until the operation is completed or convert this “syncronous” operation into an asyncronous one.
II. Syncronous operation was implemented as asyncronous.
This type of the error is very rare simply because implementation of asyncronous operation typically takes a significant more resources, it is unlikely that developer will take the pain to write a complicated async web service which can be completed instantaneously. 🙂