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

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
clayschick
I'm trying to create a simple query to select distinct values from a column. If I only use select and distinct I get back a list of uniqu...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
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
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement