Code Monkey home page Code Monkey logo

Comments (5)

holinov avatar holinov commented on June 30, 2024

I do it by intent. Idea is that aggregate could be restored to actual state reading event log. In my case
If i persit data and smth happens i have 2 options
1 - data is not written. i got failure and do not reduce state (thus not damaging buisness-data and not starting any effects)
2 - data is writen and i have error in aggregation function. even if it fails (saying it's not bug in aggregation logic but within infrastructure) next time i read evelt log i restore to consistent state
but if i switch to "effect-first" - i easy get to situation when aggregation was reduced (and launched long-running effects) but no data was added to datastore

from zio-event-sourcing.

heksesang avatar heksesang commented on June 30, 2024

As it is, if you call persist for events which are not valid according to the reducer, it will first persist the event to the event journal, then it will try to modify the aggregate, and then update the ref with the new aggregate if it was a success. But at this point you have stored the events in the journal, even though they were not valid.

However, if you first had reduced the event it would fail and no event would be persisted.

What you are doing now is persist -> reduce -> update ref, but if you switch it around you would have reduce -> persist -> update ref. The latter would mean no incorrectly persisted events.

from zio-event-sourcing.

holinov avatar holinov commented on June 30, 2024

i see your idea but filtering must happen on read side. all incoming data should be saved. but when reducing you could skip any "unwanted" data you want.
in EventSourcing you could have more than one aggregate build using same event log and different aggregates could count different events as "unwanted".
method you speaking about was made to have a little optimization in most-used case when there is only one aggregate type and aggregate is kept for a long time (i'm not quite sure if i need to keep it or not - cause you just made a mistake i was thinking about when created this method).

from zio-event-sourcing.

heksesang avatar heksesang commented on June 30, 2024

But if the event can't be reduced, then you can never reduce that aggregate as you will always read an invalid event after you have stored it? If I have an event Created that is not supposed to be possible to reduce twice for the same aggregate, but is stored twice in the journal, how do you solve this?

from zio-event-sourcing.

holinov avatar holinov commented on June 30, 2024

But if the event can't be reduced - don't get this. I could always filter-out unneeded events. But if i have this events in event log i'm able to build some analytics aggregations on this "corrupted" data

from zio-event-sourcing.

Related Issues (5)

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.