'Does Cadence have the concept of Workflow Evolution?

"Does cadence have a concept of ""workflow evolution""?

In other words, I have a ""stateful actor"" that models a customer. Initially, the customer has two fields with some signal methods that modify them, some query methods that fetch state, and some main workflow on that actor. Suppose I have 10 of these instances and they are long-lived.

Later I want to add a third field and maybe another signal method. What can I use?



Solution 1:[1]

Versioning with Cadence can help here. Here's the documentation.

From the documentation, as an example, a line like below

err := workflow.ExecuteActivity(ctx, ActivityA, data).Get(ctx, &result1)

becomes

var err error
v := workflow.GetVersion(ctx, "Step1", workflow.DefaultVersion, 1)
if v == workflow.DefaultVersion {
    err = workflow.ExecuteActivity(ctx, ActivityA, data).Get(ctx, &result1)
} else {
    err = workflow.ExecuteActivity(ctx, ActivityC, data).Get(ctx, &result1)
}

if you have more than 2 versions it will look like below:

v := workflow.GetVersion(ctx, "Step1", workflow.DefaultVersion, 2)
if v == workflow.DefaultVersion {
    err = workflow.ExecuteActivity(ctx, ActivityA, data).Get(ctx, &result1)
} else if v == 1 {
    err = workflow.ExecuteActivity(ctx, ActivityC, data).Get(ctx, &result1)
} else {
    err = workflow.ExecuteActivity(ctx, ActivityD, data).Get(ctx, &result1)
}

and so on. You can refer to the documentation for more details.

Solution 2:[2]

Yes, Cadence and Temporal support the evolution of already running workflows. See Versioning documentation for more details.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ender
Solution 2 Maxim Fateev