Udi Dahan on Service-Oriented Composition
In a Service-Oriented Architecture (SOA) where client-side components for one service runs in the same process as components for other services we need to collect several logical calls into one larger physical call, Udi Dahan explains answering a question of how to avoid the high cost, in terms of client to server communication, that otherwise could be substantial.
Demonstrating how to optimize client-server round trips when using loosely coupled components both on the client-side and the server-side, Udi, an authority on service-oriented architecture and creator of NServiceBus, gives an example where an event raised on the client side, e.g. a clicked button, result in two components requiring access to their respective server component in order to get data.
Instead of a regular Ajax call each component subscribing to the event uses a client-side wrapper library to register a call-back method to be called when data is returned from the server. This library is aware of the context of the event being processed and therefore holds all requests in memory until all call-backs have been registered at which time it makes one physical call to the server with all the requests.
On the server side a corresponding library unpacks all the independent requests and invokes the corresponding server component for each request. When the result from all components has been received they are returned as one result to the client.
The client library, when receiving the response, unpacks and dispatches the individual results to each client component at which point the event has been fully handled.
Udi emphasizes that most of the code written for both client and server is transparent to this wrapper library. What’s added is a generic packing and unpacking library enabling support for client and server side composition with lots of small components doing logical calls while minimizing the actual calls made between a physical client and a physical server.