-
Notifications
You must be signed in to change notification settings - Fork 55
RPC
RPC stands for "Remote Procedure Call". Allows external systems to interact with the workflow execution.
It's invoked by client, executed in workflow worker, and then respond back the results to client.
RPC can have access to not only persistence read/write API, but also interact with WorkflowStates using InternalChannel, or trigger a new WorkflowState execution in a new thread.
It's important to note that in addition to read/write persistence fields, a RPC can trigger new state executions, and publish message to InternalChannel, all atomically.
Atomically sending internal channel, or triggering state executions is an important pattern to ensure consistency across dependencies for critical business – this solves a very common problem in many existing distributed system applications. Because most RPCs (like REST/gRPC/GraphQL) don't provide a way to invoke background execution when updating persistence. People sometimes have to use complicated design to acheive this.
But in iWF, it's all builtin, and user application just needs a few lines of code!
Note that by default, read and write are atomic separately.
To ensure the atomicity of the whole RPC for read+write, you should use PARTIAL_WITH_EXCLUSIVE_LOCK
persistence loading policy for the RPC options.
The PARTIAL_WITH_EXCLUSIVE_LOCK
for RPC is only supported by Temporal as backend with enabling synchronous update feature (by frontend.enableUpdateWorkflowExecution:true
in Dynamic Config).
See the wiki for further details.
There are two major ways for external clients to interact with workflows: Signal and RPC.
Historically, signal was created first as the only mechanism for external application to interact with workflow. However, it's a "write only" which is limited. RPC is the new way and much more powerful and flexible.
Here are some more details:
- Signal is sent to iWF service without waiting for response of the processing
- RPC will wait for worker to process the RPC request synchronously
- Signal will be held in a signal channel until a workflow state consumes it
- RPC will be processed by worker immediately