Journaling Results
Restate uses an execution log for replay after failures and suspensions. This means that non-deterministic results (e.g. database responses, UUID generation) need to be stored in the execution log. The SDK offers some functionalities to help you with this:
- Journaled actions: Run any block of code and store the result in Restate. Restate replays the result instead of re-executing the block on retries.
Journaled actions
You can store the result of a (non-deterministic) operation in the Restate execution log (e.g. database requests, HTTP calls, etc). Restate replays the result instead of re-executing the operation on retries.
Here is an example of a database request for which the string response is stored in Restate:
async def do_db_request():# ... implement ...return "my_result"result = await ctx.run("database request", do_db_request)
You cannot use the Restate context within ctx.run
.
This includes actions such as getting state, calling another service, and nesting other journaled actions.
You can return any payload that can be serialized with bytes(json.dumps(obj), "utf-8")
and deserialized with json.loads(buf)
.
If not, you need to specify a custom serializer.
Always immediately await ctx.run
, before doing any other context calls.
If not, you might bump into non-determinism errors during replay,
because the journaled result can get interleaved with the other context calls in the journal in a non-deterministic way.