> ## Documentation Index
> Fetch the complete documentation index at: https://docs.goldsky.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Non-Deterministic Values (sideEffect)

> Cache non-deterministic values like timestamps and UUIDs with ctx.sideEffect so task replays stay deterministic.

## 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.

```typescript theme={null}
sideEffect<T>(fn: () => T | Promise<T>): Promise<T>
```

### Example

Generate a request id and timestamp once, then reuse them in a `writeContract` call:

```typescript theme={null}
import { TaskContext } from "compose";

export async function main(ctx: TaskContext) {
  // Computed once; the cached values are returned on any replay.
  const { requestId, timestamp } = await ctx.sideEffect(async () => ({
    requestId: crypto.randomUUID(),
    timestamp: Date.now(),
  }));

  const wallet = await ctx.evm.wallet({ name: "default" });
  // requestId and timestamp are passed in the contract call args
  await wallet.writeContract(
    ctx.evm.chains.base,
    ctx.env.CONTRACT_ADDRESS as `0x${string}`,
    "recordRequest(string,uint256)",
    [requestId, timestamp]
  );
}
```

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](./overview#durable-execution-and-context-caching).

## Next Steps

<CardGroup cols={2}>
  <Card title="callTask" icon="code" href="./call-task">
    Invoke another task in the same app.
  </Card>

  <Card title="Context overview" icon="parentheses" href="./overview">
    How context functions, caching, and retries work.
  </Card>
</CardGroup>


## Related topics

- [Overview](/compose/context/overview.md)
- [Delivery guarantees](/turbo-pipelines/delivery-guarantees.md)
- [Non-EVM Data Schemas](/mirror/reference/schema/non-EVM-schemas.md)
- [Turbo SQL Functions Reference](/turbo-pipelines/reference/sql-functions.md)
- [Payments & fintech on Goldsky](/solutions/payments-fintech.md)
