Temporal sticky execution and the workflow cache

Sticky execution routes a workflow's next task back to the worker that already holds its state in cache, which avoids replaying history. This page explains how the cache and sticky queues work, how to size them and how to spot a cache that is too small.

On this page

How Temporal sticky execution and the workflow cache cut replay cost

Sticky execution and the workflow cache let a worker keep the state of a workflow in memory between workflow tasks, so it does not have to rebuild that state from the full event history each time a new task arrives. Rebuilding state means replaying history through workflow code, and that replay consumes CPU and adds latency on every workflow task. When a team sees rising latency or CPU on workflow tasks, the first question is whether workers are replaying far more often than they need to. Sticky execution routes follow-up workflow tasks for a workflow to the same worker through a worker-specific sticky task queue, and the cache holds the workflow's state on that worker so the next task starts from memory.

Teams need to think about this in three situations: long-running workflows with long event histories, many concurrent workflows on each worker, and worker restarts or deployments that empty the cache. Each one raises the replay work, because a long history is costlier to replay, a crowded cache evicts workflows that will be needed again, and a restart forces every workflow on that worker to replay on its next task. The practical checks are to watch replay-related metrics and cache hit behavior in your SDK's metrics, and to size the cache against the number of open workflows each worker is expected to hold.

The names and defaults for sticky queue timeouts, cache size and related options vary by SDK and runtime, so confirm them in the SDK documentation for the language your workers use before changing anything. Treat a change in cache size as a measured decision: record the memory footprint and task latency before and after, and check that a larger cache does not push workers toward memory pressure during a restart. Your own load tests are the source for sizing decisions, not a generic figure.

How a workflow task travels between the Temporal Service and a worker

The path starts in the Temporal Service, where workflow history is stored and the normal task queue holds the next workflow task. A worker's poller takes that task, and the worker keeps the workflow state in its workflow cache. The worker then polls its own sticky queue for later tasks of the same workflow. If no worker picks up the sticky task in time, the task returns to the normal queue, and whichever worker takes it must replay the workflow from history. Check the fallback path first when replay rates rise.

Sticky and normal queues with the worker cache and fallback replay path.

Which cache and sticky settings to review and when each fits

This table compares the worker-side settings that shape sticky execution and the workflow cache, with the trade-off each one makes between memory, latency and replay work. Read each row as a question to answer from measurement before changing a value. Names and defaults differ by SDK (Go, Java, Python, TypeScript, .NET, Ruby, PHP), so confirm them in your SDK's current documentation first.

SettingTrade-offWhen to review it
Maximum cached workflow executions per workerHigher values keep more workflow state in memory and avoid replay. Lower values free memory but cause more full-history replays.Review when cache miss rates rise under load or when worker memory headroom is measured and clearly available.
Sticky queue schedule-to-start timeoutA longer timeout keeps workflow tasks on the cached worker longer before the server reroutes them. A shorter timeout recovers faster from a slow or lost worker but moves more work to the full-history path.Review when a worker is slow to pick up sticky tasks, or when failover after a worker stops takes longer than expected.
Worker count per hostMore worker processes spread cache and memory across cores and isolate failures. Each process holds its own cache, so total cache capacity is split across them.Review when one process is CPU-bound, when a single process hits memory limits, or when a host has spare cores and a measured cache shortfall.
Concurrent workflow task slotsMore slots allow more workflows to progress at once and keep more state live. Each active workflow competes for memory and CPU on the same process.Review when workflow task slots are saturated while CPU and memory have room, or when cached executions are evicted under pressure.
Workflow task poller countMore pollers reduce pickup latency for sticky and normal queue tasks but add load on the server and the worker process.Review when schedule-to-start latency rises on the sticky queue while the worker is otherwise idle.
Workflow history size and event volumeLarge histories make every full replay slower and more memory hungry. Reducing history size helps cache misses cost less.Review alongside cache settings when replay on miss is expensive for long-running workflows, and confirm limits with your team's design.
Worker deployment and restart frequencyEach restart or rollout empties the cache on that process, so frequent restarts raise replay work across the fleet.Review during rollout planning, and confirm drain and shutdown behavior for your SDK before changing rollout timing.

Why replay cost grows with history length

A Temporal worker does not store workflow state between tasks. Each workflow task carries only the new events, so when a worker has no cached copy of a workflow's state, it must replay the workflow's event history from the beginning before it can run the new code path and produce commands. The longer the history, the more events are replayed, and the more CPU and time each task consumes. Replay cost also scales with how many workflow executions are moving through a worker at once, because every execution that lacks a warm copy pays the same rebuild cost. A worker that receives tasks for many long-running workflows spends a growing share of its capacity on replay rather than on new work.

A warm cache changes the arithmetic. When the worker still holds a workflow's state in memory, it can apply only the events added since its last task and then continue. The cost of each task then tracks the size of the new work, not the length of the whole history. Whether a given task hits the cache depends on how the worker is sized, how many executions it holds, and whether the task reaches the same worker that kept the state, which is the job of sticky execution. Measure replay time and cache hit behavior in your own environment with your own workflow shapes, because history length and event density vary widely between workloads.

This is the trade-off behind cache sizing. A larger workflow cache keeps more executions warm and lowers replay work, but each worker process holds more state in memory, so memory limits and garbage collection pressure rise with it. A smaller cache protects memory but makes replay more frequent. Before you change any cache setting, confirm the memory each worker has available, the typical and longest history lengths your workflows produce, and the worker count you expect at peak. Those three inputs decide whether a larger cache is affordable or whether the fix is to reduce history length through workflow design.

Symptoms of a workflow cache that is too small

A workflow cache that cannot hold active workflow state forces workers to fetch and replay history more often than planned. The symptoms below tend to appear together, so check them as one picture before changing cache settings.

Rising workflow task latency

Workflow task latency climbs when workers rebuild workflow state from history instead of reusing it from memory. Compare schedule-to-start and start-to-close latency for workflow tasks against the baseline from before the change. Then confirm whether the rise lines up with cache eviction in the worker metrics your SDK documents, not with activity slowdowns.

Self-hosted deployment docs

Frequent full history fetches

When a cached workflow is evicted, the next workflow task usually requires the worker to fetch the full event history and replay it. Look for repeated history fetch or replay entries for the same workflow IDs in worker logs. Check the SDK's logging settings and metrics for replay counts, since a steady pattern of full fetches points to a cache that is too small for the number of open workflows.

Sticky cache misses climbing

Sticky execution routes a workflow's next task to the worker that already holds its state. A growing count of sticky cache misses means that routing is not finding warm state, so the worker is falling back to the normal task queue. Pull the sticky cache hit and miss metrics from your SDK documentation and compare them over the same period as your deployment and traffic changes.

Higher worker CPU under normal load

Replay costs CPU, so a worker that suddenly runs hotter at the same throughput may be replaying history rather than executing new workflow code. Compare CPU per completed workflow task before and after the cache change, and check whether the increase follows eviction counts. Confirm that the rise is not caused by a new workflow code path, a larger payload or a change in activity concurrency.

Slow completion after worker restarts

After a restart, every workflow on that worker starts with an empty cache, so the first task for each one replays history. Completion times for long-running workflows can stretch noticeably during the warm-up period. Measure how long it takes the cache to refill after a rolling deploy, and compare that window with your graceful shutdown and termination settings to see whether restarts are the trigger.

More tasks on the normal queue

Workflow tasks that land on the normal task queue instead of the sticky queue are a sign that the cache did not keep the workflow's state. Check how many workflow tasks are dispatched to each queue type in your metrics and whether the normal queue share rises with the number of open workflows. A shift toward the normal queue means the sticky path is no longer carrying most of the load.

How to size and verify the cache in a production worker

This sequence turns a guessed workflow cache size into one that is measured against your own workflow mix, proven to survive a worker restart, and watched by alerts on the same signals. It produces a cache setting you can defend in a capacity review.

  1. Confirm the SDK cache and sticky options

    The platform engineer on the worker team reads the release notes and configuration reference for the Temporal SDK version the workers run, and records the cache size option, the sticky queue timeout, and how the worker reports cache hits, misses and evictions. Confirm the exact option names and defaults against the SDK documentation for that version, since they differ by language. Write the values into the worker configuration repository so every later test runs against the same baseline. The step is done when the team can name each option, its default and its unit, and the version is pinned in the worker image.

  2. Build a representative workflow mix

    The engineering lead groups production workflow types by how long they run, how many events they write and how often they wait on timers or signals, then sets a traffic ratio for each group from production history. Include at least one long-running workflow that sleeps for extended periods, because those executions are most likely to be evicted from cache and replayed. Use illustrative mixes only until production numbers are pulled from your own visibility store. The step is done when the mix is written down with a ratio per workflow type and reviewed by the team that owns the workflows.

  3. Load test a staging worker

    The performance engineer runs the mix against a staging worker with the same CPU and memory limits as production, using a load generator that starts workflows at a steady rate and then at a peak rate. Keep the Temporal Server version and the task queue settings identical to production so the cache is the only variable being measured. Let the test run long enough for workflows to pass through idle waits, so eviction and sticky fallback actually occur. The step is done when the run completes at peak without failed workflow tasks caused by the worker and the results are saved with the configuration used.

  4. Record cache, replay and memory signals

    During the load test, the SRE captures per worker cache hit and miss rates, the number of cached workflow executions, eviction counts, replay time for workflow tasks, and resident memory over time. Compare sticky task hits with fallbacks to the shared task queue, because a rising fallback rate means the cache is not keeping workflows that the worker needs next. Confirm that the metric names used for these signals exist in the SDK version you pinned. The step is done when a table of these signals at steady state and at peak exists for every worker in the test.

  5. Adjust the cache limit and retest

    If memory headroom at peak is thin or evictions cause frequent replays, the platform engineer changes the cache size option in small steps and reruns the same load profile, one change at a time. Lower the value if memory climbs toward the container limit, and raise it only while memory stays clear of that limit and replay time falls. Record each setting with its hit rate, replay time and peak memory so the choice can be explained later. The step is done when one setting meets the team's memory headroom target at peak with a hit rate that holds steady, and the target is written into the runbook.

  6. Test behavior under a rolling restart

    The release engineer restarts workers one at a time during a sustained load run, the way a rolling deployment would, and watches the cache rebuild on each new pod. A restart clears the in-memory cache, so the expected result is a temporary rise in replays that then settles. Check that replay counts return to the pre-restart level once the cache is warm and that no workflow tasks fail or time out during the rollout. The step is done when replay counts stop growing after the last restart and the rollout log shows no failures traced to the worker.

  7. Set alerts on the same signals

    The on-call owner creates alerts for the signals measured in the test: sustained rise in cache miss rate, sticky fallback rate above the baseline, replay time above the measured steady state, and memory approaching the container limit. Each alert links to a runbook that names the cache setting, the worker memory limit and the rollback step. Test each alert by reproducing its condition in staging, such as a deliberately small cache, and confirm it fires. The step is done when every alert has fired once in staging and has an owner who can act on it.

What the sticky fallback means for latency and failover

When the worker holding a workflow's cache cannot pick up the sticky task within the configured timeout, the task moves to the normal task queue, where any worker on that queue can take it. That worker has no cached state for the workflow, so it rebuilds the workflow by replaying its event history before it can run the next workflow task. The fallback keeps work moving, but it converts a warm handoff into a cold one, and the cost lands on latency. The timeout that governs this handoff is the number teams most often assume. Temporal's documentation describes a five-second fallback, but the exact figure depends on the SDK and the server version in use, so confirm the sticky schedule-to-start timeout in the current documentation for your SDK and server before you size alerts or SLAs around it.

The fallback matters most during planned and unplanned capacity loss. During a graceful shutdown, a worker that stops accepting new tasks still holds cached workflows that other workers cannot use directly, so each of those workflows may wait out the sticky timeout and then replay on a different worker. During a rolling deploy, the same pattern repeats for every replaced pod. During a host failure, there is no graceful handoff at all, and recovery depends on how quickly the sticky timeout expires and how long each replay takes for long histories. Your latency during these events is therefore a function of cache hit rate, workflow history length, and the timeout, not only of average throughput in steady state.

Treat this path as something to test, not assume. Run a load test that drives in-flight workflows with realistic history lengths, then stop a worker and measure workflow task latency and replay volume against your baseline. Repeat the test during a deploy in a non-production environment that matches your Kubernetes termination settings. Check the replay and cache metrics your SDK exposes so you can see whether the fallback is firing as expected. Ask your platform team to record the results as an acceptance criterion for the worker rollout, because a fallback that has never been exercised is a latency surprise waiting for the next incident.

How cache sizing differs on Kubernetes, VMs and serverless workers

Worker pods on Kubernetes are usually long-running, so the workflow cache lives as long as the process does. A pod that stays up keeps warm workflow state, and sticky routing sends new workflow tasks back to it. The cache is lost when the pod restarts, moves to another node, or is replaced during a rollout, and each of those events forces the next tasks for affected workflows to replay history.

  • Rollouts and drains: Every rolling update or node drain replaces pods and clears their caches, so the first tasks after a deployment cost more than steady-state tasks.
  • Autoscaling: Scaling out adds workers with empty caches, and scaling in removes workers that hold warm state. Scale-down behavior that removes the newest pods first can reduce churn.
  • Memory limits: The cache sits in process memory, so the container memory limit must cover the cache limit plus the SDK, runtime and activity memory. Leave headroom and confirm under load that the container is not OOM-killed.
  • Termination settings: A termination grace period shorter than the worker's shutdown timeout interrupts in-flight tasks and forces a cold start on the replacement pod.

Before you choose a cache limit, confirm your rollout strategy, autoscaler policy and memory requests with a load test, and check the autoscaling and graceful shutdown pages for the detailed settings.

Security and data exposure in the worker cache

The workflow cache keeps workflow state in worker memory between tasks, so it holds the same data that flows through the workflow. The cards below cover where that data can leak and which controls limit the damage if a worker is compromised.

Treat cached state as sensitive data

Cached workflow state lives in worker memory and can include payloads your workflows pass between activities, such as customer records or account identifiers. Before you enable a large cache, list which workflow inputs and activity results carry regulated or confidential fields. Those fields define what a memory dump or debug snapshot of the worker would expose.

Encrypt cached payloads with a codec

Payload encryption through a custom codec covers what the worker caches as well as what Temporal stores. Confirm that the codec runs in the worker's data converter path so cached state is encrypted in the same way as persisted payloads. Check the key handling for the codec and the codec server separately, since a decrypting codec server is another place where plaintext can appear.

Self-hosted security docs

Review memory dumps and debug endpoints

Heap dumps, core files and profiling endpoints on a worker expose the cached workflow state in plain memory, even when payloads are encrypted before storage. Disable or restrict any debug or profiling endpoint in production, and confirm who can take a process dump on the host. Decide how dumps are stored, how long they are kept and who can read them.

Isolate workers on shared hosts

A worker that shares a host, container node or VM with unrelated workloads gives those workloads a path to read its memory or inspect its process. Run workers on hosts dedicated to your Temporal namespaces where your policy requires it, and confirm that container runtime and node-level access controls keep other tenants out of the worker process.

Keep workers on trusted networks

Temporal's deployment guidance says Temporal services should run on hosts not reachable from the public internet, with network access restricted to trusted internal networks. Workers connect to the frontend and hold cached state, so apply the same rule to worker hosts. Confirm that worker egress and ingress rules allow only the Temporal frontend and the systems the activities call.

Self-hosted deployment docs

Size the cache to limit exposure

Cache size sets how many workflow executions hold live state in one worker's memory at once, so it also sets how much data a single compromised worker can expose. Choose a cache size that meets your latency target without holding more executions than the worker needs. Record the chosen value in the worker configuration so reviewers can compare it with the data classification.

Scrub cache diagnostics before logging

Cache hit, miss and eviction messages can include workflow IDs, run IDs or payload fragments if the logger is set to verbose output. Review what the worker logs at debug level, and mask or drop any field that carries sensitive values before logs reach a shared store. Confirm retention and access rules for that store, since logs often outlive the workflow data they describe.

Questions teams ask before tuning sticky execution and the cache

Can the workflow cache be tuned without changing workflow code?

Often yes, but the cache sits between worker configuration and the workflow code, so the answer depends on what is wrong. Worker-level settings such as the size of the workflow cache, the number of workflow task pollers and the sticky queue behavior are set in worker startup configuration, not in workflow definitions. Changes to how much history each workflow carries, how many activities run per workflow or how large payloads are can reduce cache pressure too, and those do require code review. Before changing anything, confirm the exact SDK option names and defaults for your language in the Temporal SDK documentation, then test the change in staging under realistic load. Treat a configuration-only change as a hypothesis until metrics show the cache hit rate and replay volume moving in the expected direction.

How long does a sticky execution and cache tuning project take?

Duration depends on how much measurement exists before the work starts, how many worker types and task queues are involved, and how many load tests the team needs to trust the result. A single service with existing metrics and a staging environment that resembles production usually takes less time than a fleet of workers across several languages with no baseline. Ask any partner to state the duration in the written scope, with the number of services, languages, environments and test cycles it assumes. DeployOpen agrees timelines in writing before work starts, so the scope document is where the duration is set and justified.

What does the team need to provide for a cache tuning engagement?

The work needs three inputs. First, read access to worker and server metrics, including sticky cache hit and miss rates, workflow task latency, schedule-to-start latency and worker memory and CPU over time. Second, a staging environment that can take a replay of production-like load, because cache behavior changes with the number and length of open workflows. Third, someone who knows the SDK and the workflow code well enough to explain which workflows are long-running, how large their histories grow and which activities are heavy. Without these, tuning becomes guesswork. Confirm access, environment availability and code ownership during scoping, not after the first test run.

Can an internal platform team tune the sticky execution cache alone?

Yes, if the team has Temporal SDK experience, production-grade metrics and a load test process. Internal teams usually know their workloads better than an outside partner does. The risk is that cache problems look like general latency or memory problems, so a team without a baseline can change several settings at once and not know which one helped. Teams that do this in-house typically benefit from a written test plan, one variable changed per run and a rollback path. An external partner adds the most value when the team lacks a second pair of eyes on the test design or needs the work documented for an audit or handover.

What does a fixed-scope cache tuning engagement include?

A fixed-scope engagement is agreed in writing before work starts and normally defines the workers and task queues in scope, the metrics reviewed, the load tests run, the configuration changes recommended and the documentation handed over. For this topic, a typical scope covers a baseline review of sticky cache hit rates and replay activity, a sizing analysis per worker type, staged test runs with one variable changed at a time, a set of alerts for cache misses and a runbook for the symptoms of an undersized cache. Exclusions matter as much as inclusions, such as code changes to workflow design, changes to the Temporal Server or Temporal Cloud configuration and work on other task queues. Ask for the exclusions to be listed explicitly.

How do SDK and Temporal Server upgrades change cache behavior?

Upgrades can change cache behavior in ways that are not obvious from release notes alone, so every upgrade should include a cache check. An SDK upgrade can change worker defaults, the way sticky queues are used or how much memory a cached workflow occupies. A server upgrade can change how tasks are dispatched to workers. Temporal's upgrade guidance says the server should move one minor version at a time, with the latest patch of the current minor first, and that schema upgrades run before server upgrades when release notes call for them. Add cache hit rate, replay volume and schedule-to-start latency to the upgrade checklist, and compare them before and after each step in staging. Confirm the exact compatibility rules for your SDK version in the vendor documentation.

What drives the cost of cache tuning up or down?

Cost is mostly labor, and labor follows the number of workers, languages, task queues and environments in scope, plus how much baseline measurement already exists. Costs rise when metrics are missing, when workflows have very long histories that need code changes, when multiple SDKs are involved or when load tests need to be repeated several times. Costs fall when dashboards already show cache hit rates, when staging can reproduce production load and when a small number of task queues carry most of the risk. Recurring costs are usually limited to the infrastructure for test environments and ongoing monitoring. Ask for a quote built from a written scope that lists each worker group, each environment and each test cycle, so the trade-offs are visible. DeployOpen does not publish a price list, and the quote follows the scope.

Limits to confirm in your environment before changing the cache

Sticky execution and the workflow cache depend on the SDK, the server version, the platform the workers run on and whether you operate the service yourself. Check these four to six points before changing any cache or sticky setting, because a change that looks correct in one layer can have no effect or a harmful effect in another.

Exact option names in your SDK

The sticky timeout and the workflow cache size are set through SDK-specific worker options, and names and defaults differ by language and release. Read the option reference for the exact SDK version you pin, not an older example from a blog or a previous project. Confirm which values are per worker process and which are per task queue, since that determines how a cache setting scales across replicas. Record the pinned version in the change request so the tuning can be reproduced.

Server version and sticky release notes

Sticky behavior and related task queue handling can change between server minor lines, so the server version matters as much as the SDK. The current server is v1.32.1, with patch lines v1.31.4 and v1.30.8 published for earlier minors. Check the release notes for your running minor before changing sticky timeouts, and plan the change to fit the upgrade order your team already follows for the server.

Temporal releases

Memory limits and autoscaler behavior

A larger cache only helps if the container or host can hold the cached workflow state without being evicted or restarted. Confirm that the Kubernetes memory limit, the node size and any autoscaler policy account for the cache, not only the worker process footprint. If the autoscaler scales on CPU alone, it may add replicas that each warm a separate cache, which changes the cost of the same change. Test under representative load before you accept a new limit.

Workflow history size and replay cost

The cache avoids replaying history for workflows that stay on the same worker, so the benefit depends on how large the histories grow. Long-running workflows with big histories cost more to replay after an eviction, a restart or a sticky timeout, and each cached copy takes more memory. Review the history size limits your team sets and the event counts of the slowest workflow types, and decide whether those workflows should use continue-as-new before you raise the cache.

Managed or self-hosted operation

Temporal Cloud is a managed service, and the levers available to your team differ from a self-hosted Service that you run yourselves. In a managed deployment you may not control the server-side settings or the server upgrade cadence, so cache tuning falls mostly to the worker side. Confirm with the service provider which settings you can change, which the service manages, and who approves a change, before you plan the cache work around options that are not in your control.

Temporal pricing

How DeployOpen works on this

DeployOpen approaches Temporal sticky execution and the workflow cache as part of a planned worker deployment inside infrastructure you control. We start from your workflow histories, worker sizing and failure symptoms, then tune the cache and sticky settings with your engineers and document the results for handover.

How we scope

  • Inventory your workers, task queues, SDK languages and current cache and sticky settings before any change is proposed.
  • Agree in writing which workloads, namespaces and worker pools the tuning work covers and which it leaves out.
  • Confirm the measurements you can export, such as worker memory, CPU, replay activity and cache miss signals, before work starts.

How we build

  • Set cache size and worker concurrency from measured memory and CPU on your workers, not from default values.
  • Test sticky queue behavior under load, including worker restarts and the fallback to the shared task queue.
  • Verify workflow code paths that replay after cache eviction, so determinism issues surface before production traffic does.

How we hand over

  • Deliver a written record of chosen cache, sticky and concurrency settings with the measurements behind each value.
  • Document the symptoms of an undersized cache and the metrics your team should watch to catch them early.
  • Walk your platform and on-call engineers through the runbook so they can adjust settings after the engagement ends.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer after the fixed-scope work is complete.
  • Re-check cache and sticky settings when you change worker versions, SDK releases or traffic patterns.
  • Confirm with your team which support scope, response expectations and review cadence the retainer should include.

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.