Run
UseRestate.run (Java) / runBlock (Kotlin) to safely wrap any non-deterministic operation, like HTTP calls or database responses, and have Restate store its result in the execution log.
Asynchronous run actions
Asynchronous run actions
To run an action asynchronously, use You can use this to combine your run actions with other asynchronous operations, like waiting for a timer or an awakeable.Check out Concurrent tasks.
Restate.runAsync (Java) / runAsync (Kotlin):Serialization
Serialization
Have a look at the serialization docs to learn how to serialize and deserialize your objects.
Error handling and retry policies
Error handling and retry policies
Failures in a run block are treated the same as any other handler error. Restate will retry it unless configured otherwise or unless a
TerminalException is thrown.You can customize how a run block retries via:- You can limit retries by time or count
- When the policy is exhausted, a
TerminalExceptionis 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 suspend 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 inactivity timeout and abort 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 that return the same result on retries.UUIDs
To generate stable UUIDs for things like idempotency keys:Random numbers
To generate a deterministic float between0 and 1:
Random class but is deterministically replayable.
You can use any of the methods of java.util.Random to generate random numbers: for example, nextBoolean(), nextLong(), nextFloat(), etc.