I am designing a backend using CQRS + Event sourcing, using Akka + Scala. I am not sure about how to handle a growing state. For instance, I will have a growing list of users. To my understanding, each user will be created following a UserCreated event, such events will be replayed by the PersistentActor, and the users will be stored in a collection. Something like:
class UsersActor extends PersistentActor {
override def persistenceId = ....
private case class UsersState(users: List[User])
private var state = UsersState()
....
}
Obviously such state would eventually grow too big to be held in memory by this actor, so I guess I'm doing something wrong.
I found this example project: the idea seems that each user should be held by a different actor, and loaded (from the event history) as needed.
What is the right way to do this? Thanks a lot.