Giter VIP home page Giter VIP logo

Comments (5)

octonato avatar octonato commented on May 28, 2024

I don't get your point.

Events are applied after persisting and internal state is only update after that.

Replay only happens when aggregate is re-instantiated in which case they are not applied twice because whether we come from 0 or from a snapshot. There is no replay happening on a previous state that stays in-memory.

from fun-cqrs.

pjan avatar pjan commented on May 28, 2024

Please correct me if I'm wrong, but this is how I understand it:

  1. AggregateActor receives a Command
  2. The applyCommand of the behaviour/interpreter gets called. This executes asynchronously (future)
  3. Upon success of the future, you have both the resulting events and updated AggregateState, which you send to yourself in a Successful
  4. You receive the Successful, persist the events, and update your state to that updated AggregateState upon a successful persist

Now you want to protect against the events being applied multiple times (not the same as protecting against the same events happening because you received the command twice). This can only happen (very unlikely though) if the Successful you send in 3. arrives twice in 4.

What happens in your code is, you save the events first, and keep the state of that Successful message. If this message happens 2 times, the state will indeed be correct (events only applied once). However, your events are persisted twice. If you now replay the events when "waking up" the Aggregate, the events will be applied twice to the state.

If you want to avoid this, you have to make sure the events aren't persisted either, and have idempotent semantics in your Successful.

from fun-cqrs.

octonato avatar octonato commented on May 28, 2024

But under which circumstances can the Successful message arrive twice in 4?

from fun-cqrs.

pjan avatar pjan commented on May 28, 2024

This is impossible, but I understood this was what you were trying to protect against. Most likely my mistake, and misread / misunderstood. Can close. Apologies.

from fun-cqrs.

octonato avatar octonato commented on May 28, 2024

My intention was to prevent other commands to be processed while we are still persisting the events. Classical become/unbecome thing.

I'm closing this one.

from fun-cqrs.

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.