6.0 Architectural Composition Patterns
In a microservice environment, a single client request often requires data and processing from multiple services. Architects employ composition patterns to provide proven solutions for orchestrating these inter-service calls, addressing the challenges of complexity, latency, and data aggregation in a distributed system.
Aggregator Pattern The Aggregator pattern introduces a single service—the aggregator—that acts as a coordinator. When a client request arrives, the aggregator calls multiple other microservices to gather the necessary data. It can then apply business logic to consolidate, transform, or filter the results before returning a single, unified response to the client. Architects employ this pattern to consolidate data from disparate sources into a cohesive whole.
Proxy Pattern A variation of the aggregator model, the Proxy pattern also introduces an intermediary service. However, a proxy may call different services individually without necessarily combining their results. This pattern is often used to provide a simplified or unified interface to a set of underlying services and can be used to implement an extra layer of security, acting as a gateway that controls access.
Chained Pattern In the Chained pattern, services are linked together in a sequence. The client communicates directly with the first service in the chain. The output of that service then becomes the input for the next service, and so on, until the final response is generated. A major drawback of this architecture is its blocking nature; the client must wait for the entire chain of synchronous calls to complete, which can introduce significant latency. It is therefore highly recommended to keep the chain length as short as possible.
Branch Microservice Pattern This pattern is an extension of the aggregator and chained patterns. It allows a service to communicate with more than one service at a time in a concurrent manner. For example, Service A could simultaneously call Service B and Service C to perform parallel processing. This pattern enables dynamic configuration of service calls and can significantly improve response times for complex requests involving independent processing paths.
Shared Resource Pattern The Shared Resource pattern is described as a conglomerate of the other patterns and is the most effective and widely followed approach. In this model, a client or a load balancer can communicate directly with each service as needed. This pattern offers maximum flexibility, allowing for a mix of aggregation, proxying, and direct calls depending on the specific business goal, providing an optimized path for any given request.