8.3 Aggregating Gateway
Aggregate multiple service requests into a single client responseThis pattern is based on Newman’s Central Aggregating Gateway [3, p. 475], Microsoft’s Gateway Aggregation [49] and Richardson’s API Composition, specifically its implementation in a service [20, p. 221].
The last of the roles of a central gateway (defined in § 4.1) is to coordinate and aggregate multiple service responses, but in contrast to Offload to Gateway (§ 5.3), this acts for the benefit of the clients. While this pattern is a distributed equivalent of the well-known facade pattern, it has different corollaries and is worth mentioning separately.
8.3.1 Context
Clients need data from multiple services, and there is a need for at least one of the following.
Reduce the complexity of the client by offloading the aggregation or filtering logic to the gateway.
Reduce network usage with the client if the amount of data is larger than the aggregate and the gateway, especially if the gateway is near the services.
Decrease latency and improve reliability if the data has to be transmitted over an unreliable or high-latency network, such as over mobile networks, as each new request adds to the latency and increases the likelihood of failure.
Decrease coupling between the client and the services
8.3.2 Solution
Extend a Gateway Router (see § 4.1) with a Facade (see [24, p. 175]). Instead of a client sending multiple requests to different services to ask for the resources it needs to construct the result, it asks directly for the result (see fig. 22).
To also effectively combat network latency and reliability issues, the gateway needs to have a better link to the services than the client.
8.3.3 Potential issues
Overuse of this pattern has similar effects as the overuse of Offload to Gateway (see § 5.3), namely becoming a development and performance bottleneck and a single point of failure, and handling too many concerns.
8.3.4 Example
See the example in Backend for Frontend.
8.3.5 Related patterns
If only no aggregation is needed, Gateway Routing can still be used to abstract service locations (see § 4.1)
After an aggregator is placed, it might be beneficial to offload shared functionality to it using Offload to Gateway (see § 5.3) – however, see the note in § 4.1.7
If the need for server-side aggregation comes from differing needs of clients, Backend for Frontend (BFF) can be instead utilised to effectively combat the complexity of the aggregator (see § 5.4)