Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to share case classes-based messages in an Akka microservice architecture

Tags:

scala

akka

Keeping with the spirit of a microservice architecture, I'm pondering using a git repository for each service of my Scala+Akka based system. The build for each service produces an artifact that is published to a packaging system (e.g. maven) repo. These artifacts are the mechanism used for sharing common code.

Now, since using case classes for message passing between services, the same class version needs to be available everywhere. Would it be advantageous to separate each service in an interface and implementation artifacts using a multi-project build, and then only import the interface artifact from the dependent projects? Some alternatives would be to include both the interface and implementation on the same artifact and importing that, or have separate repos for the interface and implementation which seems overkill and likely to be too much overhead.

like image 218
mgois Avatar asked Oct 27 '15 12:10

mgois


1 Answers

Here's where you will get the 2 view points on micro-service based designs, share everything and share nothing. I'm on the share nothing side. Agree to a communication interface (like JSON or some other serialization mechanism) and allow each service to handle the domain object representations separately. Here's why

  1. If one updates its code base, another is free to not update until it absolutely has to update in order to interface properly. It also means that your parsing libs can interpret the objects as needed and ignore fields that they don't care about.

  2. Logic tends to find its ways into things. Worse, business logic tends to find it's ways into little "helper" methods on classes, even case classes. This can adversely couple services in benign ways ...right up until it's no longer benign.

like image 172
wheaties Avatar answered Oct 11 '22 06:10

wheaties