Gateway Aggregation pattern

Single service as aggregator of multiple individual requests

Published on Monday, November 9, 2020

Use a single service to aggregate multiple individual requests into a single request.

Problem

To perform a single operation, a client may need to call different backend services. By calling each service individually chattiness between the receiver (caller) and back-end increases. The chance of failure may seem insignificant, but if each request has a success rate of 99.9%, for a complete request that takes 10 calls, success rate is going to be only 99%. Of course, it would be possible to remedy this problem with retries, using partial data (if possible), etc. With high latency networks, this problem is even larger.

The popularity of microservices has made this problem much more prominent than before with classic service-oriented architecture (generally with much less independent services and cross-service calls).

Solution

Use a single back-end service - aggregate service, to aggregate multiple individual requests into a single request. Aggregate service can even be used with multiple clients.

The gateway should be as close as possible to back-end services, to reduce latency even further. For example if, let's say the mobile communicates with back-end services and it takes around 100ms for each request to complete. For only 3 requests, that cannot be parallel, it would take 300ms (100ms + 100ms + 100ms). But if we create a gateway, that is "closer to home", it could take few milliseconds (let's say 10ms) for the gateway to communicate with back-end services. With the gateway, the request would only last about 130ms (100ms for communication with gateway, and 30ms (10ms + 10ms + 10ms) for gateway communication with back-end services).

  • As with all gateways, the aggregation pattern creates a single point of failure problem.

References