akkaactorlagom

Are Lagom Persistent Entities Actors? / Actor Models


I am using Lagom's persitent entity, and read side Cassandra support to implement, save the sate for read side queries. So trying to understand, are the persistent entities also actors? meaning only one event / command will be handled at a time ? Are events also messages the "persistent entity" handles? I could not find much documentation regarding the following:


Solution

  • Are the persistent entities also actors? Meaning only one event / command will be handled at a time ?

    I would not ask the question this way; actors do perform synchronous message handling, but that something performs synchronous message handling does not imply that it is an actor.

    Now that the semantics are out of the way, we can address the question... PersistentEntitys are technically not actors... However, PersistentEntityRegistrys will create something that is a PersistentActor.

    • is every entity persisted in memory once created?

    Entities are persisted in whichever store you use according to that Akka persistence snapshotting (see here) mechanism.

    • If we go by a model in which the actor is removed after some timeout... Will the actor have to read all events again to handle another request?

    Again, snapshotting will help considerably.

    • If adding items to cart is handled by commands / queries how is it ensured that the same item is not added onto the cart twice?

    You can read more about delivery semantics of Akka actors here.