Giter Site home page Giter Site logo

Routing using GenEvent about commanded HOT 6 CLOSED

commanded avatar commanded commented on April 29, 2024
Routing using GenEvent

from commanded.

Comments (6)

slashdotdash avatar slashdotdash commented on April 29, 2024

GenEvent was not suitable for a few reasons.

  1. For command dispatching in CQRS there must be exactly one registered handler for each command. Not having a handler, or more than one, configured is an error. This is enforced by the Commanded Router macro.
  2. GenEvent doesn't guarantee delivery of events. If a subscriber process goes down, it will miss any events published until it restarts. This is the main reason that it is unsuitable.
  3. All GenEvent handlers run in a single process.

In comparison, each Commanded event handler has its own subscription to the event store. It acknowledges every event it receives and successfully processes. This allows it to resume in the event of a process crash, or catch up if it is lagging behind. It also allows new subscribers to be added and they can receive every event published from the event stream origin. Event handlers run concurrently and are independently supervised. So a problem with one does not affect any other.

from commanded.

henry-hz avatar henry-hz commented on April 29, 2024

Got it, it's an elegant design 💯

For the reason 1, it's okay, the developer can pay attention if the system is small, and if the system is too big, a consistency test tool can track commands, events and errors, and alert if they are inconsistent with the CQRS rules, or if some command was lost and no event or feedback was emitted. For the reason 2 and 3, seems that GenStage comes to solve them: http://elixir-lang.org/blog/2016/07/14/announcing-genstage/ . Please, let me know if makes sense.

from commanded.

slashdotdash avatar slashdotdash commented on April 29, 2024

GenStage could be useful for event handling. I've taken a look at it before. Its approach to broadcast is to wait for every subscriber. This may not be appropriate if you have independent event handlers that you don't want to be blocked by the slowest handler. Back pressure has already been implemented for Commanded's event handlers.

from commanded.

Papipo avatar Papipo commented on April 29, 2024

I think that GenStage producers can provide input for any consumer that requests demand.
Besides, there is an experimental PartitionDispatcher which makes a lot of sense for event sourcing.

from commanded.

Papipo avatar Papipo commented on April 29, 2024

For the record, I have read at least a couple of articles advising against using gen_event.

from commanded.

henry-hz avatar henry-hz commented on April 29, 2024

Yep, also read, seems we should avoid it.

from commanded.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.