Hey there!
currently looking into event sourcing.
I stumbled over commanded and it looks pretty neat. Followed the documentation and set the example bank account commands/events.
Now I am at a step where I would like to transfer what I learned but I am certainly missing some understanding.
What I want to store and track are some documents (files on disk) and a graph with their relations. That means, at some point, I actually have to write the files and adjust the graph. But I do not get where or how I would do that in a way that things are not run repeatedly but are still replayable.
As an example, a document should have an owner, which is stored as an edge/connection in the graph. I do not know how/when/where I should create this edge.
Example 1: Create relation in execute
- Dispatch command
AssignOwner
- execute:
- Check if owner can be assigned, the document exists etc.
- Update the Graph by adding the relation
- Generate Event
OwnerAssigned
Now … lets say I’d like to debug something locally that happened on the server, I would download the events and … the relation in the graph would be missing, because the event OwnerAssigned
does not create it and the command AssignOwner
is no longer present.
Example 2: Create relation in apply
- Dispatch command
AssignOwner
- execute:
- Check if owner can be assigned, the document exists etc.
- Generate Event
OwnerAssigned
- In
apply
create the edge in the graph
I guess now, every time the events are aggregated, the edge would be created?
Example 3: Create additional commands from event
- Dispatch command
AssignOwner
- execute:
- Check if owner can be assigned, the document exists etc.
- Generate Event
OwnerAssigned
- React to event
OwnerAssigned
and trigger additional commands that alter the graph.
How would this differ from Example 2?