Search code examples
azure-functionsazure-durable-functions

Why does The behavior of "replay" ensure reliable execution in Azure durable functions?


I think that the behavior of "replay" ensures reliable execution in Azure durable functions as described in the following link.

https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-checkpointing-and-replay

However, I don't know why this means reliable and the difference between "replay" and no "replay".

The behavior of replay is very complicated. I guess not using replay is simpler than using replay.

Why do durable functions use replay? Why does The behavior of "replay" ensure reliable execution in Azure durable functions?


Solution

  • Reliable Execution is specifically required because durable functions are usually best suited for complex long-running operations which involve multiple functions - both orchestrator and activity.

    When running on the consumption plan, your function app might move between VMs depending on how long your function runs. In such scenario, your function should be able to run from where it left off in one VM in the next VM. This is basically where replay comes in.

    Your function is essentially rerunning every time to ensure that the current state of your function is as committed into Azure Storage (which durable functions use for external state management/logging).

    Do note that this does not mean your functions just keep re running every time, instead their results are also stored allowing for the "re-hydration" of your function execution state without actually rerunning the functions.

    But for this to be possible, your orchestrator code has some constraints which you must follow as documented. For reference,

    • Deterministic - Don't use functions that give different outputs on each replay. If you need such functions, move them into their own activity functions
    • Non-Blocking
    • No async operations apart from the ones made using the Durable Functions library
    • Avoid infinite loops

    You can read more on the underlying pattern that Durable Functions implement - Event Sourcing - for more information.