rithinch / event-driven-microservices-docker-example

šŸ³ Simple example of event driven communication between microservices, based on Docker containers, Docker Compose and RabbitMQ. Microservices are implemented in Node.js using Koa.
MIT License
250 stars 85 forks source link

Question: Querying across services, Database-per-service or One database #28

Open darklight147 opened 3 years ago

darklight147 commented 3 years ago

Hi am building a simular project, using event driven microservices architecture, and am stuck thinking wether i should use a single Database and connect all services to it, or do a database-per-service approach, i could brainstorm some reasons why doing a single database is bad (sharing Model schema between multiple services)

but the advantage am looking for in the single Database approach is: you can query any table you want, which is a thing i can't do in database per service, soo my question is how would you go about querying data from another service, let's say UserManagement needs data from ticketing service for exemple, any approach aside synchronously calling the other service using http.

Am using rabbitmq to broadcast the creation of a document to other conserned services

SuspiciousLookingOwl commented 3 years ago

Might be helpful (from microservices.io)

There are various patterns/solutions for implementing transactions and queries that span services:


https://microservices.io/patterns/data/shared-database.html

The benefits of Shared Database pattern are:

The drawbacks of Shared Database pattern are:


https://microservices.io/patterns/data/database-per-service.html

Using a database per service has the following benefits:

Using a database per service has the following drawbacks: