Disable session affinity#
Performance Efficiency · Container App · Rule · 2023_09 · Important
Disable session affinity to prevent unbalanced distribution.
Description#
Container apps allows you to configure session affinity (sticky sessions). When enabled, this feature route requests from the same client to the same replica. This feature might be useful for stateful applications that require a consistent connection to the same replica.
However, for stateless applications there is drawbacks to using session affinity. As connections are opened and closed, a subset of replicas might become overloaded with requests, while others are dormant. This can lead to: poor performance and resource utilization; less predictable scaling.
Recommendation#
Consider using stateful application design and disabling session affinity to evenly distribute requests across each replica.
Examples#
Configure with Azure template#
To deploy Container Apps that pass this rule:
- Set
properties.configuration.ingress.stickySessions.affinity
tonone
or don't specify the property at all.
For example:
{
"type": "Microsoft.App/containerApps",
"apiVersion": "2023-05-01",
"name": "[parameters('appName')]",
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"environmentId": "[resourceId('Microsoft.App/managedEnvironments', parameters('envName'))]",
"template": {
"revisionSuffix": "[parameters('revision')]",
"containers": "[variables('containers')]"
},
"configuration": {
"ingress": {
"allowInsecure": false,
"stickySessions": {
"affinity": "none"
}
}
}
},
"dependsOn": [
"[resourceId('Microsoft.App/managedEnvironments', parameters('envName'))]"
]
}
Configure with Bicep#
To deploy Container Apps that pass this rule:
- Set
properties.configuration.ingress.stickySessions.affinity
tonone
or don't specify the property at all.
For example:
resource containerApp 'Microsoft.App/containerApps@2023-05-01' = {
name: appName
location: location
identity: {
type: 'SystemAssigned'
}
properties: {
environmentId: containerEnv.id
template: {
revisionSuffix: revision
containers: containers
}
configuration: {
ingress: {
allowInsecure: false
stickySessions: {
affinity: 'none'
}
}
}
}
}
Notes#
This rule may generate false positive results for stateful applications.
Links#
- Avoid a requirement to store server-side session state
- Session affinity
- Session Affinity in Azure Container Apps
- Azure deployment reference