Skip to main content

Non-deterministic values and durable execution

Durable execution replays a task from the start after an interruption, such as a restart or rolling deploy. Context calls that already completed return their cached results instead of re-running. A bare Date.now() or crypto.randomUUID() is not a context call, so it produces a different value on every replay and desynchronizes the run from its cached history. ctx.sideEffect() runs your callback once and caches the returned value like any other context call. On replay, it returns the cached value and the callback does not run again.

Example

Generate a request id and timestamp once, then reuse them in a writeContract call:
Use ctx.sideEffect() for any value that must stay the same across replays: timestamps, random values, UUIDs, or any other source of non-determinism. For the caching model that makes this necessary, see Durable execution and context caching.

Next Steps

callTask

Invoke another task in the same app.

Context overview

How context functions, caching, and retries work.