While it's not unreasonable to structure the Actor hierarchy like this, I suspect it's not actually what you want. It is specifically likely to make it a hassle to look up Users just by their UserID.
Rather, I would recommend researching Akka Clustering Sharding. That's very likely the right way for you to manage your User Actors, because it is designed precisely for the case where you want to be able to look up (and create, when necessary) an Actor of a particular type given an ID. Storing data in the UserActor makes good sense, especially if you pair this with Akka Persistence -- that's often the easiest way to set things up. In all likelihood, you should have a separate Clustering Sharding Region for Countries as well, if they have their own data. A Country might well contain a list of Region IDs, even if those Regions aren't actually Actors. As for Regions, I'm not sure -- you might want to think about whether Regions are anything more than an identifier that is used as a handle for subscribing and broadcasting events. That is, instead of "look up all the actors by Region", you might want to instead ask "how do I *broadcast* to all Users in a Region?", which might be an easier problem to solve. I wouldn't bother making Regions an Actor type unto themselves unless there was some per-Region state you were managing. On Sat, May 13, 2017 at 6:00 PM, Christian Hessenbruch <[email protected]> wrote: > This is a couple of very basic questions concerning akka. I'm totally > green on akka, so any advice is appreciated. > > > Say that I have an application with thousands of users - not millions. > > > The domain model is a hierarchy where each user is located in a region > within a country i.e. a country has multiply regions, a region has multiple > users. > > > I'm thinking of creating the exact same hierarchy in akka. CountryActor > ->* RegionActor ->* UserActor. The CountryActor could aside from being > parent, also have functional duties such as collecting newsfeeds, > calculating statistics, supervising its children etc. Whereas the > RegionActor is only a parent of UserActors. > > > *Q1: Does it make sense to mimic the domain model this way?* > > > *Q2: Should I store the attributes of each entity in the actor?* This way > the data would only need to be stored once and the akka system would > effectively be memory database as well. > > > (pseudo-code) > > CountryActor { > Name, > CountryCode, > (children = list of RegionActors handled by akka) > } > > RegionActor { > Name, > RegionCode, > (children = list of UserActors handled by akka) > } > > UserActor { > UserId, > Firstname, > Lastname, > Alias, > ReceiveRegionalNews, > ReceiveCountryNews, > ... > } > > > *Q3: How do I efficiently lookup a user by userId?* I expect the > child-name of the UserActor will be the userId, but given that I only have > a userId, I still need to find that correct Country and Region to do a > getContent().findChild(userId)? Do I need to keep a complete map of all > userIds and reference to their actor? > > > *Q4: How to locate actors by their state?* Imagine that each user has the > ability to switch on a RegionalNews attribute, which means that he wants to > receive news from the RegionalActor. Whenever the RegionalActor want to > distribute news to all listeners, how does it locate them? Does it keep an > internal map of the users with the attribute or does it make a broadcast to > all it's children and then send to all responders? > > > Thanks in advance > > -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ > >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/ > current/additional/faq.html > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > --- > You received this message because you are subscribed to the Google Groups > "Akka User List" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. > -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
