We have several microservices on Golang and Python, On Golang we are writing finance operations and on Python online store logic, we want to create one API for our front-end and we don't know how to do it. I have read about API gateway and would it be right if Golang will create its own GraphQL server, Python will create another one and they both will communicate with the third graphql server which will generate API for out front-end.
I do not know much details about your services, but great pattern I successfully used on different projects is as you mentioned GraphQL gateway
.
You will create one service, I prefer to create it in Node.js where all requests from frontend will coming through. Then from GraphQL gateway
you will request your microservices. This will be basically your only entry point into the backend system. Requests will be authenticated and you are able to unify access to your data and perform also some performance optimizations like implementing data loader's caching and batching to mitigate N+1 problem. In addition you will reduce complexity of having multiple APIs and leverage all the GraphQL benefits. On my last project we had 7 different frontends and each was using the same GraphQL gateway
and I was really happy with our approach. There are definitely some downsides as you need to keep in sync all your frontends and GraphQL gateway
, therefore you need to be more aware of your breaking changes, but it is solvable with for example deprecated
directive and by performing blue/green deployment with Kubernetes cluster.
The other option is to create the so-called backend for frontend in GraphQL. Right now I do not have enough information which solution would be best for you. You need to decide based on your frontend needs and business domain, but usually I prefer GraphQL gateway as GraphQL has great flexibility and the need to taylor your API to frontend is covered by GraphQL capabilities. Hope it helps David