What happens during workflow replay when mutable side effect is recomputed to a different result?

The use case for mutableSideEffect is reading a configuration value that can change repeatedly. Imagine code like this:

for {
   value = readConfigValue()
    doSomething(value)
}

If readConfigValue uses sideEffect, then a marker event is written for each loop iteration, even if the returned value is the same. When mutableSideEffect is used for this only one marker per different value is recorded.

When a workflow gets replayed at runtime and the mutableSideEffect happens to be recomputed to a new value that is different from the original result,

mutableSideEffect doesn’t recompute value during replay. It uses values recorded in the history, so it is deterministic.

1 Like