EventFlow icon indicating copy to clipboard operation
EventFlow copied to clipboard

Load aggregate at specific version

Open Athosone opened this issue 3 years ago • 9 comments

Hi !

In our company we are starting to use Eventflow.

We have a use case where we want to query the state of our aggregate between date range.

So far I did not see any out of the box way to do that. Did I miss something or did not understand a concept?

I think that I should use the event store and load all events for my aggregate then replay them until the desired date however I can foresee performance issue at some point.

This is where I may use snapshot,

However I did not see a way to query a snapshot from a certain date...

Do you have any advice concerning this use case?

Regards

Ayrton

Athosone avatar Oct 19 '21 21:10 Athosone

Hi @Athosone

Just to make sure that I fully understand, you want to read the aggregate as it looked at a specific point in time? If so, then no, there isn't anything currently in the framework. But sounds like a useful thing to have.

I looked into the current available APIs and doing it yourself doesn't seem complicated. Read the events from the aggregate you are interested in via the IEventStore, do the required filtering, then create a new empty instance of your aggregate via the IAggregateFactory and simply invoke ApplyEvents with the list of filtered events on the aggregate.

rasmus avatar Oct 20 '21 06:10 rasmus

Thanks for the quick reply

Ok then I'll experiment with this, we could contribute eventually if that's something that may interest you?

Athosone avatar Oct 20 '21 13:10 Athosone

As for the snapshot I would need to implement a custom snapshot store which persist a new snapshot of the aggregate instead of updating the current one right ? using the timestamp / id as index

Athosone avatar Oct 21 '21 14:10 Athosone

I have a similar need, so if it's something you want in EventFlow, I can fork and PR it for you. I would also be interested in helping contribute to the project, we are ramping up to use it here at my company. So let me know if you'd be interested in that as well.

Zev-OwitGlobal avatar Feb 07 '22 22:02 Zev-OwitGlobal

@Athosone did you see https://github.com/eventflow/EventFlow/issues/570

rasmus avatar Mar 03 '22 08:03 rasmus

Something like

// Load events representing version
var domainEvents = IEventStore.LoadEventsAsync(id)
domainEvents = domainEvents.Where(e => e.AggregateSequenceNumber < selected version).ToList()

// Apply to empty aggregate
var aggregate = IAggregateFactory.CreateNewAggregateAsync(id)
aggregate.ApplyEvents(domainEvents)

rasmus avatar Mar 03 '22 08:03 rasmus

Hello there!

We hope you are doing well. We noticed that this issue has not seen any activity in the past 90 days. We consider this issue to be stale and will be closing it within the next seven days.

If you still require assistance with this issue, please feel free to reopen it or create a new issue.

Thank you for your understanding and cooperation.

Best regards, EventFlow

github-actions[bot] avatar Apr 08 '23 13:04 github-actions[bot]

Hello there!

We hope you are doing well. We noticed that this issue has not seen any activity in the past 90 days. We consider this issue to be stale and will be closing it within the next seven days.

If you still require assistance with this issue, please feel free to reopen it or create a new issue.

Thank you for your understanding and cooperation.

Best regards, EventFlow

github-actions[bot] avatar Jul 08 '23 09:07 github-actions[bot]

Will make it respect the stale exempt

rasmus avatar Jul 08 '23 15:07 rasmus