Invoking services synchronously or asynchronously
You can invoke services either synchronously or asynchronously.
- Synchronously invoked services (on demand) - These services can perform all their processing and return the result in single call.
- Asynchronously invoked services (message driven)
Synchronously invoked services
These services can perform all their processing and return the result in a single call, on demand.
Asynchronously invoked services
These services automatically perform all their processing whenever triggered by a message from an external system or from within the application. The trigger could be in the form of a file, a database record or a message in a message queue depending upon the mode of integration. These services do not return any value and are purely used for background processing such as sending out emails or automatically receiving updates from or sending updates to an external system.
In general, asynchronous services provide a lower cost to performance ratio than synchronous services and should be preferred wherever possible. However, asynchronous services queue up and process messages in the order they are received. The time to process a certain transaction after it's been queued can vary widely depending upon peaks in your processing cycle and a host of other factors. Therefore, they are not suitable for certain specific scenarios where an SLA (service level agreement) requires that a transaction has to be processed within a specified short time frame. However, these scenarios are rare for most businesses and business processes and asynchronous processing is efficient enough for the majority of transactions at a significantly lower cost while still providing a high service level.