Search code examples
microserviceslagom

Dividing microservices in Lagom


Lagom by default creates two modules for every microservice - API and implementation.

Is it possible to divide one microservices into 3+ modules?


Solution

  • Absolutely. You would do this the same way you would with any other Java or Scala project: create a sub-project that is an internal library included into your service.

    For an example of this look at the Online Auction Java example Lagom project. Specifically, the security and tools sub-projects. These are included into other services using the sbt dependsOn method in build.sbt.

    For example:

    lazy val itemApi = (project in file("item-api"))
      .settings(commonSettings: _*)
      .settings(
        version := "1.0-SNAPSHOT",
        libraryDependencies ++= Seq(
          lagomJavadslApi,
          lombok
        )
      )
      .dependsOn(security, tools)
    

    In this case, it is the API project that depends on the additional libraries, but you could do the same thing with your implementation project to use libraries that are not needed by the API. Note that the implementation project also depends on its corresponding API, so any dependencies of the API are inherited by the implementation.