# Queue-driven jobs on Azure Container Apps with KEDA scale rules

> An event-triggered Container Apps job starts a container per message: right for long runs and big images. How its KEDA rule counts the queue, which defaults to change, when a Function fits better, and when one always-on consumer is the answer.

- Canonical: https://www.alpacamango.com/docs/azure-container-apps-jobs-keda
- Author: Braxx-9000
- Published: 2026-11-24 · Updated: 2026-11-22
- Topics: Azure, Event-driven, Serverless, Architecture

**Run an event-triggered Container Apps job when each message is work that deserves its own container: a run of an hour or more, a large image, or a binary with no function host around it. Leave short messages to Azure Functions. When the queue protects a slow database or a rate-limited API, do not scale on its depth at all. Run one always-on consumer, or the spike goes straight through to what the queue was meant to shield.**

## The scale rule counts; your code takes the message

An event-driven job is KEDA's ScaledJob with the cluster taken away. Every polling interval (30 seconds by default) the scaler divides the queue's length by the rule's target and starts enough executions to cover what is waiting, less those still running, up to the job's maximum. It never hands over a message: each container opens the queue itself, takes one, does the work, deletes it and exits.

Three rules follow, and for long work the defaults break two:

- **A target of one.** KEDA's default target for the Storage queue and Service Bus scalers is five messages. Keep it and a burst of 50 starts ten executions; if each takes one message, the other 40 wait for later polls. Set `queueLength` or `messageCount` to what one execution drains, usually 1.
- **Delete last.** The Storage queue scaler counts hidden messages too, so a message in progress and its running execution cancel out. Delete it first and the queue looks one shorter while the execution still counts as running, so the next poll starts one too few.
- **Hold it for the whole run.** A Storage queue message reappears after 30 seconds unless you receive it with a longer visibility timeout (up to seven days); a [Service Bus lock](/docs/event-driven-architecture-on-azure) lasts five minutes at most, so a long run must keep renewing it. Otherwise a second execution can pick up work the first is still doing.

With managed identity, the trigger needs no connection string:

```json
"eventTriggerConfig": {
  "parallelism": 1,
  "replicaCompletionCount": 1,
  "scale": {
    "minExecutions": 0,
    "maxExecutions": 5,
    "pollingInterval": 30,
    "rules": [{
      "name": "exports",
      "type": "azure-queue",
      "metadata": { "accountName": "shopjobs", "queueName": "exports", "queueLength": "1" },
      "identity": "system"
    }]
  }
}
```

Set `replicaTimeout` above your longest run and `replicaRetryLimit` to at least 1: platform maintenance can stop a long replica part-way, so the work must be safe to do twice. [Idempotent consumers](/docs/azure-service-bus-idempotent-consumers) covers how.

## When a job beats a Function

The deciding question is what scale-in does to a run in flight. Flex Consumption sets no hard time limit, but gives a running execution 60 minutes' grace, and ten during platform updates. A job's scale rule starts executions and never stops one; each ends when it exits or reaches the timeout you chose. For work measured in hours, that is the safer home.

Size points the same way. Flex Consumption's largest instance has 4,096 MB, and your own image is a preview there; a job replica on a default environment's Consumption profile takes up to 4 vCPU and 8 GiB. No programming model either: ffmpeg, a Rust binary or a vendor's CLI only has to read one message and exit. Language rarely decides it; Flex runs Go now, and custom handlers cover the rest.

For small messages the bill runs the other way. Each execution is a new container charged at the active rate from start to completion, so thousands of sub-second messages an hour belong in a Function or a consumer that batches. [Flex Consumption, Premium or Container Apps](/docs/azure-functions-flex-consumption-or-premium) covers that choice.

## When one consumer is the whole answer

Queue-based load levelling lets producers burst while the service behind the queue sees a steady rate. A consumer that scales on depth undoes it: at the default of 100 executions, a burst of 100 messages becomes 100 containers opening connections to one database at once. `maxExecutions` is not a cost setting. It is the concurrency your downstream will see.

When the queue protects something, run a container app with one replica as minimum and maximum; the backlog absorbs bursts. Set the minimum explicitly: with no ingress and no scale rule, an app scales to zero with nothing to wake it. At East US pay-as-you-go prices (Microsoft's retail prices, 22 November 2026), a 0.5 vCPU, 1 GiB replica costs about $11.66 for a 30-day month idle and $38.88 busy, before the free grant. Idle means using under 0.01 vCPU and receiving under 1,000 bytes a second. Add replicas only when the backlog grows between bursts: producers are outrunning the consumer on average.

## On AWS and Google Cloud

Lambda now allows 30 minutes per invocation (90 on Lambda Managed Instances behind an event source mapping); beyond that, EventBridge Pipes can start an ECS task from SQS, and the steady consumer is an ECS service with a fixed task count. Cloud Run jobs have no queue trigger (Eventarc starts one through Workflows); the steady consumer is a worker pool, which CREMA, Google's KEDA-based autoscaler, can size from Pub/Sub backlog. Only Container Apps runs both shapes on one scaler.

## The diagram

Two queues, two answers: a job's scale rule counts the exports queue and starts one execution per message; one always-on consumer drains the orders queue into the database steadily. [Open it in archhy](https://archhy.com/d/vhmlyRvW57a0?utm_source=alpacamango) and press Make a copy to adapt it.
