Run
UseRun
to safely wrap any non-deterministic operation, like HTTP calls or database responses, and have Restate store its result in the execution log.
Run
, you cannot use the Restate context (e.g., get
, sleep
, or nested Run
).
You should only use methods available on the RunContext
provided to your function.
Serialization
Serialization
You can return any payload that can be serialized. By default, serialization is
done with
JSONCodec
which uses encoding/json
. If you don’t need to return anything, you can use
restate.Void{}
which serialises to a nil byte slice.Error handling and retry policies
Error handling and retry policies
Failures in
Run
are treated the same as any other handler error. Restate will retry it unless configured otherwise or unless a TerminalError
is thrown.You can customize how Run
retries via:- You can limit retries by time or count
- When the policy is exhausted, a
TerminalError
is thrown - See the Error Handling Guide and the Sagas Guide for patterns like compensation
Increasing timeouts
Increasing timeouts
If Restate doesn’t receive new journal entries from a service for more than one minute (by default), it will automatically abort the invocation and retry it.However, some business logic can take longer to complete—for example, an LLM call that takes up to 3 minutes to respond.In such cases, you can adjust the service’s abort timeout and inactivity timeout settings to accommodate longer execution times.For more information, see the error handling guide.
Deterministic randoms
The SDK provides deterministic helpers for random values — seeded by the invocation ID — so they return the same result on retries.UUIDs
To generate stable UUIDs for things like idempotency keys:Random numbers
Methods exist onrestate.Rand(ctx)
for generating float64
and uint64
, or
otherwise restate.Rand(ctx).Source()
can be provided to math/rand/v2
as a
source for any random operation: