docs/architecture/deployment-execution/callbacks.md
(callbacks)=
The callback system allows programs, or even component libraries, to expose user-authored functions to the engine and call them across process boundaries. These functions are defined alongside the rest of the Pulumi program, and run in the same process, but are typically not called directly by user code. Instead they are called by the engine at specific moments of the deployment. This mechanism enables features like resource transforms and resource hooks.
The language SDKs start a gRPC server implementing the service (for example, _callbacks.py). This server exposes a single method: . User-authored functions are registered with this server, and the engine is informed of their existence by calling or .
The message is used to register a callback. It represents a callback reference and contains two essential pieces of information:
When the engine needs to invoke a callback, it calls with a . This message contains the token used to identify a function registered with an SDK's gRPC callback server.
The language host receives the request, looks up the function associated with the token, deserializes the request bytes, invokes the function, and returns a :
The callback and are intentionally generic and untyped at the gRPC layer. This allows the system to support multiple callback types, each with their own request/response message formats serialized into the bytes fields.
The system supports multiple callback types, each with their own request/response message formats: