joethemow
joethemow

Reputation: 1773

Should a microservice take care of this or the api gateway?

I am building out a microservice architecture and kinda confused on one part. I am using Kafka as a message broker system to communicate within my services. A perfect example would be Uber's API for request estimation. It returns duration, distance, price, etc. I would assume they have a microservice for each of those, i.e. service for pricing, service for duration/distance, service for drivers, etc. My question is when hitting the endpoint /requests/estimate does the requests microservice make rest calls to the other microservices to retrieve data for the duration, distance, etc? or does the API Gateway take care of that?

Upvotes: 0

Views: 1078

Answers (3)

V. Mokrecov
V. Mokrecov

Reputation: 1094

In practice, not all gateway APIs support multiple calls and aggregation. In the micro service architecture, there is a common pattern ("API Composition", "Composition Patterns" in particular "Aggregator Pattern"), the idea of which is that you need to make a separate service that will contain the business logic of multiple calls and aggregation.

Upvotes: 1

Raphael
Raphael

Reputation: 405

Both are perfectly valid ways of doing it, but I would go the Estimate microservice way to avoid putting too much logic in the API Gateway.

Maybe in the future your estimation calculation will change, and it wouldn't make much sense to me to update the gateway every time.

Upvotes: 1

Jocke
Jocke

Reputation: 2284

I say it depends on the use case. If service A needs to know what service B knows, then it is perfectly sane for service A to make a REST call to service B. But if the combined knowledge for A and B is only needed in your gateway then the gateway can combine the results.

Upvotes: 1

Related Questions