Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CQRS + EventSourcing. Change Aggregate Root history

I have following problem. Given. CQRS + EventSourcing application. How is that possible to change the state of the Aggregate root in history?

For example, accounting application, accounter wants to apply transation but with past date. The event which will be stored in Event Store will have the older date than recent events, but the sequense number of this event will be bigger.

Repository will restore the state of aggregate root by ordering events by sequence number. And if we will take the snapshot for this past date - we will have aggregate root without this event.

We can surely change the logic of repository to order events by date, but we use external framework for CQRS, and this is not desirable.

Are there some elegant solutions for this case?

like image 323
Aleks Sidorenko Avatar asked Nov 30 '22 22:11

Aleks Sidorenko


1 Answers

What you're looking for is a bi-temporal implementation.

e.g. On dec 3rd we thought X == 12 (as-at), but on dec 5th we corrected the mistake and now know X == 14 on dec 3rd (as-of)

There are two ways to implement this

1) The event store holds as-at data and a projection holds as-of data (a possible variation is both an as-of and as-at projection as well)

2) The aggregate has an overloaded method indicating the desire for as-of vs as-at values from the event store. This will most likely involve using a custom secondary snapshot stream for as-of data values.

Your solution could very likely use both implementations as one is command focused and the other is query focused.

The as-of snapshots for the aggregate root in the second option would need to be rebuilt as corrective events are recieved.

Martin Folwler talks about this in this article

Note: The event store is still append only.

like image 137
CCondron Avatar answered Dec 10 '22 04:12

CCondron