Blokh

Blokh

Event sourcing in Elixir - Without CQRS

Greetings,

I’ve been looking around for a good Event-Sourcing sample project in Elixir but all I could find is the great job of Ben Smin (@slashdotdash).
Which is really great but I do not believe in CQRS complexity for a simple project.

Does anyone have any suggestions where I could study more about Event sourcing in elixir without slicing apart my read and write interfaces?

Thanks in advance,
Blokh

Marked As Solved

slashdotdash

slashdotdash

You can use Commanded for event sourcing without requiring CQRS. Commanded focuses on the write model, but provides the Ecto projections library as one way of projecting events into a SQL database. There’s an undocumented function to access aggregate state (Commanded.Aggregates.Aggregate.aggregate_state/3) which would allow you to use Commanded with a single model for writing and to later query the state of the aggregate.

The reason why this isn’t the preferred approach (IMO) is because although the query model initially closely resembles the write model, soon they will start to differ in structure or access pattern (e.g. reporting, aggregating data and multi-entity views). Hence why I opt to go with separating reads from writes from the outset (CQRS) when using event sourcing.

Also Liked

LostKobrakai

LostKobrakai

It’s not really ready yet (a few upcoming changes in the pipeline), but https://github.com/CargoSense/fable is a great intermediate between not doing es and going all in with commanded.

kokolegorille

kokolegorille

You might like

I am not sure it is a requirement to have multiple database, isn’t it just a separation of concern between read and write?!

peerreynders

peerreynders

Event Sourcing

  • Every software developer who has used version control has interacted with an Event Sourcing system.
  • If you need to explain Event Sourcing to the business, use accounting ledgers.
benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Event sourcing is more than just writing to a table called events. The “sourcing” bit of event sourcing means that you are driving state exclusively off of the event log. Your example here simply writes an event alongside the normal table insert, it doesn’t drive the table insert off of the event. To do this properly you also need order guarantees: that each event is processed in order to other events.

bottlenecked

bottlenecked

Hi there, the problem that cqrs tries to solve is that because of the way data is written in the event store it’s very difficult and/or inefficient to do aggregate queries against that data.

For example lets say your domain is banking accounts, and each event represents a transaction in some customer’s account. Without a separate read model optimized for queries it would be really difficult to get stats like “give the top ten accounts that have made a deposit over x amount last month”

So unless you never read that data outside your main application (eg no admin screens presenting aggregate info over your data), you’re probably going to need a separate read model- and that means buying fully into es+cqrs

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
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
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

Other popular topics Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
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
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
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
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement