Scala Italy 2015 Highlights

A few days ago I had the opportunity of attending and speaking at Scala Italy 2015, hosted in Milan. Scala Italy is the only Italian Conference on Scala: they aim to spread the use of Scala in the Italian Developers Community and to contribute to the Scala Community.

The conference was hosted by UniCredit and DataBiz in the beautiful skyscraper of the UniCredit Town Hall and it was divided into the morning and afternoon sessions.

The first talk of the morning session was given by Martin Odersky (@odersky) on the evolution of Scala: where it started and where they would like it to be in the near future (video). My favourite part was when he said that Scala is a library-driven language: it provides the tools for people to create libraries rather than imposing them “because we trust developers” ….how cool is that? 😀 Another unforgettable moment was when he showed a slide with the sentence “Scala is a gateway drug to Haskell” and an awesome proposal for a new name for Scala: HASCALATOR.

The second talk was by Phil Calcado (@pcalcado), Director of Core Engineering at SoundCloud (video). He talked about the design and architecture of their microservice system and how they managed to apply principles of functional programming to them. It was a truly inspirational talk, I was so excited about it that I was about to send a message to my CTO during the talk itself to tell him that we should ABSOLUTELY do the same! Also, he stated that functional principles correlate with good design and good architecture. I agree with Phil, we should explore this concept a lot more than what we have done so far.

Last but not least for the morning session, Jon Pretty (@propensive) gave a talk on the Type Inference in Scala (video). His talk was giving the audience a demonstration on how mysterious and complex this topic can be, but also on how some of these problems can be overcome. I do remember my “Holy Crap!” exclamation when he showed us an inferred type a few pages long.

After a nice and chatty lunch break, the afternoon session started…together with the panic for my talk.

My talk was the first talk of the afternoon session. I gave an introduction to Akka and the Actor-Based Model (video). Yes, I did say that “Actors are like monkeys sending emails”. No, I don’t regret it. Also, I showed how you can interact with the Actor System using their four core operations (i.e.: create, send, become, supervise) and talked a bit about best design practices.
Overall, I think it went quite well: I didn’t trip over or stab myself with a pen, I didn’t spill water all over myself or the microphone, no people snoring (at least that I could hear/see) or throwing rotten tomatoes at me. I have also received a couple of interesting questions around the interdependencies between Actors. If interested, the slides on my talk are available here, while the video can be found here.

At the same time of my talk, Mirco Dotta (@mircodotta), Software Engineer at Typesafe, was talking about Reactive Streams (video). I cannot wait to see his talk! Reactive Streams has been in my “TO-PLAY-WITH” list for a while now…

Finally, the last talk I’d like to mention was the one by Alessandro Abbruzzetti from Ericson (video). His talk was so overwhelming and entertaining that there was a Standing Ovation at the end of it: he built a Commodore 64 emulator in Scala that runs on the same hardware resources of an original Commodore 64 — he even analysed the Circuit Diagram!
Why on earth would you do that? If Scala is so performant as they claim, then if it runs on an equivalent hardware of a Commodore 64, the overall result should be more performant than the original one we had in the 80s.
He took him 1 year and a half of his spare time but he did it….and the result is simply amazing. Can you imagine doing crazy cool graphics, processing and I/O with only one thread?? He proved it can be done. THIS IS THE COOLEST THING EVER! 😀
During the talk you could see all his passion and happiness, all his hard work dedicated to this crazy project. Every few minutes or so he was reminding us, just to make sure we didn’t forget: “Remember…one thread…just one thread…”. His project, called Kernal64, is available on GitHub at abbruzze/kernal64.

Finally, I’d like to mention the great work that the organizers of this conference did, in particular Marco Firrincelli (@mfirry) that took good care of me and made sure I made it to the event without getting lost in the middle of nowhere in Milan….well done guys! 🙂

All the videos of this conference can be found here.

Akka Dead Letters Channel

Akka doesn’t guarantee the delivery of a message. What happens when a message cannot be delivered? In this article we will describe how the Dead Letters Channel works and how it can be used to spot issues in our system.

How it works

In a previous article we have described the use of Event Streams in Akka. The Dead Letter Channel is nothing more that a special Event Stream that the system uses internally every time a message cannot be delivered: either because the message cannot be processed or delivered.

When Akka is redirecting the failed message to the Dead Letter actor, it wraps the message in a case class called Dead Letter to provide the message, the original sender and recipient:

case class DeadLetter(message: Any, sender: ActorRef, recipient: ActorRef)

Unless specified differently, dead letters are logged in the INFO level: more information on how to tweak your logging settings can be found here.

How to use it

Because the Dead Letter Channel is an Event Stream, we can subscribe to it and listen to all the messages it publishes.

The code used for this tutorial is available here.

First of all, let’s create a dummy actor, called EchoActor, that prints all the messages it receives:

class EchoActor extends Actor {
  def receive = {
    case msg => println(s"New msg received: $msg")

The second step is to create our actor system: we will have two instance of EchoActor, one called deadLettersSubscriber that will listen for DeadLetters and the other, called echoActor, that will simply wait and receive messages.

  implicit val system = ActorSystem("dead-letters-usage-example")

  val deadLettersSubscriber = system.actorOf(Props[EchoActor], name = "dead-letters-subscriber")
  val echoActor = system.actorOf(Props[EchoActor], name = "generic-echo-actor")

  system.eventStream.subscribe(deadLettersSubscriber, classOf[DeadLetter])

When successfully sending a message, no dead letter is generated.

  echoActor ! "First Message"
  // generic-echo-actor - New msg received: First Message

However, when we try to send a message to an actor that has been killed, the message is successfully transformed into a DeadLetter.

  echoActor ! PoisonPill
  echoActor ! "Second Message"
  // dead-letters-subscriber - New msg received: DeadLetter(Second Message,Actor[akka://dead-letters-usage-example/deadLetters],Actor[akka://dead-letters-usage-example/user/generic-echo-actor#317003256])
  // INFO  [RepointableActorRef]: Message [java.lang.String] from Actor[akka://dead-letters-usage-example/deadLetters] to Actor[akka://dead-letters-usage-example/user/generic-echo-actor#317003256] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

Finally, we can also send messages directly to the Dead Letter Actor: this is usually not advised as the Dead Letter Channel should be reserved for the system to redirect failed messages.

  system.deadLetters ! "Dead Message"
  // dead-letters-subscriber - New msg received: DeadLetter(Dead Message,Actor[akka://dead-letters-usage-example/deadLetters],Actor[akka://dead-letters-usage-example/deadLetters])
  // INFO  [DeadLetterActorRef]: Message [java.lang.String] from Actor[akka://dead-letters-usage-example/deadLetters] to Actor[akka://dead-letters-usage-example/deadLetters] was not delivered. [2] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.


Akka redirects all the messages that couldn’t be delivered or process to the Dead Letter Channel. In this article we have discussed how Akka uses it and how we can exploit it when testing our system and investigating issues with our system.