A side effect is an externally observable operation performed alongside persistent-state updates. Typical examples include posting to an HTTP server or inserting a database record. In an Akka persistent actor, the command handler adds side effects to an effect such as persist with thenRun. section 9.2.1
Use side effects carefully around event persistence:
- Run the callback after the event has been successfully persisted; callbacks appended to persist execute in order. section 9.2.3
- Keep side effects out of the event handler. Recovery replays saved events through that handler, which would replay the side effects as well. section 9.2.1
- Do not place persist after another effect when the earlier effect assumes persistence succeeded; a persistence failure could make the notification or operation false. section 9.2.3
Adding a side effect to persistence
A container command can produce Effect.persist([CargoAdded]).thenRun(callback). The callback can notify another actor or perform another external operation after the cargo event is saved. Use thenReply when the intended reaction is specifically a reply, and thenStop when the actor should stop after handling the command. section 9.2.3























