
Invocation ID
Invocations have a unique Invocation ID starting withinv_. You can find this ID in every place where an invocation is mentioned:
- The invocations page of the Restate UI
- Logs and traces (
restate.invocation.id), both in Restate and SDKs - In CLI commands such as
restate invocation ls
Lifecycle
Invocations follow a well-defined lifecycle:
Cancel
You can cancel an invocation at any point in its lifecycle. Cancellation has the following characteristics:- Frees held resources
- Cooperates with your handler code to roll back any changes made so far
- Allows proper cleanup
For proper rollback, handlers must include compensation logic to maintain service state consistency. Check the sagas guide.
How Cancellation Works
How Cancellation Works
Requirements
For cancellation to work, the invocation must reach the deployment (the service endpoint must be reachable).If the deployment is not reachable, use kill instead.Cancellation Flow
When an invocation is canceled:- User sends cancellation request to the Restate runtime
- Runtime forwards cancellation to the SDK eagerly
- SDK surfaces cancellation at the next await point in your handler code
TerminalError in TypeScript/Python, TerminalException in Java/Kotlin) is thrown at the next await point - operations that wait for a result, such as ctx.run(), call responses, sleeps, awakeable results, etc.One-way calls (
ctx.send()) and delayed calls (ctx.sendDelayed()) are detached from the call tree. They will be scheduled and execute fully even if the originating invocation is cancelled.Example
Call Graph Propagation
Cancellation propagates recursively through the call graph:- Propagate to leaves: Cancellation first reaches the leaves of the call graph
- Throw at await points: Each handler receives the cancellation exception at its next await point
- Run compensation: Handlers execute their compensation logic (if defined)
- Propagate upward: Cancellation flows back up the call graph (unless handled differently), allowing each parent to compensate
Kill
Use kill when cancellation fails (e.g., when endpoints are permanently unavailable). Killing immediately stops all calls in the invocation tree without executing compensation logic. This may leave your service in an inconsistent state. Only use as a last resort after trying other fixes. Note that one-way calls and delayed calls are not killed because they’re detached from the originating call tree.Resume
If an invocation retries for too many times, Restate will pause it. When an invocation is paused, you need to resume it manually:Resuming on a different deployment
Resuming on a different deployment
When resuming, the invocation will run on the same deployment where it started.If the invocation failed due to some bug you fixed on a new/different deployment,
you can override on which deployment the invocation should be resumed:Be aware that if the business logic/flow between the old and the new deployment code differ, once resumed the invocation will start fail with non-determinism errors!