Azure Container Apps with KEDA + Azure Service Bus scaling to 0 even when messages are coming in

Max Voloshyn 5 Reputation points
2025-08-04T23:30:35.39+00:00

Hi,

I'm using Azure Container Apps with a custom KEDA-based scaling rule that listens to an Azure Service Bus queue.

Here’s my setup:

  • minReplicas: 0

maxReplicas: 2

pollingInterval: 30 seconds

cooldownPeriod: 300 seconds

The scaling generally works — it scales up when messages arrive and down when idle.

However, I’m seeing unexpected scale-to-zero behavior even when messages are still coming in (though sporadically).

📈 My scenario:

Messages arrive with irregular frequency: 1 message every 1 to 15 seconds.

Each message is processed very quickly, so the queue often appears empty when KEDA checks it.

As a result, the app sometimes scales to 0 before the full 300-second cooldown, even though messages continue to trickle in.

❓ My question:

Is my assumption correct that because messages are processed too quickly, KEDA may not "see" them during the polling intervals — causing it to believe the queue is empty and trigger scale-down?

If so, is there a recommended way to prevent this kind of premature scale-down for low-frequency but steady message traffic?

Thanks in advance!Hi,

I'm using Azure Container Apps with a custom KEDA-based scaling rule that listens to an Azure Service Bus queue.

Here’s my setup:

minReplicas: 0

maxReplicas: 2

pollingInterval: 30 seconds

cooldownPeriod: 300 seconds

The scaling generally works — it scales up when messages arrive and down when idle.

However, I’m seeing unexpected scale-to-zero behavior even when messages are still coming in (though sporadically).

📈 My scenario:

Messages arrive with irregular frequency: 1 message every 1 to 15 seconds.

Each message is processed very quickly, so the queue often appears empty when KEDA checks it.

As a result, the app sometimes scales to 0 before the full 300-second cooldown, even though messages continue to trickle in.

❓ My question:

Is my assumption correct that because messages are processed too quickly, KEDA may not "see" them during the polling intervals — causing it to believe the queue is empty and trigger scale-down?

If so, is there a recommended way to prevent this kind of premature scale-down for low-frequency but steady message traffic?

Thanks in advance!

Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
{count} votes

1 answer

Sort by: Most helpful
  1. Anurag Rohikar 205 Reputation points Microsoft External Staff Moderator
    2025-08-05T14:57:15.45+00:00

    Hello Max Voloshyn, thank you for the quick follow-up and for providing the scaler configuration details, this really helps to narrow things down.

    A couple of clarifications and next steps:

    About messageAge Scaler:

    You're absolutely right, there isn’t a native "messageAge" scaler available for Azure Service Bus in KEDA as of now. My earlier suggestion was more of a conceptual alternative that sometimes gets implemented via custom scalers or in other services where trigger-based execution models can handle message age/latency better. For Azure Container Apps + KEDA, we're currently limited to queue length-based metrics when using the Azure Service Bus scaler.

    Analyzing Your Current Setup:

    From your config:

    • activationMessageCount: 0 — This defines when the app should "wake up" from scale-to-zero. So, even a single message should activate the app.
    • messageCount: 1000 — This defines the scaling target; KEDA will scale linearly up to maxReplicas as the queue approaches this count.

    However, with sporadic messages that arrive in small bursts (1-15 seconds apart) and get processed rapidly, it’s likely that:

    1. The queue rarely accumulates enough messages for the messageCount trigger to activate.
    2. KEDA may still miss messages during its polling intervals, especially at low queue lengths.

    Recommended Actions:

    The root cause seems to be a combination of a high polling interval and the messageCount being too large for your workload pattern. Based on this, here are the recommended adjustments:

    1. Lower the messageCount value: Since your queue processes messages quickly and doesn’t build up to high volumes, setting messageCount to something like 5 or 10 may help KEDA react more sensitively to incoming traffic.
    2. Reduce the pollingInterval further: Try setting it to 5s or 10s to catch those quick-arriving messages.
    3. Consider minReplicas: 1: If reducing polling intervals is not sufficient or if you need zero cold-start delays, this will keep an instance warm at all times.

    Let me know if this helps. Happy to assist further. Thank You!

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.