How should the various services share a common DB Schema and code?

Technology CommunityCategory: MicroservicesHow should the various services share a common DB Schema and code?
VietMX Staff asked 3 years ago

The “purest” approach, i.e. the one that gives you the least amount of coupling, is to not share any code. In practice, as usual, it’s a tradeoff:

  • If the shared functionality is substantial, I’d go for a seperate service.
  • If it’s just constants, a shared library might be the best solution. You need to be very careful about backwards compatibility, though. Use a packaging system or some source code linkage such as git-tree for distribution.
  • For configuration data, you could also implement a specific service, possibly using some existing technology such as LDAP.
  • Finally, for simple code that is likely to evolve independently, just duplicating might be the best solution.

Regarding schema – if you want to play by the book, then each microservice has its own database. You don’t touch mine, I don’t touch yours. That’s the better way around this.