Search code examples
microservices

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?


Solution

  • 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.