vin
vin

Reputation: 1019

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:

Upvotes: 0

Views: 540

Answers (2)

erip
erip

Reputation: 16935

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.

Upvotes: 2

Rafał Sobota
Rafał Sobota

Reputation: 1468

  1. Persisted entity is removed from memory after configurable time of inactivity.
  2. Persisted entity is loaded again to memory by reading recent snapshot and every event after it.
  3. Command can be verified by comparing to persistent entity state which is built from event log (source of truth). You can store products in internal state and know when product is added again. Then you can reject this command by not emitting events and returning error.

Upvotes: 1

Related Questions