Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I structure Persistence Actors in Akka persistence?

How should I structure my Actors in Akka persistent (Eventsourcing/CQRS) ?

  • Hierarchical
  • Parallel

I have these domain objects in my ecommerce application

  • User - User can create account
  • Store - User can create store
  • Product - User can add products to it's store
  • Cart - A User can add any product from other User's stores into the Cart.

So my question is how should I structure my Actors ? What are advantages and disadvantages of choosing one over the other specially in relation to an Ecommerce domain model ?

akka actor structure

like image 868
user794783 Avatar asked Oct 19 '22 21:10

user794783


1 Answers

I think your question is more about the boundaries of your aggregates.

In any case, there should be NO hierarchical structure between aggregates. Aggregates should be independent from each other. No parent child relationship.

According to your description. There is a User Aggregate that can create stores and add products to it.

Store could be an apart aggregate that is initiated by the User aggregate. Note that the fact that an user can create a Store doesn't mean that they should have a parent/child relationship. It's more about access control. A Store is created by a user and only this user have right to add products to it.

However, Product seems to be a entity inside the Store aggregate.

Your fourth example, "Cart - A User can add any product from other User's stores into the Cart", reveals something totally different. You have two kind of users. Users that create and manage stores and consumers of a given store. They are not the same and they should be modeled differently.

Try to model the domain of your business without trying to reuse objects just because they are similar.

like image 196
Renato Avatar answered Oct 31 '22 21:10

Renato