Skip to content

Disable session affinity#

Performance Efficiency · Container App · 2023_06

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, if your application does not store large amounts of state or cached data in memory (stateless application design pattern), session affinity might decrease your throughput because one replica could get overloaded with requests, while others are dormant.

Recommendation#

Consider 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 to none or don't specify the property at all.

For example:

Azure Template snippet
{
  "type": "Microsoft.App/containerApps",
  "apiVersion": "2022-10-01",
  "name": "[parameters('appName')]",
  "location": "[parameters('location')]",
  "identity": {
    "type": "SystemAssigned",
    "userAssignedIdentities": {}
  },
  "properties": {
    "environmentId": "[parameters('environmentId')]",
    "template": {
      "revisionSuffix": "",
      "containers": "[variables('containers')]"
    },
    "configuration": {
      "ingress": {
        "external": false,
        "stickySessions": {
          "affinity": "None"
        }
      }
    }
  }
}

Configure with Bicep#

To deploy Container Apps that pass this rule:

  • Set properties.configuration.ingress.stickySessions.affinity to none or don't specify the property at all.

For example:

Azure Bicep snippet
resource containerApp 'Microsoft.App/containerApps@2022-10-01' = {
  name: appName
  location: location
  identity: {
    type: 'SystemAssigned'
    userAssignedIdentities: {}
  }
   properties: {
    environmentId: environmentId
    template: {
      revisionSuffix: ''
      containers: containers
    }
    configuration: {
      ingress: {
        external: false
        stickySessions: {
          affinity: 'none'
      }
    }
  }
}

Last update: 2023-05-16

Comments