简体   繁体   中英

All my microservices have their own db's, should I create common microservice to handle connections?

I have a number of microservices that maintain their own databases (mongodb, elastic, mysql) and each of the microservices I have to set-up a new connection constantly.

I was considering would it be wise if I created another microservice, that could handle these connections for the microservices, before they start up.

Example: My API Gateway microservice gets a request for search, it then calls search microservice, which before the search starts, calls the database setup miscroservice and returns an established connection back to it, based on what microservice called it (in this case - the search microservice).

Would it be better, if I just found out what connection is needed inside the API Gateway? Or should I just leave the logic separately in each microservice.

You would break the microservices encapsulation by assuming the type of persistence that each microservice is using.

Each microservice should be free to use whatever persistence type it wants or to change it when it wants transparently, without notifying or requesting permission from the other microservices about this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM