Problem Statement

A microservice based application can have multiple services, each performing a unique individual task. A client to the application may require combinations of data obtained from each of those microservices. Microservices usually provide fine-grained APIs, which means that the client would need to interact with every individual microservice of interest.

The Aggregator Pattern attempts to solve a similar problem as the API Gateway Pattern.

The Aggregator Pattern

The Aggregator is a microservice by itself. It provides a unified API to a client obtain data from various microservices. Unlike the API Gateway pattern, the Aggregator will not be an entry point to the system.

This is a composite service that is used when we need to apply a set of rules while preparing the result data created from the outputs of multiple microservices.

The Aggregator pattern sends requests to multiple services for data, and then aggregates the data for the requestor.

Usage of the Aggregator Pattern

The Aggregator is efficient when:

  • Used as a collection point for data from microservices, and not as a switch or router;
  • When the collected data must be processed according to certain rules
  • When the transaction rate is low
  • When the risk due to the Fan-out Antipattern is low (ie. when multiple services fail leading to a potential slowing down or disruption of services)
  • When data provider services are asynchronous

Advantages of the Aggregator Pattern

  • Reduces the communication overhead between a client and the services from whom it requires data
  • Architecturally, allows for simple endpoint consolidation of discrete functionality.

Disadvantages of the Aggregator Pattern

Some issues with the usage of this pattern may be:

  • Updates to the implementation due to new service additions may require us to redesign the code.
  • Increased risk of latency or failure when one or more of the data provider microservices (or their dependencies) fail
  • Troubleshooting may be laborious

Contextual Example

An example can be found in [6].

Online Code Examples

[Example 1] https://github.com/iluwatar/java-design-patterns/tree/master/aggregator-microservices

References

[1] DZone on the Aggregator Pattern: https://dzone.com/articles/design-patterns-for-microservices

[2] API Gateway Pattern: https://medium.com/nerd-for-tech/design-patterns-for-microservices-aggregator-pattern-99c122ac6b73

[3] Aggregator vs. API Gateway: https://stackoverflow.com/questions/68044745/api-gateway-pattern-vs-aggregator-pattern-in-the-context-of-microservices

[4] Aggregator on the AKF page: https://akfpartners.com/growth-blog/microservice-aggregator-pattern

[5] Fan-out Antipattern : https://akfpartners.com/growth-blog/microservice-anti-pattern-service-fan-out

[6] Gateway aggregation : https://docs.microsoft.com/en-us/azure/architecture/patterns/gateway-aggregation