serverlesstechnology / cqrs

A lightweight, opinionated CQRS and event sourcing framework.
Other
370 stars 40 forks source link

How can I replay all events in the order they were committed? #93

Closed filwaline closed 3 months ago

filwaline commented 5 months ago

How can I replay all events in the order they were committed?

I am storing events from multiple aggregates in the same table, such as aggregates A, B, and C. The events are presented staggered in the table as follows:

However, QueryReplay requires an Aggregate type and only replays events for that specific aggregate. What I want is to replay all events in the order they were committed, regardless of which aggregate they belong to.

Consider these scenarios:

  1. A::E2 has a foreign key dependency on C::E1; if I only replay aggregate A's events, it will lead to a database error.
  2. If I replay C's events after B's events and they update some common fields, there may be conflicting updates.
davegarred commented 3 months ago

Hi @filwaline,

The naive approach is to use a commit time field in the database.

I think a more important question is why do you want them replayed in temporal order across aggregate boundaries? If your domain model relies on this, you probably have an error in that model.