Akka, Cluster and Microservices

Akka is a great tool. It has so many cool feature and very impressive performance. Today its one of the best technologies todo lightweight sync or async processing. Great for high frequency trading domains, onlime media, ads and financial. Even if your company is not in one of this domains you can benefit from akka, specially if you are looking for efficiency.  So whats the relation with Microservices architecture(MSA)? Microservices architecture powers distribution over centralization, thats leverage another aspect called Discoverability.

Because you will have way more services so its almost impossible to configure and handle all this services with static registries and manual operations thats why also we need DevOps in this context.

Discoverability for Free

Akka Cluster gives discoverability for free to you.  Akka cluster works with Gossip Protocol, this happens in a very event driven way, so this is also create for EDA scenarios. So it`s very easy to get events like when a node is up, node is down, actor is created, actor is killed. You will need go code your application using this information but won't need worry about complex configuration.

You dont need code anything because the cluster already know how to discover other nodes but you will need code what your application needs todo with that information so the discoverability is for free but the business logic is not. :-)

Akka Cluster is more like a Tool Set, you should think that akka cluster is not a container like JEE container like JBoss/WildFly. Because in a JEE Container you have things inside the box, in akka you have tools to build things inside the box, akka cluster have tools that allow you to create your specs, your abstractions to work with the cluster thats very different compared with a JEE container, once you get that in mind everything else will be way easier.

Design VS Actor Model VS Akka Technology

When we talk about microservices we are always talking about SOA. In SOA we have internal service design that will vary service from service, but depending of your nature or business requirements you can use an actor model for it. Other times actor model won't make sense because not everything should be model as actors, actors are great but they suck for composition and they are not good stateful tasks and long running jobs.

It`s possible to benefit from akka even not using actors model, but use akka as a technology and creating abstractions in the top of akka, thats whats type safe did with the play framework for web development. You can create your own abstractions, your own "middleware" with akka.

Code your business services in whatever model it makes sense, even in java or any other JVM language. Down into the internals, under the hood, use akka to run things. So the service can handle all standard SOA concerns like Backward compatibility, versioning, contract testing, business centralization and you let akka and akka cluster deal with discoverability, service catalog, registry, transport, remote transport, serialization and scalability.

In this case akka will be like a worker for you. The advantage of this approach is that you can plug all sets of things into the cluster not only SOA service but GUI Applications, Legacy Systems, Data Services and make your service assets easy to consumed by anyone with discoverability, remoting, non-blocking programing models for you. However when need think about operations Akka is not great in sense of monitoring, there are some paid solutions from typesafe but you wont find many monitoring and operation capabilities for you like kamon.

Leverage Microservices

Akka does not work only on the cluster flavor, you also can work with the akka kernel and use akka with a embedded actorsystem. This is great for isolation and you still can join the cluster if you want, thats amazing because you could use akka into a CQRS way to deal with data updates and notifications.

Microservices are about distribution, that does not mean you would not benefit from akka, because even with a microservice you still need todo computations, akka will help to get a great model to deal with parallelism(the actor model) inside your actor / microservice scope.

Popular posts from this blog

Podman in Linux

Java Agents

HMAC in Java