Aggregate services

Data in a microservice architecture is owned by a single service, but there are many times when we might need to retrieve data from a number of different sources at once. Consider, again, a member of the Small Council in the land of Westeros. They may have a number of informants from whom they gather information about the workings of the kingdom. You can consider each informant to be its own microservice.

Tip

Informants are a fantastic metaphor for microservices as each one is independent and holds its own data. Services may also fail from time to time just as informants may be captured and terminated. Messages are passed between informants just as they are among a collection of microservices. Each informant should know very little about how the rest of the informants work, and even, who they are – an abstraction which works for microservices too.

With the aggregate service pattern, we ask each one of a collection of nodes to perform some action or return some piece of data. This is a fairly common pattern even outside the microservice world and is a special case of the façade or even adapter pattern. The aggregator requests information from a number of other services and then waits for them to return. Once all the data has been returned, then the aggregator may perform some additional tasks such as summarizing the data or counting records. The information is then passed back to the caller. The aggregator can be seen in this illustration:

Aggregate services

This pattern may also have some provision for dealing with slow-to-return services or failures of services. The aggregator service may return partial results or return data from a cache in the event that one of the child services reaches a timeout. In certain architectures, the aggregator could return a partial result and then return additional data to the caller when it becomes available.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset