rrevanth

rrevanth

Discussion about event driven Elixir apps - CQRS/ES using Phoenix

I recently came accross this pattern where he created event driven elixir app.

I am planning a personal project and stuck on the pattern to adopt. Want some opinions on CQRS/ES pattern.

It seems awesome but wanted opinion from you guys :slight_smile:

Most Liked

karmajunkie

karmajunkie

There’s quite a lot to read and learn about if you’re going to take on these patterns (plural because they are distinct from one another, despite being used together most of the time). I would suggest that you move cautiously in your first couple of attempts to apply them and learn some lessons in an application you’re ok with rewriting once or twice until you get the hang of it.

On ES: If you are comfortable with how GenServers work, you are 90% of the way toward grasping the mechanics of this architectural pattern. Imagine that while receiving messages as a GenServer you persist them before applying them—this is the essence of ES. To be sure, its somewhat of an oversimplification—for example, if you decide that your messages need to change format or payload in some way, its a simple matter to update the sender and receiver, while with ES your “receiver” (aka projection in ES parlance) will have to live with those messages for potentially long periods of time. So modelling your domain events correctly becomes far more important, as does understanding the notion of a boundary and what it means to have coupled code. If you get this part badly wrong, you’re going to have some long-lived headaches. On the upside, however, you also will find that having stored the events you are now free to have as many representations of your data as you need, and that you can generate them retrospectively quite easily (provided you captured the data in the first place.)

On CQRS: I have to confess I’m of the opinion that this one doesn’t make a lot of sense in Elixir. CQRS was meant as a stepping stone towards ES (a decidedly functional data pattern) for object-oriented developers and code. Thus, there is a lot of emphasis placed on terminology like “aggregate root” which is no different from any other state you would build up in a GenServer. So I think that CQRS can actually be counterproductive in that it adds additional conceptual layers on top of things that Elixir already does very well natively, which is confusing for newcomers as well as developers experienced in using CQRS from other platforms. Command messages as an artifact of code are needed in most OO languages because (Smalltalk notwithstanding) they don’t tend to model messaging as a first-class notion; command handlers are similarly modelled very easily with pattern matching and process registries.

On frameworks: There are a few I’m aware of in Elixir-land, with @slashdotdash’s work being the furthest along, at least as far as I am aware. I think if you are going to implement these patterns and you want to use a framework, they are a good choice with an API that makes sense most of the time. However, as noted above, I think Elixir/OTP gives you the tools already to implement these patterns out of the box, with the exception perhaps of a robust eventstore (which has additional requirements beyond simply being a database of events). I would consider carefully whether the additional dependencies are worth the cost.

Getting help/learning more: There are not a lot of high quality books on applying ES in particular that I’ve found useful, and the ones that look most interesting to me are generally either aimed at Akka, .Net, or using Kafka. One book I think every developer ought to have on principle here is Enterprise Integration Patterns, which is basically a book on messaging patterns. The other somewhat required reading is the DDD “Blue Book”. You don’t HAVE to use DDD with event sourcing, but most people I think find understanding some of the essential notions to be invaluable in determining stream boundaries. Especially given that Phoenix appears to be trending in this direction, its worthwhile reading anyway.

The DDD/CQRS google group is good to read and lurk in, and the community there is generally helpful. We also have a slack channel dedicated to eventsourcing on the elixir slack, and there is a whole slack dedicated to it as well with many of the folks from the google group active on it.

Good luck with your explorations on this!

slashdotdash

slashdotdash

@rrevanth I gave a talk to a local user group on Thursday evening covering this topic. Unfortunately it wasn’t recorded, but I’ve published the slides online.

You might find them useful too. Let me know if you have any questions.

peerreynders

peerreynders

The puzzling thing is that you identify the pattern but not the project - which is basically is like asking whether a particular answer is appropriate for some unknown question. So is the true objective your personal project or finding a project to learn more about CQRS/ES?

When it comes to CQRS/ES I like to stick close to the source. Martin Fowler’s CQRS:

Greg Young was the first person I heard talking about this approach - this is the summary from him that I like best.

So for example Greg Young - CQRS and Event Sourcing - Code on the Beach 2014 and Greg Young - A Decade of DDD, CQRS, Event Sourcing (and for good measure Greg Young - The art of destroying software).

Bryan Hunter - CQRS with Erlang (github) could also be of interest.

Where Next?

Popular in Discussions Top

PragTob
Hello everyone, I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
New
thojanssens1
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.: redirect "/", UserController, ...
New
pillaiindu
In django there is a cache framework backed by memcached. Rails also puts a lot of emphasis on caching, and even the idea of russian-doll...
New
Qqwy
Looking at the stacks that existing large companies have used, WhatsApp internally uses Mnesia to store the messages, while Discord uses ...
New
WildYorkies
It seems that the more I read, the more I find Elixir users speaking about all the ways that Elixir is not good for x, y, and z use cases...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
AstonJ
I’ve just started the Phoenix part of the utterly brilliant online course by @pragdave. On generating the Phoenix app he uses the --no-ec...
New
paulanthonywilson
I like Umbrella projects and pretty much always use them for personal Elixir stuff, especially Nerves things. But I don’t think this is ...
New

Other popular topics Top

New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
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
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
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
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
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

We're in Beta

About us Mission Statement