i’ve got a question about managing data integrity for public events in lagom.
My case is an entity whereas its instances can be arranged in a tree. Each entity holds only the entityId of its parent as Optional. If an entity is moved e.g. 2 times successively, 2 instances of PEntityMovedEvent will get created. If i want to send the absolute path in the PUBLIC event i have to query the write-side (or a read side) to get the path. Therefore the outcome of this resolve process is timing dependent. If i’m lucky and the event processing is fast enough, the path is correct. If its after the 2nd modification, the absolute path will be the current one… depending on the layout of the public event, i may emit the same event two times or worse, the data of the event could be inconsistent.
What are the possibilies for the developer to solve this?
a.) “Pollute” the persistent event with data of the state which are required for the public event. (Pollute because this data is not required to recreate the entity state internally). In my case this would be the new absolute path.
b.) Implement some sort of synchronization mechanism. E.g. do not allow certain entity updates until this processor has processed the emitted event. Could be done by returning e.g. a uuid as a transaction identifier which is also in the persistent-event. In my case this is very tricky. The lock would have to affect not only the entity itself but also all entities in the absolute path.
Is this “the way to go” or are there better solutions?
PS: This is also done in the online auction example:
What if the state of the action is different from the state when the auction was created? We always emit the “current” state here.