You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe this is a stupid idea because I'm too naive not having event sourced an app before, but I've been thinking for a couple of scenarios regarding event replaying that could potentially be useful.
Selectively Replaying Events
I can image a situation where I want to replay only a subset of events, for example I want to exclude events fired by a specific user on reply.
An example might be an auction platform where each bid is an event. Most auctions sites if the high bidder does not pay will simply rerun a new auction for the item or offer to the second highest bidder at their bid price. However I think a better method would be to exclude bids from the non paying bidder and replay the remaining bids to calculate the new winning bid and bidder for example.
Another use case would be to only replay events that were fired within a specific timeframe, for example in the last calendar year.
I have though about how this might be implemented and I'm leaning towards a query builder like experi nice (maybe called EventBuilder?) So I could do something like this.
To only replay those events for item 7 not fired by user 12 for example.
Custom Projection on Replay
Another use case I am thinking of is what I guess I would consider a partial projection. That is if I want to add a new projection it could be nice to only run the new projection on existing events instead of having to truncate tables and rerun all previous projections.
One specific example that I have (which also would require selectively Replaying Events) is End of Year Reporting. Let's say it's January 2024 and I want to take all events fired in 2023 and roll them up into an end of year report on its own table.
But what makes this different than the last example is I don't want to have to drop the affected rows from previous projections on those events to just reproject. I want to define a custom sub projection. I'm thinking that could be done by passing a closure into the replay method like so and Verbs would replay the events running that clasoure in lieu of the handle method on the event. But because the event is passed in, the closure could run the handle or any other method on the event if needed or wanted.
The one downside I see is replaying requires something more precise than simply truncating a projection table and so without proper setup could make the projections fail or be incorrect but I think with a warning in the docs it should be fine. Chef's use sharp knifes after all. Plus worst case scenario you could get back to a good state by truncating everything and replaying all events as normal so there's not a huge risk.
I'm curious to see what Daniel and anyone else who has done real world event sourced apps thinks about these ideas.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Maybe this is a stupid idea because I'm too naive not having event sourced an app before, but I've been thinking for a couple of scenarios regarding event replaying that could potentially be useful.
Selectively Replaying Events
I can image a situation where I want to replay only a subset of events, for example I want to exclude events fired by a specific user on reply.
An example might be an auction platform where each bid is an event. Most auctions sites if the high bidder does not pay will simply rerun a new auction for the item or offer to the second highest bidder at their bid price. However I think a better method would be to exclude bids from the non paying bidder and replay the remaining bids to calculate the new winning bid and bidder for example.
Another use case would be to only replay events that were fired within a specific timeframe, for example in the last calendar year.
I have though about how this might be implemented and I'm leaning towards a query builder like experi nice (maybe called EventBuilder?) So I could do something like this.
To only replay those events for item 7 not fired by user 12 for example.
Custom Projection on Replay
Another use case I am thinking of is what I guess I would consider a partial projection. That is if I want to add a new projection it could be nice to only run the new projection on existing events instead of having to truncate tables and rerun all previous projections.
One specific example that I have (which also would require selectively Replaying Events) is End of Year Reporting. Let's say it's January 2024 and I want to take all events fired in 2023 and roll them up into an end of year report on its own table.
But what makes this different than the last example is I don't want to have to drop the affected rows from previous projections on those events to just reproject. I want to define a custom sub projection. I'm thinking that could be done by passing a closure into the replay method like so and Verbs would replay the events running that clasoure in lieu of the handle method on the event. But because the event is passed in, the closure could run the handle or any other method on the event if needed or wanted.
The one downside I see is replaying requires something more precise than simply truncating a projection table and so without proper setup could make the projections fail or be incorrect but I think with a warning in the docs it should be fine. Chef's use sharp knifes after all. Plus worst case scenario you could get back to a good state by truncating everything and replaying all events as normal so there's not a huge risk.
I'm curious to see what Daniel and anyone else who has done real world event sourced apps thinks about these ideas.
Beta Was this translation helpful? Give feedback.
All reactions