1

I was reading Akka Persistance documentation and it says that Akka is good for Event Sourcing.

Imagine I have a User entity. Each user is defined uniquely with ID and has some properties and some business rules around how they can be altered. Also, some modifications of User properties can have some async side effects, like notifying another system that a User has been created. Very basic DDD setup.

So from what I understand Akka PersistenceActor is good for keeping the current state of the User, accepting modifications 1 by 1, so nothing can slip inbeetween.

So if I model these users with PersistenceActors where I create an actor per user, but the number of users is way too big to keep them all (or even load them all) into the memory, how do I deal with creating/stopping actors, their persistence/etc..

It seems like quite a complicated task to bear manage. But if I do not do that, what else can PersisteceActors be good for?

2

You want to look at Akka Cluster Sharding. This complements Akka Persistence to distribute the instances that are currently kept in memory in the cluster and manage their lifecycle.

Also keep in mind that Akka is - by design - a rather low-level toolkit. For an easier getting started experience with event sourcing and cqrs based on Akka, you might want to look at higher-level framework, like Lagom Persistence (Java & Scala) or Fun.CQRS (Scala).

2

I think you may want to read about Passivation.

An entity actor is loaded (recovered) when you send a message to it, and can passivate itself when it receives timeout. Using passivation, you can avoid having all users loaded in memory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.