PersistentEntity != Actor?

Hi all,

I understand that PersistentEntity does not directly correspond to the Akka’s actor. However, am I correct to say that “an instance of PersistentEntity ends up becoming an instance of PersistentActor”?

So for example, if I initialize 100 instances of CustomerEntity in my Lagom project, will there be 100 persistent actors created inside Actor systems, each of them corresponds to exactly one customer entity instance.

It would be great if Lightbend can explain this in a bit more details, I’ve been asked many times about this relationship.

Thanks,

Joo

Hey there,

You are correct. The PersistentEntity actor extends the PersistentActor.

Spot on.

They do so already in the PersistentEntity’s Underlying Implementation documentation. The more curious folk, who would like to understand the nitty-gritty details, can also take a look at the source code hosted on GitHub.

Hope this helps.

1 Like

I (from Lightbend) can confirm that this is correct. The PersistentEntity is run/driven by a PersistentActor.

1 Like

@patriknw and @chmodas thanks for the replies!

One more question…
But technically speaking, when you look inside the PersistentEntity, it itself is an abstract class and PersistentEntity does not seem to be extending from the PersistentActor trait / abstract class in the code.

So how is it technically correct to say “PersistentEntity extends from PersistentActor”? Or the answer is rather a conceptual explanation?

abstract class PersistentEntity {

  type Command
  type Event
  type State
}

It’s via composition instead of extension. “PersistentEntity extends from PersistentActor” is technically incorrect. “A PersistentEntity is run by a PersistentActor” would be better.

2 Likes