How the Synchronous Proxy pattern works
masterThe Synchronous Proxy pattern allows a non-workflow process (like a stateless web application) to advance a workflow state machine from an initial state to a terminal state by both sending data to and receiving data from the workflow.
The Problem
- Signals are one-way (fire and forget). A Temporal client can send a signal, but a workflow cannot send a signal back to a client.
- Queries can retrieve information, but they are intended to be idempotent and should not modify the workflow's state. They also require inefficient polling.
The Solution
To achieve a request-response loop between a non-workflow process and a workflow, you use Proxy Workflows:
- Primary Workflow: Holds the main state machine and business logic.
- Proxy Workflow: A secondary workflow started by the non-workflow process. It signals the Primary Workflow with data and then blocks (waits) for a response. When the Primary Workflow signals the Proxy Workflow with a result, the Proxy Workflow exits and returns that value to the caller.
This allows the non-workflow caller to treat the interaction as a synchronous, blocking call that receives a return value.