Search code examples
google-cloud-platformmicroservicesgoogle-cloud-endpointsgoogle-cloud-run

How create a combined response from multiple microservices (cloud run containers) in a single api endpoint using Google Cloud Endpoints (gateway)?


I am familiar with firebase platform, but I am relatively a new user of the google cloud platform as whole. I am working on a project built using a microservices structure, and I do have so many question for which I cannot find an answer or better I cannot find any example. Unfortunately all the example that I am able to find are way to simple to be able to extrapolate a viable answer for my issues.

I adopted the new cloud run offer, and I decided to play with the full managed version (not kubernetes). I built few microservices (each service is built using express for node or flask for python - depending on what the services does). Each microservices expose it's own endpoint and has it's own api to call the methods - and I use a service account to allow the application to perform the internal calls.

I now want to expose the application to the external (specifically to my client built using vuejs technology), and I was trying to leverage another google product to create and expose an api: the google endpoints.

My question (specifically referred to the cloud run structure) is related to how is possible and what I need to do to create an api endpoints to communicate with the client app, that internally calls multiple services and combine their response in one.

Just to be clear, let's make an example:

  • Cloud run service 1 -> crud user api

  • Cloud run service 2 -> crud product api

  • Cloud endpoint external visible api -> get user from service 1, and after get products from service 2 and return the combined response all green products for user Jane Doe.

How I can aggregate the response directly in the endpoint gateway, check for failure and if everything goes smooth send the aggregate response to the client?

I need to build the aggregate endpoint in something else, like a cloud function for example? or I can do it directly in the google endpoints gateway?

Note that for cloud run the google endpoints is another cloud run container.

Thanks guys for some help, running pretty much out of option here.


Solution

  • In my opinion, from an architectural point of view, the best option for you is to create a new microservice which will take the responses from the other two and then, it will aggregate them.

    I understand that you want to aggregate the responses in a api-geteway and you are not able to find code examples for it. Here I was able to find a guide on what are you wanting to implement. The full code implementation can be found in this repository.

    Keep in mind though, this idea of implementation is not a best practice.