larshei

larshei

Event Sourcing with commanded: How to handle side effects?

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

  1. Dispatch command AssignOwner
  2. execute:
    1. Check if owner can be assigned, the document exists etc.
    2. Update the Graph by adding the relation
    3. 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

  1. Dispatch command AssignOwner
  2. execute:
    1. Check if owner can be assigned, the document exists etc.
    2. Generate Event OwnerAssigned
  3. 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

  1. Dispatch command AssignOwner
  2. execute:
    1. Check if owner can be assigned, the document exists etc.
    2. Generate Event OwnerAssigned
  3. React to event OwnerAssigned and trigger additional commands that alter the graph.

How would this differ from Example 2?

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement