Tech Basics
Tech Basics

Reputation: 27

How to get data between Graphql Microservices with Shared Database?

In the midst of developing a Graphql API for our application we decided to embrace the microservices architeture and made a desicion that we should have another API for payments (which also would be a Graphql API) just so we could start with decoupling our App. We are using MongoDB for our database with Mongoose. The problem that we are facing at the moment is that in order to work with payments we would need to get user data but our Payment API does not have Mongoose Models through which we could query user data. We are wondering what would be the best approach to solve this. Do we copy the Models that we need to query from the first API? What is it that we are doing wrong here? Is it a wrong approach altogether to have a shared database in microservices architecture?

Upvotes: 1

Views: 528

Answers (1)

Josh Wulf
Josh Wulf

Reputation: 4877

The whole idea of GraphQL is to have a single endpoint. This reduces the complexity for the "front-end" developers (API consumers).

So you would have a GraphQL endpoint service that manages database access.

Usually "micro-services" have their own databases.

You can still put business logic in microservices, but you would have those services contact your GraphQL service for database access.

But if you are fronting the system with a GraphQL API, then you make a single endpoint.

To have these discrete microservices as you describe, you would usually make them REST or gRPC for the consumer.

Upvotes: 2

Related Questions