Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it considered as a good practice to connect to two different databases in on microservice?

Is it considered as a good practice to connect to two different databases in on microservice API Or I need to implement another microservice for working with the second database and call the new microservice API inside the first one?

like image 547
user849727 Avatar asked Sep 10 '25 09:09

user849727


1 Answers

The main thing is that you have only one microservice per database, but it is ok to have multiple databases per microservice if the business case requires it.

Your microservice can abstract multiple data sources, connect them, etc. and then just give consistent api to whoever is using it. And who's using it, doesn't care how many data sources there actually is.

It becomes an issue, if you have same database abstracted by multiple microservices. Then your microservice is no longer isolated and can break, because the data source you are using was changed by another team who's using the same data source.

like image 71
Erndob Avatar answered Sep 13 '25 06:09

Erndob