Skip to content

Commit 239ce51

Browse files
authored
Merge pull request #233975 from hhunter-ms/hh-72935
[Dapr/ACA] New doc for scaling Dapr components with KEDA
2 parents 811fee1 + 0d54f61 commit 239ce51

File tree

6 files changed

+164
-5
lines changed

6 files changed

+164
-5
lines changed

articles/container-apps/TOC.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@
7575
href: authentication.md
7676
- name: Workload profiles
7777
href: workload-profiles-overview.md
78-
- name: Dapr integration
79-
href: dapr-overview.md
78+
- name: Dapr
79+
items:
80+
- name: Dapr integration
81+
href: dapr-overview.md
82+
- name: Scale Dapr apps with KEDA using Bicep
83+
href: dapr-keda-scaling.md
8084
- name: Azure Arc-enabled Kubernetes clusters
8185
href: azure-arc-overview.md
8286
- name: How-to guides
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
title: Scale Dapr applications with KEDA scalers using Bicep
3+
description: Learn how to use KEDA scalers to scale an Azure Container App and its Dapr sidecar.
4+
author: hhunter-ms
5+
ms.author: hannahhunter
6+
ms.service: container-apps
7+
ms.topic: conceptual
8+
ms.date: 04/17/2023
9+
---
10+
11+
# Scale Dapr applications with KEDA scalers
12+
13+
[Azure Container Apps automatically scales HTTP traffic to zero.](./scale-app.md) However, to scale non-HTTP traffic (like [Dapr](https://docs.dapr.io/) pub/sub and bindings), you can use [KEDA scalers](https://keda.sh/) to scale your application and its Dapr sidecar up and down, based on the number of pending inbound events and messages.
14+
15+
This guide demonstrates how to configure the scale rules of a Dapr pub/sub application with a KEDA messaging scaler. For context, refer to the corresponding sample pub/sub applications:
16+
- [Microservice communication using pub/sub in **C#**](https://github.com/Azure-Samples/pubsub-dapr-csharp-servicebus)
17+
- [Microservice communication using pub/sub in **JavaScript**](https://github.com/Azure-Samples/pubsub-dapr-nodejs-servicebus)
18+
- [Microservice communication using pub/sub in **Python**](https://github.com/Azure-Samples/pubsub-dapr-python-servicebus)
19+
20+
21+
In the above samples, the application uses the following elements:
22+
1. The `checkout` publisher is an application that is meant to run indefinitely and never scale down to zero, despite never receiving any incoming HTTP traffic.
23+
1. The Dapr Azure Service Bus pub/sub component.
24+
1. An `order-processor` subscriber container app picks up messages received via the `orders` topic and processed as they arrive.
25+
1. The scale rule for Azure Service Bus, which is responsible for scaling up the `order-processor` service and its Dapr sidecar when messages start to arrive to the `orders` topic.
26+
27+
:::image type="content" source="media/dapr-keda-scaling/scaling-dapr-apps-keda.png" alt-text="Diagram showing the scaling architecture of the order processing application.":::
28+
29+
Let's take a look at how to apply the scaling rules in a Dapr application.
30+
31+
## Publisher container app
32+
33+
The `checkout` publisher is a headless service that runs indefinitely and never scales down to zero.
34+
35+
By default, [the Container Apps runtime assigns an HTTP-based scale rule to applications](./scale-app.md), which drives scaling based on the number of incoming HTTP requests. In the following example, `minReplicas` is set to `1`. This configuration ensures the container app doesn't follow the default behavior of scaling to zero with no incoming HTTP traffic.
36+
37+
```bicep
38+
resource checkout 'Microsoft.App/containerApps@2022-03-01' = {
39+
name: 'ca-checkout-${resourceToken}'
40+
location: location
41+
identity: {
42+
type: 'SystemAssigned'
43+
}
44+
properties: {
45+
//...
46+
template: {
47+
//...
48+
// Scale the minReplicas to 1
49+
scale: {
50+
minReplicas: 1
51+
maxReplicas: 1
52+
}
53+
}
54+
}
55+
}
56+
```
57+
58+
## Subscriber container app
59+
60+
The following `order-processor` subscriber app includes a custom scale rule that monitors a resource of type `azure-servicebus`. With this rule, the app (and its sidecar) scales up and down as needed based on the number of pending messages in the Bus.
61+
62+
```bicep
63+
resource orders 'Microsoft.App/containerApps@2022-03-01' = {
64+
name: 'ca-orders-${resourceToken}'
65+
location: location
66+
tags: union(tags, {
67+
'azd-service-name': 'orders'
68+
})
69+
identity: {
70+
type: 'SystemAssigned'
71+
}
72+
properties: {
73+
managedEnvironmentId: containerAppsEnvironment.id
74+
configuration: {
75+
//...
76+
// Enable Dapr on the container app
77+
dapr: {
78+
enabled: true
79+
appId: 'orders'
80+
appProtocol: 'http'
81+
appPort: 5001
82+
}
83+
//...
84+
}
85+
template: {
86+
//...
87+
// Set the scale property on the order-processor resource
88+
scale: {
89+
minReplicas: 0
90+
maxReplicas: 10
91+
rules: [
92+
{
93+
name: 'topic-based-scaling'
94+
custom: {
95+
type: 'azure-servicebus'
96+
metadata: {
97+
topicName: 'orders'
98+
subscriptionName: 'membership-orders'
99+
messageCount: '30'
100+
}
101+
auth: [
102+
{
103+
secretRef: 'sb-root-connectionstring'
104+
triggerParameter: 'connection'
105+
}
106+
]
107+
}
108+
}
109+
]
110+
}
111+
}
112+
}
113+
}
114+
```
115+
116+
## How the scaler works
117+
118+
Notice the `messageCount` property on the scaler's configuration in the subscriber app:
119+
120+
```bicep
121+
{
122+
//...
123+
properties: {
124+
//...
125+
template: {
126+
//...
127+
scale: {
128+
//...
129+
rules: [
130+
//...
131+
custom: {
132+
//...
133+
metadata: {
134+
//...
135+
messageCount: '30'
136+
}
137+
}
138+
]
139+
}
140+
}
141+
}
142+
}
143+
```
144+
145+
This property tells the scaler how many messages each instance of the application can process at the same time. In this example, the value is set to `30`, indicating that there should be one instance of the application created for each group of 30 messages waiting in the topic.
146+
147+
For example, if 150 messages are waiting, KEDA scales the app out to five instances. The `maxReplicas` property is set to `10`, meaning even with a large number of messages in the topic, the scaler never creates more than `10` instances of this application. This setting ensures you don't scale up too much and accrue too much cost.
148+
149+
## Next steps
150+
151+
[Learn more about using Dapr components with Azure Container Apps.](./dapr-overview.md)

articles/container-apps/dapr-overview.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ Now that you've learned about Dapr and some of the challenges it solves:
355355
- Try [Deploying a Dapr application to Azure Container Apps using the Azure CLI][dapr-quickstart] or [Azure Resource Manager][dapr-arm-quickstart].
356356
- Walk through a tutorial [using GitHub Actions to automate changes for a multi-revision, Dapr-enabled container app][dapr-github-actions].
357357
- Learn how to [perform event-driven work using Dapr bindings][dapr-bindings-tutorial]
358+
- [Scale your Dapr applications using KEDA scalers][dapr-keda]
358359
- [Answer common questions about the Dapr integration with Azure Container Apps][dapr-faq]
359360

360361
<!-- Links Internal -->
@@ -363,6 +364,7 @@ Now that you've learned about Dapr and some of the challenges it solves:
363364
[dapr-arm-quickstart]: ./microservices-dapr-azure-resource-manager.md
364365
[dapr-github-actions]: ./dapr-github-actions.md
365366
[dapr-bindings-tutorial]: ./microservices-dapr-bindings.md
367+
[dapr-keda]: ./dapr-keda-scaling.md
366368
[dapr-faq]: ./faq.yml#dapr
367369

368370
<!-- Links External -->
33.4 KB
Loading

articles/container-apps/microservices-dapr-bindings.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: hhunter-ms
55
ms.author: hannahhunter
66
ms.service: container-apps
77
ms.topic: how-to
8-
ms.date: 03/08/2023
8+
ms.date: 04/11/2023
99
zone_pivot_group_filename: container-apps/dapr-zone-pivot-groups.json
1010
zone_pivot_groups: dapr-languages-set
1111
---
@@ -579,3 +579,4 @@ azd down
579579

580580
- Learn more about [deploying Dapr applications to Azure Container Apps](./microservices-dapr.md).
581581
- Learn more about [Azure Developer CLI](/azure/developer/azure-developer-cli/overview) and [making your applications compatible with `azd`](/azure/developer/azure-developer-cli/make-azd-compatible).
582+
- [Scale your Dapr applications using KEDA scalers](./dapr-keda-scaling.md)

articles/container-apps/microservices-dapr-pubsub.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: hhunter-ms
55
ms.author: hannahhunter
66
ms.service: container-apps
77
ms.topic: how-to
8-
ms.date: 03/16/2023
8+
ms.date: 04/11/2023
99
zone_pivot_group_filename: container-apps/dapr-zone-pivot-groups.json
1010
zone_pivot_groups: dapr-languages-set
1111
---
@@ -679,4 +679,5 @@ azd down
679679
## Next steps
680680

681681
- Learn more about [deploying Dapr applications to Azure Container Apps](./microservices-dapr.md).
682-
- Learn more about [Azure Developer CLI](/azure/developer/azure-developer-cli/overview) and [making your applications compatible with `azd`](/azure/developer/azure-developer-cli/make-azd-compatible).
682+
- Learn more about [Azure Developer CLI](/azure/developer/azure-developer-cli/overview) and [making your applications compatible with `azd`](/azure/developer/azure-developer-cli/make-azd-compatible).
683+
- [Scale your Dapr applications using KEDA scalers](./dapr-keda-scaling.md)

0 commit comments

Comments
 (0)