Lagom is a framework for building microservices. It’s based on Lightbend’s reactive technology stack. I’ve been playing around with the Scala version of it and I’m noting down some of my understanding here to supplement the Lagom (+ Play + Akka) documentation.
Starting with the high level overview of the technical stack, Lagom has both Java and Scala based implementations. I only really have experience with the Scala version and there a Lagom project is a multi-module SBT project. Essentially each service uses the Play framework to implement HTTP APIs. Lagom provides a DSL over the Play API so defining the actual service is slightly different. However, it’s all built on top of Play. Within the world of HTTP APIs Lagom allows us to produce and consume both standard request-response APIs and Websocket streaming APIs. Lagom further allows us to publish messages to streaming topics via Kafka. Finally, serialisation between services, over either HTTP or Kafka, uses Play-JSON by default. It’s possible to configure other serialisation technologies.
A key point here is that an instance of a Lagom service is just a Play server. The Lagom DSL is primarily aiming at configuring the server cleanly and easily.
Within the Play services Lagom provides easy access to the Akka framework for defining actors. Newer versions of Lagom lean towards Akka-Typed. With the Akka framework comes not just the Actor implementation but also patterns around persistence, clustering and streaming. Akka actors persist to Cassandra, so they can then be recreated on any instance of the service in the cluster. Having said that not every actor needs to be persistent. Nor does every actor need to be sharded across the cluster.
SBT will package Lagom services as docker containers. They can then be deployed to a number of container environments. Kubernetes is probably the simplest. There are a number of possible implementations of Lagom’s ServiceLocator interface. By default the framework will use an implementation based on Akka HTTP.
In summary, there’s quite a lot of technology in a Lagom Microservice. As such, it’s worth having a working knowledge of each of these before you start building a Lagom microservice.
- Scala
- SBT
- Play Framework
- Akka
- Akka Persistence
- Akka Streaming
- Akka Cluster
- Akka HTTP Service Discovery
- Cassandra
- Kafka
- Kubernetes