1
votes

We are currently studying the possibility of transforming our existing monolith application into fine-grained Microservices running along an API gateway for coordination.

I have this case where there are three microservices:

1- Product Microservice: A REST API service for products. 2- Category Microservice: A REST API service for categories. 3- Aggregation Microservice: A REST API service which joins between a list of categories and their products and then return them into one model.

According to the attached image, any client can send a request to the API Gateway specifying which microservice he wants to retrieve information from in addition to all request options like HTTP method and request body.

The API gateway will receive the client's request and use service discovery reroute it to the designated microservice.

My question is, what if the client tries to contact the aggregation microservice? This will result in a request to the API gateway and then the API gateway will reroute to the aggregation service. However, the aggregation service needs to contact both category and product services in order to reply back to the client with a unified model. This requires the aggregation microservice to also contact the API gateway again so it can reroute its requests to the category and product microservices.

There seem to be a lot of communication traffic occurring here, am I missing something here or this is the right way to implement such scenario.

API Gateway Example

1
Clients should make requests against API gateway, not against an specific service. API gateway get the needed data from the other services, aggregate it and returns the data back to the client. Service discovery shouldn't be visible to the client.Héctor
Hello Hector, I understand that service discovery should not be visible to clients. However, my question was about the internal communication between microservices. If microservice A wants to communicate with microservice B, should this happen directly or through the API gateway. Moreover, which approach is best practice, create a microservice for the purpose of aggregating the data or just perform the aggregation inside the API gateway? Thanksmohammed.khalidi

1 Answers

0
votes

In your case the easiest approach would be to do service orchestration. The domain services wouldn't talk with each other and the aggregation service would be the orchestrator that would call the two domain services, combine the results and return them to the client. The gateway should only contact the orchestrator that would be also a facade that would hide to the client the complexity of the internal services.

The alternative is service choreography in which the communication is decentralised and each service decides which other services it should contact. However it is a lot more complex and it is only worthy when you have tons of microservices. For example you have to prevent cycles, it is more difficult to deploy separately because you have to consider the dependencies...