1
votes

Let's say I have a product catalog where people can change product prices. I implement a event store to be able to replay all "price changed" events to get last price in case it disappears.

When replaying the events, how do I know the starting price? I mean, if the event contains only the information "price changed to 10$", then I must know what it was first. Or do you always put that info in the event? Like this "price changed from 9$ to 10$".

2

2 Answers

0
votes

What is the price of a product when it hasn't changed its price yet?

0
votes

You could include on the event data the timestamp or the version number of your aggregate. When replying you could then consider those values and ask something along the lines of . Is this price newer than the one I already have? if so Update else don't do anything. This way you could eventually get the newest and oldest price, even if you don't know all the past prices. Only if this is ok by your domain.

Storing the event "price changed from 9$ to 10$" can help you determine races between to users. It is a bit of extra information that can help you answer future questions.

I have a similar situation in which something outside my event store creates the first version of the aggregate on the view. I had to create a special processes that looks around the view for un-aggregated rows. and creates an Imported Event, then puts it on the store.