Mastering Scaling Rules in Azure Container Apps
Scaling rules in Azure Container Apps are essential for managing your application's performance and resource efficiency. They allow your app to automatically adjust the number of replicas based on real-time demand, ensuring that you can handle varying loads without manual intervention. This dynamic scaling helps maintain performance while minimizing costs, especially since you aren't billed when your app scales to zero.
Azure Container Apps utilizes KEDA (Kubernetes Event-driven Autoscaling) to manage scaling through a set of declarative rules. You can set parameters like minReplicas and maxReplicas to define the limits of your scaling. For instance, setting minReplicas to 0 and maxReplicas to 5 allows your app to scale between these limits based on traffic. You can implement HTTP scaling rules that trigger additional replicas when concurrent HTTP requests exceed a specified threshold. Similarly, TCP scaling rules can be set to manage concurrent TCP connections. This flexibility allows you to tailor your scaling strategy to your specific application needs.
In production, be aware of some important considerations. You won't incur charges if your app scales down to zero, but idle replicas may still incur a lower billing rate. If you're using Functions on Container Apps, scaling rules are automatically configured, and manual adjustments are not possible. Additionally, TCP scaling rules must be configured using the Azure CLI or Bicep, as they aren't supported in the Azure portal. Always remember to set activeRevisionsMode to single when using non-HTTP event scale rules to avoid unexpected behavior.
Key takeaways
- →Define `minReplicas` and `maxReplicas` to control scaling limits effectively.
- →Implement HTTP scaling rules to manage traffic by setting concurrent request thresholds.
- →Use the Azure CLI or Bicep for configuring TCP scaling rules, as the Azure portal does not support them.
- →Remember that scaling to zero incurs no charges, but idle replicas may still cost you.
- →Set `activeRevisionsMode` to single for non-HTTP event scale rules to ensure proper functionality.
Why it matters
Properly configured scaling rules can significantly reduce costs and improve application responsiveness during traffic spikes. This ensures a better user experience and efficient resource management in production environments.
Code examples
1resource symbolicname 'Microsoft.App/containerApps@2025-02-02-preview' = {
2 ...
3 properties: {
4 ...
5 template: {
6 ...
7 scale: {
8 maxReplicas: 0
9 minReplicas: 5
10 rules: [
11 name: 'http-rule'
12 http: {
13 metadata: {
14 concurrentRequests: '100'
151az containerapp create \
2 --name <CONTAINER_APP_NAME> \
3 --resource-group <RESOURCE_GROUP> \
4 --environment <ENVIRONMENT_NAME> \
5 --image <CONTAINER_IMAGE_LOCATION>
6 --min-replicas 0 \
7 --max-replicas 5 \
8 --scale-rule-name azure-http-rule \
9 --scale-rule-type http \
10 --scale-rule-http-concurrency 1001resource symbolicname 'Microsoft.App/containerApps@2025-02-02-preview' = {
2 ...
3 properties: {
4 ...
5 template: {
6 ...
7 scale: {
8 maxReplicas: 0
9 minReplicas: 5
10 rules: [
11 name: 'tcp-rule'
12 http: {
13 metadata: {
14 concurrentConnections: '100'
15When NOT to use this
Container Apps jobs don't support HTTP scaling rules or TCP scaling rules. If your application relies on these features, consider alternative solutions that better fit your scaling needs.
Want the complete reference?
Read official docsMastering Durable Functions: Building Stateful Workflows in Azure
Durable Functions empower you to create stateful workflows in a serverless environment, solving the complexity of managing state and retries. With the Durable Functions runtime, you can ensure your workflows are resilient and reliable over long periods.
Mastering Azure Functions Scale: Choosing the Right Plan
Scaling Azure Functions effectively can make or break your serverless architecture. Understand the differences between the Flex Consumption plan and the Premium plan to optimize performance and cost. This knowledge is crucial for maintaining responsive applications in production.
Mastering Reliability in Azure Functions: Best Practices You Can't Ignore
Achieving reliability in Azure Functions is crucial for any production environment. Leveraging the right hosting plans, like the Flex Consumption plan, can significantly enhance your app's performance and scalability. Dive into the specifics that will keep your functions running smoothly.
Get the daily digest
One email. 5 articles. Every morning.
No spam. Unsubscribe anytime.