Giter Site home page Giter Site logo

Comments (1)

nanov avatar nanov commented on June 11, 2024

Hi!

Well you have a few options here, the one i would choose is not to implement the sequencer as an aggregate. There is one question that needs to be asked here:

  • Do you really need to 'undo' the number generation? Maybe having just ascending numbers ( who maybe not be always +1 ) works for you?

If so there are many ways to achieve this fairly cleanly, one idea that pops into mind is to use the aggregateId generation functionality ( async ) and then generate ids out of somewhere ( a mongo / redis collection and using the $inc operator will do for example ).

If having a following sequence number is a hard requirement and you, you could design a service with locks to generate those ids for you, or if you would like to do it with aggregates, i would implement something as following:

Two aggregates -> sequencer and ticket - as you have done.

For creating a ticket ( ie assigning a number ) you should do something as following :

command to sequencer -> CreateTicket -> increment seq ( event ) -> businessRule -> fire somehow a create command on the ticket aggregate with the sequence inside and wait for the result ( ie successful or not / created event whatever ) -> if the result is successful than the business rule is fine, otherwise reject the command.

Some things to have in mind:

  • Ticket aggregate can be created only from the sequencer one.
  • The sequence aggregate will be locked until the ticket is created successfully.
  • This creates a bottleneck on the ticket creation part.

Bear in mind that event with auto-incremented field in sql you don't get grantees that numbers will be always following, if a transaction is rolled back some numbers may be skipped.

from node-cqrs-domain.

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.