How temporalio/sdk-dotnet works
Purpose and Entry Points
This is the Temporal .NET SDK: libraries for authoring durable workflows and activities, running workers, and calling Temporal Server or Temporal Cloud. The primary package is src/Temporalio/Temporalio.csproj; public application entry points are Temporalio.Client.TemporalClient, Temporalio.Worker.TemporalWorker, and static workflow APIs in Temporalio.Workflows.Workflow.
Client and Server Boundary
Client APIs start, signal, query, update, inspect, and manage workflows, standalone activities, schedules, task queues, Nexus operations, and selected server/operator/cloud APIs. TemporalClient owns the high-level typed API and handles; TemporalConnection owns connection configuration such as TLS, retries, proxies, compression, and payload limits.
• src/Temporalio/Client/TemporalClient.cs
• src/Temporalio/Client/TemporalConnection.cs
• src/Temporalio/Client/ITemporalClient.Workflow.cs
Calls cross from managed C# into the native bridge, which communicates with Temporal Server over gRPC. Targets include local/self-hosted Temporal and Temporal Cloud, including mTLS.
Native Bridge and Runtime
The SDK depends on the Rust-based sdk-core native shared library, exposed through generated/native interop and safe managed wrappers. The bridge provides client, worker, runtime, telemetry, metrics, ephemeral server, and workflow-replay primitives. This is the principal managed/unmanaged boundary and constrains supported OS/RID architectures.
• src/Temporalio/Bridge/Runtime.cs
• src/Temporalio/Bridge/Client.cs
• src/Temporalio/Bridge/Interop/Interop.cs
TemporalRuntime configures core logging, metrics, OpenTelemetry export, and native runtime lifetime.
• src/Temporalio/Runtime/TemporalRuntime.cs
• src/Temporalio/Runtime/TemporalRuntimeOptions.cs
Worker Execution Pipeline
A TemporalWorker is configured with a task queue and registered workflow/activity/Nexus definitions, then polls Temporal through the bridge. It dispatches activity tasks to ordinary .NET code and workflow activations to the deterministic workflow runtime; completions are serialized back through the bridge to the server. Worker tuning controls poller and execution-slot capacity.
• src/Temporalio/Worker/TemporalWorker.cs
• src/Temporalio/Worker/TemporalWorkerOptions.cs
• src/Temporalio/Worker/WorkflowWorker.cs
Activities run with async-local execution context for heartbeat, cancellation, logging, and shutdown handling.
• src/Temporalio/Activities/ActivityExecutionContext.cs
• src/Temporalio/Worker/ActivityWorker.cs
Deterministic Workflow Runtime
Workflow classes are reflection-defined through attributes and executed as replayable state machines. WorkflowInstance processes activations and produces commands; Workflow exposes deterministic time, random values, timers, activity/child-workflow/Nexus scheduling, signals, queries, updates, and continue-as-new. A custom scheduler and tracing listener detect invalid nondeterministic task scheduling.
• src/Temporalio/Workflows/Workflow.cs
• src/Temporalio/Worker/WorkflowInstance.cs
• src/Temporalio/Worker/WorkflowTracingEventListener.cs
History replay is a separate local validation flow over stored/fetched workflow histories.
• src/Temporalio/Worker/WorkflowReplayer.cs
• src/Temporalio/Common/WorkflowHistory.cs
Serialization, API Contracts, and Failures
The conversion boundary translates .NET values and exceptions to Temporal payloads/failures. DataConverter composes payload converters, byte-to-byte codecs (e.g., encryption/compression), and failure conversion; the same conversion model is used by clients and workers.
• src/Temporalio/Converters/DataConverter.cs
• src/Temporalio/Converters/DefaultPayloadConverter.cs
• src/Temporalio/Converters/DefaultFailureConverter.cs
Generated protobuf/gRPC contract types represent Temporal’s service and history protocol, isolating public SDK abstractions from wire-level models.
• src/Temporalio/Api/WorkflowService/V1/Service.cs
• src/Temporalio/Api/Workflow/V1/Message.cs
• src/Temporalio/Api/Failure/V1/Message.cs
Integration and Deployment Surfaces
Optional packages adapt the SDK to .NET Generic Host/DI, OpenTelemetry, DiagnosticSource metrics, AWS Lambda, and GCP Cloud Run. Hosting manages client registration and worker service lifecycle; tracing is injected via interceptors.
• src/Temporalio.Extensions.Hosting/TemporalWorkerService.cs
• src/Temporalio.Extensions.OpenTelemetry/TracingInterceptor.cs
• src/Temporalio.Extensions.Aws.Lambda/TemporalLambdaWorker.cs
Code generation is architecturally significant: protobuf API bindings, system Nexus bindings, and native interop are generated rather than hand-maintained.
• src/Temporalio.Api.Generator/Program.cs
• src/Temporalio.SystemNexus.Generator/Program.cs
• src/Temporalio/Bridge/GenerateInterop.rsp
Main entry points: TemporalClient.cs TemporalClient · TemporalWorker.cs TemporalWorker · Client.cs Managed native bridge · WorkflowInstance.cs WorkflowInstance
Components 22
Public SDK
- Temporalio package · Primary .NET SDK package.
src/Temporalio/Temporalio.csproj - TemporalClient
src/Temporalio/Client/TemporalClient.cs - Workflow client APIs · Start, signal, query, update, and manage workflows.
src/Temporalio/Client/ITemporalClient.Workflow.cs - TemporalConnection · Owns TLS, retry, proxy, compression, and payload settings.
src/Temporalio/Client/TemporalConnection.cs
Worker Execution
- TemporalWorker · Registers definitions and polls a task queue.
src/Temporalio/Worker/TemporalWorker.cs - ActivityWorker
src/Temporalio/Worker/ActivityWorker.cs - Activity execution context · Provides heartbeat, cancellation, logging, and shutdown state.
src/Temporalio/Activities/ActivityExecutionContext.cs - WorkflowWorker
src/Temporalio/Worker/WorkflowWorker.cs - Workflow runtime · Provides replay-safe workflow operations.
src/Temporalio/Workflows/Workflow.cs - WorkflowInstance · Processes activations and emits commands.
src/Temporalio/Worker/WorkflowInstance.cs - WorkflowReplayer · Validates workflows against stored or fetched history.
src/Temporalio/Worker/WorkflowReplayer.cs
Core Bridge & Contracts
- TemporalRuntime · Configures native logging, metrics, and OpenTelemetry.
src/Temporalio/Runtime/TemporalRuntime.cs - DataConverter · Composes payload converters, codecs, and failure conversion.
src/Temporalio/Converters/DataConverter.cs - Generated API contracts · Wire-level service, workflow, and failure protocol types.
src/Temporalio/Api/WorkflowService/V1/Service.cs - Managed native bridge · Exposes sdk-core client, worker, runtime, telemetry, and replay primitives.
src/Temporalio/Bridge/Client.cs - Native interop bindings · Managed/unmanaged ABI boundary.
src/Temporalio/Bridge/Interop/Interop.cs - sdk-core native library · Native Temporal client and worker runtime.
- API code generator · Generates protobuf API bindings.
src/Temporalio.Api.Generator/Program.cs - Interop generator input · Drives generated native interop bindings.
src/Temporalio/Bridge/GenerateInterop.rsp
Integration Surfaces
- Generic Host integration · Registers clients and manages worker lifecycle.
src/Temporalio.Extensions.Hosting/TemporalWorkerService.cs - OpenTelemetry integration
src/Temporalio.Extensions.OpenTelemetry/TracingInterceptor.cs
Other components
- Temporal Server / Cloud · Remote task, history, and control-plane endpoint.
Connections 23
- Temporalio package → TemporalClient: exports
- Temporalio package → TemporalWorker: exports
- TemporalClient → Workflow client APIs: implements
- TemporalClient → TemporalConnection: uses
- TemporalClient → DataConverter: serializes with
- TemporalClient → Managed native bridge: calls through
- TemporalWorker → ActivityWorker: dispatches activities
- TemporalWorker → WorkflowWorker: dispatches activations
- TemporalWorker → Managed native bridge: polls and completes through
- ActivityWorker → Activity execution context: sets
- WorkflowWorker → WorkflowInstance: drives
- WorkflowInstance → Workflow runtime: executes
- WorkflowInstance → DataConverter: converts commands and failures
- WorkflowReplayer → WorkflowInstance: replays through
- TemporalRuntime → Managed native bridge: configures lifetime
- Managed native bridge → Native interop bindings: uses
- Native interop bindings → sdk-core native library: loads
- sdk-core native library → Temporal Server / Cloud: gRPC
- Managed native bridge → Generated API contracts: exchanges protocol models
- Generic Host integration → TemporalWorker: hosts
- OpenTelemetry integration → TemporalClient: intercepts
- API code generator → Generated API contracts: generates
- Interop generator input → Native interop bindings: generates