rrevanth

rrevanth

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:

First 7 of 7 Posts Switch mode

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.

slashdotdash

slashdotdash

Implementing Domain-Driven Design by Vaughn Vernon is a good book for the practical application of CQRS when building an app. All the source code and examples are in Java, but don’t let that put you off too much.

rrevanth

rrevanth OP

Thank you for this. I had some hard time wrapping my head around the pattern from that!

This gives me some head start. :smiley:

rrevanth

rrevanth OP

Awesome. Thank you!

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.

rrevanth

rrevanth OP

Sorry. I did not phrase my sentences correctly. I wanted to know more about the pattern as it seemed interesting while reading through it .

So, I thought of doing a small project with the pattern but wanted to get some insights about it prior.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement