Multiple guardians per aggregate? (Akka Persistence)

Hello!

We are using Akka Persistence (with CQRS) and we currently have one Aggregate in the system. We want to add another Aggregate, but I couldn’t find any documentation anywhere about this.

Should we create two guardians, one for Aggregate A and one for Aggregate B? Then our seed nodes would be something like:

    seed-nodes = [
      "akka://AggregateA@localhost:2551",
      "akka://AggregateB@localhost:2552"
    ]
  public static void main(String[] args) {
      ActorSystem.create(Guardian.create(), "AggregateA", config());
      ActorSystem.create(Guardian.create(), "AggregateB", config());
  }

Or is it better practice to have one guardian actor,, say “MasterAggregate” and then branch off AggregateA and AggregateB from that guardian actor?

Hi @agapic

You should only create one ActorSystem and have a top level behavior that creates both of your aggregates.

An ActorSystem is quite expensive, thread pools etc, so you typically have one per app.

1 Like