Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persisting Akka state in case of a crash

I am a beginner with Akka, and I enjoy many of the functionalities it provides for asynchronous programming, such as Actors, Agents or Futures.

A strong selling point of Akka is the fact that when an actor crashes, an equivalent actor is created anew by the actor system and plugged in place of the old one, guaranteeing strong stability.

Some other systems (I am told JMS is one) go one step further and persist the messages sent between actors continously. This way, if the machine crashes physically - say because of a hardware failure - it is still possible to restore the state as it was before the fault.

This is very appealing for the application I am developing right now. Does Akka provide any such mechanism? If not, is there some way to integrate it with an external system in such a way that this can be achieved?

like image 928
Andrea Avatar asked Dec 07 '22 11:12

Andrea


2 Answers

Yes, what you describe can be achieved by using durable mailboxes, they can be configured as needed on a per-actor basis.

There are several implementations for different back-ends out there, and if you do not find one for your favorite message queue then it will not to very difficult to implement your own adapter. The only implementation which we will maintain within the Akka source tree is the FileBasedMailbox, serving as template of how to do it. The other mailbox types which were in the Akka 2.0.x distribution are maintained as community projects by their respective “owners”.

like image 72
Roland Kuhn Avatar answered Dec 23 '22 01:12

Roland Kuhn


Durable mailboxes are a good way to selectively save messages, so that Akka can achieve similar things like JMS. Besides the technology it is very important to consider on an architecture level what messages are relevant to your system and how should the state be restored after a system failure.

One way, which plays nicely together with a actor paradigm is event sourcing. In this concept the state of your application is stored as a series of events rather than the state itself. When a system or part of it fails, the state can be restored by applying all events from a persistent event store. A durable mailbox could be a link to such an event store or a dedicated actor would be used directly.

Martin Krasser has a very nice article on this blog describing this approach using a Akka. He is also the author of a event sourcing extension to Akka with the name eventsourced.

like image 36
opeth Avatar answered Dec 23 '22 01:12

opeth