Reputation: 37
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.
Upvotes: 0
Views: 412
Reputation: 17683
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.
Upvotes: 3