Task Queues
Task queues are the routing mechanism that connects the Temporal Server to your workers. They act as a bridge between workflow executions in the History Service and worker processes that execute workflow and activity code.Task Queue Basics
A task queue is a logical queue that workers poll for tasks. When the History Service needs workflow or activity code to execute, it dispatches tasks to the appropriate task queue.Two Types of Tasks
Workflow Tasks
Prompts worker to advance workflow execution by replaying history and generating new commands.
Activity Tasks
Requests worker to execute specific activity function with given input.
These “task queue tasks” are user-visible concepts, distinct from internal History Service tasks (Transfer Tasks, Timer Tasks) which are implementation details.
Task Queue Architecture
The Matching Service manages all task queues:Task Queue Partitioning
To handle high throughput, each task queue is split into multiple partitions:Why Partition Task Queues?
Why Partition Task Queues?
Scalability: Single queue partition limited by one Matching Service instance. Partitions spread load across instances.Throughput: Each partition handles subset of tasks. More partitions = higher total throughput.Default: 4 partitions per task queue, configurable per namespace.Trade-offs: More partitions increase dispatching overhead. Optimal partition count depends on task rate.
Task Dispatching
When History Service schedules a task, it goes through this flow:History creates Transfer Task
Workflow/Activity task decision creates a Transfer Task in History shard’s queue
Sync Match vs Async Match
The Matching Service optimizes for low latency through sync matching:Sync Match (Fast Path)
Async Match (Slow Path)
Task Queue Forwarding
To improve sync match rate, Matching uses hierarchical forwarding:Forwarding Mechanism
How Forwarding Works
How Forwarding Works
Forward Task to Parent: Child partition has task but no poller → forwards task to parent/rootForward Poller to Parent: Child partition has poller but no task → forwards poller to parent/rootMatch at Root: Root partition has better chance of matching tasks with pollers from all childrenBenefits: Higher sync match rate, better load distribution, faster task deliveryCost: Additional RPC hops, slightly higher latency for forwarded tasks
Task Queue Lifecycle
Loading
Task queue partitions are loaded on-demand:- First poll or task for a task queue triggers loading
- Partition manager created for that partition
- State loaded from database (backlog, ack levels, etc.)
- Matcher started to match tasks with pollers
Unloading
Partitions unload when idle:- No pollers for configured duration (e.g., 5 minutes)
- No tasks dispatched
- Memory pressure on Matching Service
Unloading is an optimization. When next task/poll arrives, partition reloads automatically. Users don’t see interruption.
Task Queue Backlog
When task arrival rate exceeds worker processing rate, backlog accumulates:Backlog Management
Backlog Storage
Backlog Storage
Tasks that can’t sync match are written to persistence:Cassandra: Separate table per task queue partition
SQL: Rows in tasks table with task queue + partition columnsBacklog is FIFO ordered by task ID (monotonically increasing).
Backlog Reading
Backlog Reading
Backlog Metrics
Backlog Metrics
Key metrics:
- Task Queue Backlog Age: How old is the oldest task?
- Task Queue Backlog Size: How many tasks waiting?
- Task Dispatch Latency: Time from scheduling to worker pickup
Task Queue Versioning
For worker versioning, each task queue has multiple physical queues:Default Queue
Unversioned tasks and workers without Build ID use default queue
Versioned Queues
Each Build ID gets dedicated queue. Tasks routed by versioning rules.
Task Queue Configuration
Dynamic Configuration
Rate Limiting
Task queues support rate limiting task dispatch:- Global RPS limit per task queue
- Smoothed delivery prevents spikes
- Shared across partitions
- Configurable per namespace
Sticky Task Queues
Workers can request “sticky” execution for performance:- Normal task queue:
my-task-queue - Sticky task queue:
__sticky__:${workerID}
- Route workflow tasks back to same worker
- Enable workflow cache reuse (skip replay)
- Timeout quickly and fallback to normal queue
- Per-worker, not shared across workers
Task Queue Observability
Key signals to monitor:Metrics
task_queue_backlog_age_seconds: Age of oldest tasktask_queue_backlog_size: Number of pending taskspoll_success_rate: Poller success ratesync_match_rate: Percentage of sync vs async matchestask_dispatch_latency: Time from schedule to worker
Troubleshooting
High Backlog Age
Cause: Not enough workers or workers too slowSolution: Scale workers, optimize activity code, increase concurrency
Low Sync Match Rate
Cause: Tasks arriving when no pollers waitingSolution: Increase poller count, reduce partition count, enable forwarding
High Task Latency
Cause: Network issues, Matching overload, database slownessSolution: Check Matching Service health, database performance, network latency
No Recent Poller
Cause: All workers down or misconfiguredSolution: Verify workers running, check task queue name matches, review logs
Related Concepts
- Workers - Poll task queues and execute tasks
- Workflows - Generate workflow tasks
- Activities - Generate activity tasks