Temporal task routing and worker sessions

Temporal task routing sends an activity to a worker that can reach the right local disk or hardware, and sessions keep related steps on that worker. This page explains the design choices, the build sequence and the limits to confirm before you commit.

On this page

When Temporal task routing is the right answer

Use task routing when a workflow step depends on something only some hosts have: files on a local disk that other hosts cannot read, a GPU or a licensed device attached to one machine, or a network path reachable from one segment only. In those cases an activity must run on a worker that has the resource, not on any worker that happens to poll. Temporal task routing lets you send that activity to a chosen task queue, and only the workers you have registered to that queue will pick it up. A session extends the idea to a sequence: a group of activities that must all land on the same worker so that a file written in one step is still there in the next. Confirm with your SDK's documentation how sessions are created, how long they hold, and what happens when the worker holding a session stops, because those details differ by language and version.

A shared task queue is enough when any worker can perform every activity, when the data an activity needs lives in a shared store such as object storage or a database, and when losing a worker mid-task only means a retry on another host. Most workflows fall into this group, and keeping them there is the cheaper choice. Routing adds cost in several places: you must name and manage a queue per resource class, size each pool separately so that one pool does not sit idle while another is saturated, decide how each pool is deployed and scaled, and build alerts for pools that have no pollers. A pinned host also becomes a single point of failure for the work routed to it, so you need a plan for draining that host, replacing it and handling tasks that were already assigned. Before you commit, ask whether the data can move to shared storage and whether the hardware can be exposed through a pool of workers instead of one machine.

Treat routing as an architecture decision to review with your platform and security teams, not a tuning switch. Write down, for each routed activity, the resource it needs, the number of workers that can serve it, what happens to in-flight work when one of them is removed, and who owns the runbook when a pool has no pollers. Test the failure path before production: stop the pinned worker during a session, confirm what Temporal does with the workflow, and check that the retry policy and timeouts match the time your files or devices need to recover. If the answers are unclear, a scoped design review with the team that will operate the workers is the cheapest way to find out.

How a routed activity reaches the right worker

The walk starts in the Temporal Service, where a workflow schedules an activity onto a task queue named for one host. That queue is only polled by the worker on that host, which holds the local disk or GPU the activity needs. A shared worker pool polls its own queue and never sees the pinned work. Check that the worker hosts sit on the trusted side of the boundary, since the Temporal Service must not be reachable from the public internet.

Pinned activities reach only the worker that owns the host-specific queue.

How worker-specific task queues and sessions work

Temporal workers do not receive work directly from the workflow. They poll a task queue, and whichever worker polling that queue picks up the next task. Routing a Temporal activity to a particular host or hardware class therefore comes down to naming: you start a worker on each target machine with its own task queue name (for example, a queue per host group or per GPU pool), and the workflow passes the matching queue name when it schedules each activity. Any worker that polls a queue can run its tasks, so a queue name is only a route if the only workers polling it are the ones you intend. Confirm that your deployment enforces this, because a second worker started with the same queue name by mistake will quietly take work.

Sessions are the mechanism for keeping several activities on the same worker, which matters when later steps depend on files or state left on local disk. A session is created from the workflow, binds its activities to one worker through a worker-specific queue, and ends when the workflow closes it or the session times out. The exact behavior is SDK-specific and version-specific: how sessions are created and ended, what the timeouts are, whether the worker must be configured to enable sessions, and what happens when the worker that holds a session crashes or shuts down. Check each of these in the official Temporal documentation for your language and SDK version before you design around them, and test the failure path in a staging environment with a deliberately killed worker.

The routing decision lives in workflow code, not in deployment configuration. Changing which queue an activity is sent to, or adding or removing a session, changes the command sequence a workflow produces, so it is a workflow change that needs versioning. Running executions that started before the change must still replay correctly. Plan this before the first release: decide how the queue names are derived, who owns the mapping from hardware to queue, and how you will retire a queue when a host is decommissioned, because work already routed to it has to drain or move first.

Routing options and when each one fits

This table compares four ways to send Temporal activities to a specific host or class of hardware, based on what each routes on, where it fits and what it costs in operations. Read each row against your workload: the more the work depends on local state or special hardware, the more routing control you need, and the more it has to be managed.

OptionWhat it routes onBest fitMain trade-off
Shared queue with a host label checkA host label or attribute the activity checks at start, with retry on mismatchFew hosts, occasional local-disk work, and tolerance for some retriesMismatched tasks cycle back through the queue, so placement is not guaranteed and load can skew
One dedicated task queue per host or deviceThe task queue name, set to a unique value for each host or deviceWork that must run on one specific machine, such as files staged on its diskEach queue needs its own worker, and a lost host strands its queue until it returns or is replaced
Worker sessions on a poolA session tied to one worker in a pool for the life of a related set of activitiesMulti-step file processing where several activities must share local stateSession setup and failure handling add design work, and a dead worker requires recovery logic
Dedicated worker pool per hardware classThe task queue for a hardware class, such as GPU or high-memory hostsWork that needs specialized hardware but can run on any host in that classCapacity for each class is provisioned separately, so idle pools still cost to run

How to set up routed activities in order

This sequence takes a set of activities that depend on specific hosts or hardware and routes them to the right workers, with a plan for losing a host partway through a task. Each step produces something you can check before moving on.

  1. Inventory activities that need local resources

    Start by listing every activity that needs something a generic worker does not have: files on local disk, a GPU, a licensed device, a network segment, or a cache that must stay warm. For each one, record the resource it needs, how long it typically runs, whether it can be retried safely on another host, and which team owns it. Workflow owners and platform engineers should review the list together. The check is a written inventory where every routed activity names a concrete resource and a retry position, and any activity that can run anywhere is removed from the list.

  2. Name task queues per host or hardware class

    Group the inventoried activities by the resource they need, then give each group a task queue name that describes the resource, such as a hardware class or a storage location, rather than a machine name that will change. Decide whether a queue maps to one host or to a pool of hosts with the same capability. Record the naming convention in your platform documentation so future teams follow it. The check is a short table of queue names, the activities each serves, and the workers expected to poll each one, reviewed by the team that owns the workflows.

  3. Start one worker identity per host

    On each host, start a worker process with its task queue name set at startup through configuration or an environment setting, and give each process a distinct identity so operators can see which host handled which activity. Keep the queue name out of shared images where possible, so the same image can serve different hardware classes. Confirm the exact worker option names in the SDK documentation for your language. The check is that each host appears in the Temporal Web UI or CLI as a poller on its intended queue, and that no host polls a queue it should not own.

  4. Add the routing choice to workflow code

    In the workflow, set the task queue on each routed activity call so the activity goes to the queue for its resource. Where a workflow needs the same host for several steps, use a worker-specific queue or a session pattern documented for your SDK, and confirm its current maturity before relying on it. Plan the versioning change now: a workflow that already has running executions must keep its routing decisions during replay, so guard new routing behavior with the versioning mechanism your SDK provides and deploy the change through your worker versioning plan. The check is a code review confirming each routed call sets its queue explicitly, plus a versioned change with a documented rollout plan.

  5. Define what happens when a host is lost

    Decide, per activity, what should occur when the host holding an in-progress activity disappears. Options include letting the activity time out and retry on a different queue with a pool of equivalent hosts, failing the workflow so an operator decides, or compensating for partial work such as removing a half-written file. Set activity timeouts and retry policies to match those decisions, and document which activities are safe to re-run. Involve the owners of the data and the activity code in this decision. The check is a written failure table per routed activity showing the timeout, the retry behavior, the queue used after loss, and the cleanup or compensation step.

  6. Test failover and restarts in a non-production namespace

    Create a non-production namespace that mirrors the routing setup, then run workflows that exercise each routed queue. Stop a worker mid-activity, restart a worker, and remove a host from its queue to confirm the failure table behaves as written. Check that heartbeats, timeouts and retries fire as expected, that work resumes on the intended queue, and that no activity silently runs on the wrong host. Repeat the restart test after a worker process is redeployed with a new version. The check is a recorded test run for each failure case, with the observed behavior matched against the written table, and any gaps logged as blockers before production rollout.

Routing choices for VMs, Kubernetes and specialized hardware

On plain virtual machines, the placement mechanism is the host itself. You start a worker process on a specific VM, register it on a task queue name that only that host polls, and have the workflow schedule the activities that need local files onto that name. The routing guarantee is narrow: an activity on that queue runs only on a worker that has registered for it, so the files it needs are present. Nothing in Temporal moves local files, so the guarantee holds only while the host and its volume exist.

  • Queue naming: use a name that identifies the host or its role, and keep it out of shared pools so no other worker polls it by accident.
  • Registration timing: the worker must be connected before work is scheduled. Confirm what your SDK version does when no poller is connected to a queue.
  • Where the decision lives: the workflow chooses the queue, so pass the host identity as workflow input rather than hard-coding it in a shared configuration file.
  • Disk lifetime: reimaging, replacing or resizing the VM can remove the directory the activity depends on, so keep working files on a volume that outlives the host image.
  • Drain before maintenance: stop the worker from taking new tasks, allow in-flight activities to finish within the shutdown window, then patch or restart.

Confirm who decides whether work is moved off a failed host, and how that choice is recorded in the workflow history.

Security checks for routed workers

Routed workers run activities on specific hosts, often next to sensitive files, so the controls around the Temporal Service and the worker hosts matter as much as the routing itself. The cards below cover the access, network, payload and disk checks to complete before routed workers handle real data.

Check the authorizer first

Self-hosted Temporal uses the default noopAuthorizer when no Authorizer is configured, and that default allows every API request with no authentication or access control. Any host that can reach the frontend could poll a routed task queue or start work in a namespace. Confirm that an Authorizer is configured and tested before any routed worker connects. Try a poll from an unapproved identity and expect it to be refused.

Security docs

Bind worker identity to namespaces

Mutual TLS and a ClaimMapper together decide which worker identity can poll which namespace and task queue. Map certificate or JWT claims to namespace roles so a worker built for one host group cannot poll another group's queue. Keep internode and frontend TLS settings separate in your review. Record which certificate authority issues worker identities and who can revoke them.

Keep services off the public internet

The Temporal deployment docs say Temporal services should run on hosts not reachable from the public internet, with network access restricted to trusted internal networks. For routed workers this applies to the frontend, the history and matching services, and any database behind them. Check security groups, load balancers and ingress rules against that boundary. Scan from outside your network to confirm nothing answers.

Encrypt payloads before routing files

Activity inputs and results are stored as payloads in the Temporal event history, so file names, excerpts or extracted content can persist there. Consider payload encryption through a custom codec and a codec server so the history holds ciphertext. Decide which fields are sensitive, test that the codec runs for every worker, and plan key rotation. Confirm the decryption path works in the Web UI for authorized users only.

Set retention for worker disks

Files staged on local disk by a routed worker are outside Temporal's own storage and need their own controls. Define how long files stay, how they are deleted after an activity completes or fails, and who can read the directory. Set file permissions and encryption at rest on the host, and make cleanup part of the activity's failure path. Verify deletion with a test that runs a failed activity and checks the disk afterward.

Review session and host access

Worker sessions tie a run to one host, so a compromised or decommissioned host can hold work that never finishes. Review who can run worker processes, who can change task queue names, and how host access is logged. Remove retired host identities from namespace roles promptly. Test what happens to a session when its host is removed, and document the recovery step.

Questions teams ask before routing Temporal activities

What drives the cost of routing Temporal activities to specific workers?

The cost depends mostly on how many distinct worker pools you need, how they are provisioned, and how much of the routing logic your team already understands. Each pool adds a task queue, a deployment to run and monitor, and capacity that may sit idle when its host or hardware is not busy. Routing also changes failure handling: if a host is lost, the work pinned to it cannot simply move to another worker, so you need a plan for rebuilding local state or failing the workflow. Ask any partner to price these items separately: queue and worker design, host provisioning, deployment automation, monitoring, and the runbook for lost hosts. Recurring cost comes from running those pools; one-time cost comes from design and build.

Can our internal team build Temporal worker routing alone?

A team that already runs Temporal workers in production and has solid experience with its chosen SDK can usually build simple routing alone, such as one dedicated queue for a host that processes files. The harder parts are less about code and more about operations: deciding what happens when the pinned host fails, keeping local data consistent with workflow state, and making sure deployments do not strand work on old workers. If your team has not yet run Temporal in production, or has no one who has tested failover, a scoped review or implementation partner can cover those gaps. Confirm your team's experience with task queues, worker deployment and recovery before deciding.

How long does it take to set up routed Temporal activities?

The time depends on the number of worker pools, the number of workflow types that need routing, and whether the target hardware or host images already exist. A single pinned pool for one workflow type is a much smaller job than a set of routed pools across several languages or sites. Other factors are how many environments need the setup, how much testing of failure cases is required, and how many approval steps your change process includes. DeployOpen plans these in a written scope before work starts, so the timeline is set from that scope rather than a standard figure. Ask for a timeline that lists each pool, the failure tests and the handover tasks.

What does the internal team need to provide for this work?

The internal team typically provides access to the Temporal namespace and the hosts or hardware that will run the pinned workers, along with the workflow owners who understand which activities must stay local. Platform engineers should supply deployment tooling and monitoring standards, and security teams should review how host-local files are stored, encrypted and deleted. Someone must own the decision about what happens when a host is lost, because that choice affects workflow design. Plan time from these people during the design phase, since most delays come from unanswered questions about data location and recovery rather than from the build itself.

Can we change task routing after workflows are already running?

Changing routing for workflows that are already running is possible but needs care. A running workflow has already scheduled activities on a task queue, and those tasks stay on that queue until they complete, time out or are retried. Moving new work to a different queue is usually simpler than moving in-flight work, so most teams route new executions first and let old ones drain. Check the task queue names in your workflow code, the versions of workers that poll each queue, and whether any activity holds local state that a new worker cannot read. Confirm the exact behavior of your SDK version with the vendor documentation before you change routing on live work.

How does worker versioning affect routed activities?

Worker versioning and routing interact because both decide which worker runs a given task. If a pinned host runs an older build, a new deployment may not reach it, or the older build may keep receiving tasks it no longer understands. Plan the version rollout for each pool separately, and decide whether the pinned hosts are replaced, drained or updated in place. Test a version change on one pinned host before rolling it across the pool. Confirm with your SDK and server versions how versioned task queues behave for pinned workers, because the answer determines how safe in-place updates are.

When is a shared task queue with retries the better choice?

A shared task queue with retries is usually the better choice when any available worker can complete the activity and the work does not depend on local files or specialized hardware. In that case, Temporal can retry the activity on another worker when one fails, and you avoid the extra pools, pinned hosts and recovery plans that routing requires. Routing makes sense when the data or device is physically tied to one host, when a license or hardware is limited to certain machines, or when the work must stay within a specific network zone. Document the reason for each routed activity so that it can be reviewed when the constraint changes.

Limits to confirm in your environment

Worker sessions and host-specific routing depend on server, SDK and platform behavior that varies by version and deployment. The cards below list what to confirm with the vendor and in your own environment before any design is locked, because each item changes how much work the routed design needs.

Supported versions for session features

Confirm which Temporal Server and SDK versions support the session and routing features you plan to use, including the worker-specific task queue pattern. Check the release notes for each server minor version you run, and confirm the SDK version your workers compile against. Server upgrades should move one minor version at a time, so a feature that exists only in a newer line adds an upgrade to the plan. Record the exact versions in the design document.

Upgrade docs

Host loss detection and recovery

Decide how a routed activity is recovered when the host that owns its task queue stops responding. Confirm how the worker heartbeat and activity timeouts behave for host-bound work, and what Temporal does with tasks already sent to a dead worker. Plan whether the activity is retried on the same host, moved to a standby, or failed back to the workflow for a decision. Test each path with a forced host kill.

Local data on pod or VM replacement

Files written to local disk by a worker are lost when its pod or virtual machine is replaced. Confirm where the working directory lives, whether it is an ephemeral volume, a node-local disk or a shared file system, and how a replacement worker learns that a file is missing. Decide who owns cleanup of partial output and how the workflow records the file location. Ask your platform team how node drains and autoscaling affect these directories.

Queue name governance across namespaces

Worker-specific task queue names are easy to create and hard to track once many hosts register them. Confirm who issues names, what naming convention applies, and whether names are unique within a namespace or across the whole Temporal Service. Check how a typo in a host name routes work to a queue that nobody polls. Keep a registry that maps each queue to its host, owner and workflow type.

Load balancing when one host is busy

A routed activity cannot move to another host while it waits for its specific worker, so a busy host builds a backlog that other hosts cannot clear. Confirm how slot limits, poller counts and task queue backlog are reported for each host-bound queue. Decide whether to cap concurrent work per host, queue work behind a shared pool, or accept longer waits. Set alerts on schedule-to-start latency for each queue before production traffic arrives.

Testing routed activities in CI

Routed activities depend on a specific worker being present, so unit tests that mock the queue can miss routing errors. Confirm whether your test setup can start a local Temporal server and register host-specific workers in the same run. Plan tests for host loss, a worker that never starts and a queue name mismatch. Run these tests against the server version used in production, not only the latest release.

How DeployOpen scopes and delivers routed Temporal workers

DeployOpen approaches Temporal task routing and worker sessions as a planned engineering change to your own infrastructure. We scope the routing design against your workflows, your hosts and your self-hosted Temporal deployment, then build, test, document and hand over the result so your team can run it.

How we scope

  • Inventory which activities need local disk, specialized hardware or a specific host, and which can run on any worker
  • Define the worker-specific task queue naming, host registration and failure behavior in a written scope before work starts
  • Agree deliverables, environments and acceptance tests in writing, with engagements fixed-scope and quoted from that scope

How we build

  • Implement worker-specific task queues and session logic in the languages your team uses, with routing kept separate from business logic
  • Test session expiry, host loss and retry behavior in a non-production namespace before any production traffic is routed
  • Confirm that Temporal services stay on hosts that are not reachable from the public internet, with network access restricted to trusted networks

How we hand over

  • Document the routing design, task queue inventory, host mapping and the decisions behind each choice
  • Provide runbooks for adding or draining a host, rotating workers and recovering a session after a host failure
  • Walk your engineers through the build and verification results so they can change routing without outside help

How we support

  • Offer ongoing support, upgrades and continuous testing as retainers after the initial handover
  • Retest routing changes when Temporal Server or SDK versions change, following your upgrade plan
  • Keep the worker and routing configuration under your version control and review process, so changes stay auditable

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.