Imagine a NestJS app that sends reports and processes uploads through a BullMQ queue, with workers running as their own Azure Container App. At night, two worker replicas sit idle. At 9 a.m., thousands of jobs arrive, the backlog grows for an hour, and CPU-based autoscaling does nothing, because each worker is mostly waiting on the network and CPU never looks busy.
The signal that matters for a queue worker is how much work is waiting, not how hard the CPU is working.
Scaling queue workers well comes down to a few decisions:
- Scale on the number of waiting jobs, using a KEDA-based rule in Container Apps.
- Make sure the count includes every job that's ready to run, not just one Redis key.
- Cap replicas so scaling out doesn't exhaust your database.
- Let workers finish or hand back jobs when they're scaled in.
- Decide whether scaling to zero is worth the cold start.
Why CPU is the wrong signal
Queue workers spend much of their time waiting on databases, APIs, and storage. A worker can be completely busy, with every concurrency slot taken, while its CPU sits low. Meanwhile, the backlog grows. Scaling on CPU reacts to the wrong thing: it can add workers when a single job is CPU-heavy, and fail to add them when hundreds of jobs are waiting.
How Container Apps scales
Azure Container Apps uses KEDA, the Kubernetes event-driven autoscaler, under the hood. Microsoft's scaling documentation describes HTTP, TCP, and custom rules, and says a custom rule can be based on any ScaledObject-based KEDA scaler. As of November 2026, the same page documents how scaling behaves:
- Replicas:
minReplicasdefaults to 0 andmaxReplicasto 10, with a configurable maximum of 1,000. - The target: the number of replicas is the metric divided by the target per replica, rounded up.
- Polling: rules are checked every 30 seconds.
- Scaling up happens in growing steps, such as 1, then 4, then 8, then 16 replicas.
- Scaling down waits for a 300-second stabilization window, then removes all the replicas that are no longer needed.
- The cooldown of 300 seconds applies only when scaling from the last replica down to zero.
So a backlog takes up to a polling interval to notice, and scaling in is deliberately slow. Plan around both.
Where BullMQ keeps its backlog
To scale on queue depth, you need to know where BullMQ stores waiting jobs. In BullMQ's source, standard jobs are pushed onto a Redis list named after the queue, such as bull:reports:wait. Prioritized jobs are different: BullMQ's priority logic adds them to a sorted set, such as bull:reports:prioritized. Delayed jobs aren't ready to run yet, so they usually shouldn't drive scaling.
Two details catch people:
- Prioritized jobs live in a different key, so a rule watching only the wait list won't see them.
- On a Redis cluster, the prefix includes braces. BullMQ's Redis Cluster guidance tells you to put the queue prefix inside braces, so the key your scaler reads must include them too.
BullMQ's architecture guide explains the job states if you need the full picture.
Option A: KEDA's Redis list scaler
The simplest rule uses KEDA's Redis Lists scaler to read the length of the wait list. Its main settings:
- The list name: the wait key, including any prefix and braces.
- The target list length: how many waiting jobs one replica should handle; the default is 5.
- The activation list length: the threshold for waking up from zero; the default is 0.
- Connection details: the address, TLS settings, and a password supplied as a secret.
KEDA's scaling concepts describe two phases: activation decides between zero and one replica, and the regular scaler then decides between one and the maximum. Setting a small activation threshold avoids starting a replica for a single stray job if that's acceptable for your latency.
For authentication, Microsoft's documentation shows managed identity for some Azure scalers, such as Queue Storage, Service Bus, and Event Hubs. The KEDA Redis scaler documents passwords and TLS, so plan to store the Redis access key as a Container Apps secret. Azure Managed Redis uses TLS on port 10000 by default, per its connection documentation, so enable TLS in the scaler.
The limitation is the prioritized sorted set. You can add a second rule for it, but multiple rules typically scale to whichever asks for the most replicas, not their sum. If you use priorities heavily, consider the next option.
Option B: a metrics endpoint
KEDA's Metrics API scaler reads a number from an HTTP endpoint, with a target value and an optional activation value. That lets you scale on exactly the backlog you care about. An endpoint can use BullMQ's job getters to return waiting plus prioritized jobs, and leave out delayed ones.
Host that endpoint on the API, not on the worker app. If the worker scales to zero, an endpoint inside it can't answer the question that would wake it up.
Setting min and max replicas
The maximum replica count is a database decision as much as a scaling one. Each worker replica runs some number of concurrent jobs, and each job may hold a database connection. Multiply replicas by worker concurrency and by connections per job, then add the API's own pools, and compare that with your database's limit.
As of November 2026, Microsoft's limits page lists the smallest Burstable size, B1ms, at 35 user connections, with 15 more reserved, and Burstable servers don't include the built-in PgBouncer pooler. The default maximum of 10 replicas can be too many for a small database even with modest concurrency. Set maxReplicas from your connection budget, not from how fast you'd like the backlog to drain.
Concurrency versus replicas
BullMQ's concurrency guide notes that a worker processes one job at a time by default, and that running more workers is the recommended way to scale. Raising per-worker concurrency helps for I/O-heavy jobs inside one process; adding replicas helps for CPU-heavy work and isolates failures. Both multiply database connections, so tune them together.
Scaling in without killing jobs
When Container Apps scales in, it stops replicas. Its application lifecycle documentation says that if an app doesn't respond to SIGTERM within 30 seconds, a SIGKILL terminates the container. The Container Apps template also has a termination grace period setting; check the template reference for its current limits before relying on a longer value.
That's short for long jobs. BullMQ's graceful shutdown guide explains that closing a worker waits for active jobs to finish, without a built-in timeout. If the platform kills the process first, the job can be recovered as stalled and run again by another worker, as long as stalled-job checking is configured. So:
- Handle SIGTERM and close the worker. In NestJS, shutdown hooks must be enabled for this to happen.
- Raise the grace period to cover typical jobs, within what Container Apps allows.
- Make jobs safe to run twice, because some will be.
- Split long jobs into shorter steps where you can.
Scale to zero, or not
Scaling to zero saves money: Container Apps billing doesn't charge resource consumption for a revision scaled to zero, and each subscription gets a monthly free grant of vCPU-seconds and memory. It also adds a delay, because the first job waits for a polling interval and a container start.
Two things to know:
- A worker without ingress needs a rule. Microsoft's scaling documentation warns that if ingress is disabled and you don't define a minimum replica count or a custom scale rule, the app scales to zero and has no way to start back up.
- A warm minimum costs less than full price. With
minReplicasabove zero, replicas that are nearly idle can be billed at a lower idle rate, under conditions described on the billing page.
If jobs must start within seconds, keep one replica warm. If minutes are fine, scale to zero.
When to use event-driven jobs instead
For long-running tasks, Container Apps also offers event-driven jobs, which start a job execution per event or batch of events. Microsoft positions them for events that each need to run for a long time, with settings for a replica timeout and retries. They avoid the scale-in problem entirely, because each execution runs to completion. The trade-off is that you no longer run a long-lived BullMQ worker process.
Watch it working
Autoscaling hides problems as well as solving them. Track:
- The age of the oldest waiting job, not just the count.
- Replica count over time, to see whether you're hitting the maximum.
- Failed and stalled jobs, which rise if scale-in is killing work.
- Database connections, which rise with replicas.
Checklist
- Scale on queue depth with a custom KEDA rule, not CPU.
- Point the rule at the right key, including any cluster braces.
- Count prioritized jobs too, or use a metrics endpoint for the exact backlog.
- Leave delayed jobs out of the scaling signal.
- Use TLS and a secret for the Redis scaler.
- Set maxReplicas from your database connection budget.
- Tune concurrency and replicas together.
- Handle SIGTERM, raise the grace period, and make jobs idempotent.
- Give a no-ingress worker a rule so it can start from zero.
- Choose between scale to zero and a warm minimum based on start-up latency.
- Consider event-driven jobs for long tasks.
- Alert on backlog age and on hitting maximum replicas.



