Skip to main content

Serverless Workers

View Markdown

When a Task Queue needs more Worker capacity, Temporal starts Workers on the compute provider you configure for the Worker Deployment Version. The compute provider determines how the Workers start, how long they can run, and what resources they can use.

How the compute providers differ​

The Worker Controller Instance (WCI) monitors Task Queue demand. On AWS Lambda, Amazon Bedrock AgentCore Runtime, and Modal, it invokes compute to start a Worker. On GCP Cloud Run, it adjusts the size of a Worker Pool whose instances poll continuously while they run.

Compute providerWhat you deployHow the Worker runs
AWS LambdaA Lambda function with a Temporal Lambda Worker integration.Each invocation runs a Worker that starts up, polls for Tasks, and shuts down within the function timeout.
GCP Cloud RunA container image with a standard Temporal Worker and a Worker Pool for each Worker Deployment Version and compute region.Long-lived Workers poll as long as their instances are running. The pool can scale to zero if you set its minimum to zero.
Amazon Bedrock AgentCore RuntimeAn AgentCore Runtime endpoint whose handler starts a Temporal Worker.The Worker runs in the background. Your handler controls idle shutdown and drain, subject to the Runtime session's lifecycle limits. A microVM session can run for up to eight hours.
ModalA Python function in a Modal App, with its image and compute resources defined in Python.Each invocation starts a fresh Worker with a configured timeout. Modal supplies container capacity and can reuse a container for later invocations.

Choose a compute provider​

Choose for the workload your Worker serves. Even within one application, a nightly batch and a customer-facing Task Queue can have different needs for compute and startup latency.

Start with the cloud your Activities use​

If most of the systems your Activities call already run in GCP, start with Cloud Run. For example, a Worker that reads from Cloud Storage and writes to a private Cloud SQL database can use your existing GCP identity and deployment tooling, and reach private resources through Direct VPC egress. Running the Worker in GCP can also avoid cross-cloud data transfers. You can deploy an existing containerized Temporal Worker to a Worker Pool without adding a function handler.

If your dependencies are mainly in AWS, start with Lambda for short, intermittent work such as processing webhook events, updating DynamoDB, or running scheduled integrations. If the application already runs on AgentCore Runtime, deploy the Worker there to use the same runtime environment. Factor in the Runtime HTTP contract and the idle and shutdown behavior your handler must implement.

Choose Modal for Python workloads that benefit from its GPU selection or image tooling, such as bursty batch inference or GPU-backed media processing. Check how the Worker will reach your data and private services from Modal, and confirm that your Temporal Cloud account can authorize the Modal workspace. If the data already lives in GCP, also check whether the GPUs available for Cloud Run Worker Pools meet your needs.

For any provider, check availability in your Namespace and compute region, and confirm that the Worker can reach both the Temporal Service and the services its Activities call. If you already have Worker code, check the SDK before choosing. Cloud Run runs standard Temporal Workers. The Lambda deployment guide covers Go, Python, TypeScript, Java, and .NET. The Modal integration uses Python, and the AgentCore guide shows a Python Runtime handler.

Multi-cloud Replication for AWS and GCP compute

AWS Lambda, AgentCore Runtime, and GCP Cloud Run require the Namespace to be active in the same cloud provider as the compute. With Multi-cloud Replication, a failover to a different cloud provider prevents Temporal from starting new Workers on the original provider.

Match the Worker lifetime to your Activities​

A Workflow Execution can span many Worker lifetimes. Size the compute for the longest Activity attempt you expect a Worker to run, including the time needed to start the Worker and shut it down gracefully.

  • For short Activities, Lambda and Modal can start Workers on demand. Leave room for initialization and draining in the function timeout. An Activity that starts late in an invocation has less time before the Worker shuts down.
  • For longer Activities, a Cloud Run Worker Pool has no function invocation deadline. Scale-in can still interrupt a running Activity. AgentCore can be a fit for longer AWS workloads that already use its Runtime. Account for both the session's maximum lifetime and its idle timeout. Polling Temporal does not reset the AgentCore idle timeout.
  • For expensive work that can resume, use Activity Heartbeats to record progress and have the next attempt read the last checkpoint after a Worker shuts down.

Balance startup latency and cost​

For a queue that's idle for hours at a time, start with on-demand invocations or a Cloud Run pool that can scale to zero. The first Task after an idle period may wait for compute to start and the Worker to connect. For a GCP queue with steady traffic or a tight Task pickup target, keep a minimum number of Cloud Run instances polling. In Modal, keeping containers warm can reduce container startup time. Each invocation still starts and connects a new Worker.

If an existing fixed-size AWS Worker fleet handles most traffic, you can add Lambda Workers on the same Task Queue to handle bursts.

Estimate cost using the time Workers actually run. A Lambda invocation can keep polling after it finishes a Task, and Cloud Run charges for running pool instances even when they have no Tasks to process. Include the compute you keep warm, any GPU capacity you reserve, and data transfers between regions or providers.

Verify your choice under load​

Test with your actual Worker code and expected traffic.

  1. Start from idle and measure how long it takes for the first Task to start.
  2. Send a representative burst and check whether capacity arrives fast enough to drain the backlog. Check the provider's concurrency or instance limits and GPU availability if your Worker needs an accelerator.
  3. Run a long Activity attempt and check how it behaves when compute scales in or reaches its runtime limit.

Try it locally​

To evaluate Serverless Workers on AWS Lambda without an AWS account, you can run the entire loop on your machine with LocalStack and the Temporal development server. See Test a Serverless Worker locally with LocalStack.