Skip to content

Commit ddbceb8

Browse files
committed
first editorial pass and add to toc
Signed-off-by: Hannah Hunter <[email protected]>
1 parent d7b4120 commit ddbceb8

File tree

2 files changed

+29
-43
lines changed

2 files changed

+29
-43
lines changed

articles/container-apps/TOC.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@
161161
href: storage-mounts.md
162162
- name: Plan for disaster recovery
163163
href: disaster-recovery.md
164+
- name: Dapr
165+
items:
166+
- name: Scale Dapr components with KEDA
167+
href: dapr-keda-scaling.md
164168
- name: Tutorials
165169
expanded: true
166170
items:

articles/container-apps/dapr-keda-scaling.md

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,34 @@ author: hhunter-ms
55
ms.author: hannahhunter
66
ms.service: container-apps
77
ms.topic: how-to
8-
ms.date: 04/07/2023
8+
ms.date: 04/10/2023
99
---
1010

1111
# Scale Dapr components with KEDA scalers for Azure Container Apps
1212

13-
When scale rules are omitted on an Azure Container Apps resource, the container app is created with a default scale rule. If the resource receives no incoming traffic over a duration of five minutes, that default rule scales all replicas down to zero.
13+
When scale rules are omitted on an Azure Container Apps resource, the container app is created with a default scale rule. If the resource receives no incoming traffic over a duration of five minutes, that default rule scales all replicas down to zero. This behavior can be problematic and unexpected when leveraging Dapr components, specifically pub/sub subscriptions and input bindings.
1414

15-
This behavior can be problematic and unexpected when leveraging Dapr components, specifically pub/sub subscriptions and input bindings. This is due to how the mechanism for subscriptions and input bindings work. Unlike normal http flows, subscriptions and input bindings follow a "pull" message/event exchange model. In this case the Dapr sidecar from the subscriber service "pulls" messages rather than waiting for the message broker/event deliverer to initiate a connection. As a result, since the "puller" logic is in the Dapr sidecar, when it scales down to zero, the "puller" is stopped and there's no mechanism for it to know when to resume or scale back up from zero.
15+
Using KEDA scalers, you can scale your application and its Dapr sidecar when it has scaled to zero with inbound events and messages. However, configuring _both_ a Dapr component and a corresponding KEDA scaler is not intuitive.
1616

17-
KEDA scalers is one possible solution for scaling an application and its sidecar when it has scaled to 0 and incoming events and messages are inbound. With KEDA, there is a process that's outside of the application, which is never scaled down to zero that can wawtch for new messages/incoming events. It can then scale the receiving application as needed based on the number of incoming messages/events.
17+
todo: solution - if it's redundant or complex, then why?
1818

19-
However, there is complexity and redudancncy with the experience that is offered today. A Dapr component and a corresponding KEDA scaler are two separate configurations and it's not intuative that a KEDA scaler is often needed.
19+
## Configure container apps for scaling
2020

21-
The following scenario outlines a simple scenario with two microservices - a publisher and subscriber. In a loop, the publisher is continuously publishing messages via the Dapr pub/sub API to the topic ‘orders’ in Azure Service Bus. The order-processor container app is subscribed to the ‘orders’ topic and is receiving and processing the messages as they arrive.
21+
In this scenario:
22+
1. In a loop, a `checkout` publisher container app continuously publishes messages via the Dapr pub/sub API to the `orders` topic in Azure Service Bus.
23+
1. An `order-processor` subscriber container app subscribed to the `orders` topic receives and processes messages as they arrive.
2224

23-
Let’s look at the Bicep for both Container Apps – the checkout and order-processor service as well as the Dapr Azure Serivce Bus component:
25+
Let’s look at the Bicep for:
26+
- The `checkout` and `order-processor` container apps
27+
- The Dapr Azure Serivce Bus component
2428

25-
#### Checkout Container App (Publisher)
29+
todo: need actual steps - so far it's more of a scenario concept, user isn't walking through any steps.
30+
31+
### Publisher container app
32+
33+
The `checkout` publisher is a headless services that you want to run indefinitely and never scale down to zero.
34+
35+
Set the `minReplicas` to "1", which ensures the container app does not follow the default behavior.
2636

2737
```bicep
2838
resource checkout 'Microsoft.App/containerApps@2022-03-01' = {
@@ -80,11 +90,10 @@ resource checkout 'Microsoft.App/containerApps@2022-03-01' = {
8090
}
8191
```
8292

83-
Since the checkout container app is a headless services that we want to run indefinitely and never scale down to 0, we are setting the min replicas to 1, which ensures the container app does not follow the default behavior of scaling to 0 after 5 minutes.
93+
### Dapr component
8494

85-
Next, we will look at the configuration for the Dapr component for connecting to Azure Service Bus:
95+
Next, configure the Dapr component for connecting to Azure Service Bus via a connection string.
8696

87-
#### Order-Processor Container App (Subscriber)
8897
```bicep
8998
resource daprComponent 'daprComponents' = {
9099
name: 'orderpubsub'
@@ -112,11 +121,9 @@ resource daprComponent 'daprComponents' = {
112121
}
113122
```
114123

115-
In the above example, the component is configured to connect to Azure Service Bus via a connection string.
116-
117-
Lastly, we'll review the `order-processor` container app:
124+
### Subscriber container app
118125

119-
#### Order-Processor Container App (Subscriber)
126+
In the `order-processor` subscriber, you'll add a custom scale rule on the resource for the type `azure-servicebus`. With this scale rule, KEDA can scale up the container app and its Dapr sidecar, allowing incoming messages to be processed again while order-processor is scaled to zero.
120127

121128
```bicep
122129
resource orders 'Microsoft.App/containerApps@2022-03-01' = {
@@ -178,6 +185,7 @@ resource orders 'Microsoft.App/containerApps@2022-03-01' = {
178185
]
179186
}
180187
]
188+
// Set the scale property on the order-processor resource
181189
scale: {
182190
minReplicas: 0
183191
maxReplicas: 10
@@ -206,32 +214,6 @@ resource orders 'Microsoft.App/containerApps@2022-03-01' = {
206214
}
207215
```
208216

209-
Notice the scale property on the resource:
210-
211-
```bicep
212-
scale: {
213-
minReplicas: 0
214-
maxReplicas: 10
215-
rules: [
216-
{
217-
name: 'topic-based-scaling'
218-
custom: {
219-
type: 'azure-servicebus'
220-
metadata: {
221-
topicName: 'orders'
222-
subscriptionName: 'orders'
223-
messageCount: '30'
224-
}
225-
auth: [
226-
{
227-
secretRef: 'sb-root-connectionstring'
228-
triggerParameter: 'connection'
229-
}
230-
]
231-
}
232-
}
233-
]
234-
}
235-
```
217+
## Next steps
236218

237-
This is a custom scale rule for the type “azure-servicebus”. This scale rule is needed to ensure that when a message comes into the Azure Service Bus while the order-processor is scaled to 0, that KEDA can scale up the container app, along with its Dapr sidecar so messages can be processed again.
219+
[Learn more about using Dapr components with Azure Container Apps.](./dapr-overview.md)

0 commit comments

Comments
 (0)