Anti-patterns

This is a collection of articles I wrote over the years, presently with a strong focus on building reactive systems with Akka.

Akka anti-patterns: Java serialization

Published on 20 July 2018

Akka makes use of serialization when messages leave the JVM boundaries. This can happen in mainly two scenarios: sending messages over the network when using Akka Cluster (do not use Akka Remote directly) or using Akka Persistence. Now here’s the catch: the default serialization technology configured in Akka is nothing but the infamous Java serialization, – Read More

Akka anti-patterns: stateless actors

Published on 30 May 2018

Actors are object-orientation done right (as opposed to say, objects in Java): their state is not visible from the outside and they communicate via messages. There’s no way to break encapsulation because you can’t peek into an actor’s state while it is running. That’s the entire point of actors: they provide you with the illusion – Read More

Akka anti-patterns: overusing ActorSelection

Published on 20 March 2018

Akka’s ActorSelection makes it possible to look up actors by logical path in the hierarchy:

This selection can then be used like ActorRef in order to send messages to it using the tell or ask patterns:

ActorSelection is therefore quite useful and allows more flexibility when designing an actor system given that trees – Read More

Akka anti-patterns: trusting the network

Published on 20 June 2017

One anti-pattern I’ve observed in networked Akka applications is a tendency to forget that it is, well, networked and to treat the network as a friendly place. How does that look like? Well, consider the following piece of code:

Akka’s default message sending mechanism is the fire-and-forget tell method. And that works great – – Read More

Akka anti-patterns: using remoting

Published on 8 June 2017

Whilst I have always successfully discouraged my clients from using Akka Remoting in their application, I often get questions regarding remoting while talking about anti-patterns at conferences and user groups. Don’t get me wrong. I love Akka remoting. Especially the new Aeron-based Artery remoting version that is based on UDP rather than TCP. Whilst it – Read More

Akka anti-patterns: blocking

Published on 15 May 2017

This is probably one of the most frequent (and dangerous) anti-patterns when it comes to working with Akka. Let’s look at an adequate description of the mindset you must be in in order to use it: So maybe you didn’t actually want to see the world burn. Maybe you thought that this one time it – Read More

Akka anti-patterns: being out of touch with the hardware

Published on 21 November 2016

Choosing Akka as a tool is often – if not always – driven by the need for good performance. Surely, the actor model itself is appealing as a means for organizing and reasoning about code, but this isn’t in itself a good reason enough to use the Akka toolkit. If all you are concerned about – Read More

Akka anti-patterns: logging (the wrong way)

Published on 31 August 2016

Update: removed rogue toString call in the second code example, since it was unnecessary (and harmful). Debugging actor systems is no small feat, even when there is IDE support for it. In fact, debugging any asynchronous system for that matter is a rather complicated task. Which is why, especially during development, it is not entirely – Read More

Akka anti-patterns: too many actor systems

Published on 23 August 2016

Admittedly I’ve seen this one in use only one time, but it was one time too many. For some reason I keep seeing clients come up with this during design discussions and reviews though, therefore it makes it into the list of Akka anti-patterns. What I am talking about is this: Reasons I hear for – Read More

Akka anti-patterns: race conditions

Published on 16 August 2016

The actor model makes it possible to build highly-concurrent applications through the notion that actors obey the actor send rule and the actor subsequent processing rule, hence creating a single-threaded environment inside of an actor. That being said, it’s all an illusion: as we have briefly talked about previously, Akka’s dispatchers make sure that messages – Read More