Anand
Anand

Reputation: 551

When to use AKKA persistent actor

Can someone please explain me, when should/must we use persistent actor? What are the benefits and what problem does it solve (that normal actors cant solve)?

Upvotes: 0

Views: 351

Answers (1)

Al Iacovella
Al Iacovella

Reputation: 456

A persistent actor has the ability to restore it's state after it is re-initialized. It reads journaled entries based on a persistent id which you assign. When an actor with the same persistent id re-initializes, it restores its internal state based on those journaled updates. For example, you have an actor that represents an entity such as a User. You send messages to the actor to update various aspects of that user. Sometime after those updates have been applied, the actor is terminated or passivated. At some later point, the actor is re-initialized with the same persistent id. The previously journaled updates are then applied and the actor's internal state is exactly as it was when it shut down. In general you would use it when you'd like the actor to restore to it's previous state. One use case would be if you had a supervised actor where the supervisory strategy is configured to restart the actor upon failure. After a failure occurs in this case, the actor shuts down, is then restarted and all of the journaled updates are applied. In the end the actor is in the same state as it was prior to the failure.

Upvotes: 2

Related Questions