Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share code between micro services?

For example, I have a project which has 4 micro services: client-web, admin-web, client-api, admin-api.

These four micro services should share one DB code, should I make the DB code as a submodule of git and use it in each micro service?

does it against micro service principle?

like image 751
Sato Avatar asked Mar 01 '26 02:03

Sato


2 Answers

  1. Create a library.
  2. Version the library with semantic versioning and create a package using the package management functionality of your environment (e.g. Nuget if you're on .NET).
  3. Include the package as dependency in the micro services.
like image 183
theDmi Avatar answered Mar 04 '26 16:03

theDmi


I think you should be careful making a shared library and include it in your microservices because it can give you a point of coupling, meaning that if you have to make changes to the library, you might have to change all your services, and then you loose one of the benefits of this architecture -deploying small services without deploying the whole application.

I think a better approach is to make it a microservice on its own.

like image 20
Jack Petersen Avatar answered Mar 04 '26 16:03

Jack Petersen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!