Handling race conditions of timestamped events

Hello,
I want to contemplate how Temporal handles (or not) race conditions with timestamped events.
Let’s suppose we have a workflow that updates the product price. Imagine a scenario when two sequential events are produced: “change to $10” and “change to $20.” - as a result, we want our product price to be $20.
The payload might look like this:
Event 1:

{
    "product": 1,
    "price": 10,
    "timestamp": 001
}

Event 2:

{
    "product": 1,
    "price": 20,
    "timestamp": 002
}

Sadly, due to network latency issues, the second event arrives before the first one - workflow changes the price to $20, then the second message arrives and changes the price to $10.

I know we could implement some logic on the Activity side, but are there any Temporal capabilities for handling such a case?

The workflow can keep the latest timestamp in its variable and skip the processing of events with a timestamp lower than the stored value.

1 Like

Thanks, @maxim! It seems like the easiest possible solution! But wouldn’t that break workflow determinism? This way, the processing of a current message depends on the previous message.

It will not break determinism, as all the messages are recorded in the workflow history. So, in case of a replay, they will be delivered in the same order.