Skip to content

Commit d005c52

Browse files
author
gitName
committed
[APIM] Backend session affinity
1 parent 450de40 commit d005c52

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

articles/api-management/backends.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services: api-management
55
author: dlepow
66
ms.service: azure-api-management
77
ms.topic: concept-article
8-
ms.date: 04/01/2025
8+
ms.date: 05/20/2025
99
ms.author: danlep
1010
ms.custom:
1111
- build-2024
@@ -241,14 +241,14 @@ API Management supports the following load balancing options for backend pools:
241241

242242
* **Round-robin**: By default, requests are distributed evenly across the backends in the pool.
243243
* **Weighted**: Weights are assigned to the backends in the pool, and requests are distributed across the backends based on the relative weight assigned to each backend. Use this option for scenarios such as conducting a blue-green deployment.
244-
* **Priority-based**: Backends are organized in priority groups, and requests are sent to the backends in order of the priority groups. Within a priority group, requests are distributed either evenly across the backends, or (if assigned) according to the relative weight assigned to each backend.
245-
246-
> [!NOTE]
247-
> Backends in lower priority groups will only be used when all backends in higher priority groups are unavailable because circuit breaker rules are tripped.
244+
* **Priority-based**: Backends are organized in priority groups, and requests are sent to the backends in order of the priority groups. Within a priority group, requests are distributed either evenly across the backends, or (if assigned) according to the relative weight assigned to each backend.
245+
> [!NOTE]
246+
> Backends in lower priority groups will only be used when all backends in higher priority groups are unavailable because circuit breaker rules are tripped.
248247
249-
### Example
248+
With any of the preceding load balancing options, optionally enable **session awareness** (session affinity) to ensure that all requests from a specific user during a session are directed to the same backend in the pool. API Management sets a cookie to maintain session state. This option is useful, for example, in scenarios with backends such as AI chat assistants or other conversational agents to route requests from the same session to the same endpoint.
250249

251-
Use the portal, API Management [REST API](/rest/api/apimanagement/backend), or a Bicep or ARM template to configure a backend pool. In the following example, the backend *myBackendPool* in the API Management instance *myAPIM* is configured with a backend pool. Example backends in the pool are named *backend-1* and *backend-2*. Both backends are in the highest priority group; within the group, *backend-1* has a greater weight than *backend-2* .
250+
> [!NOTE]
251+
> Session awareness in load-balanced pools is being released first to the **AI Gateway Early** [update group](configure-service-update-settings.md).
252252
253253

254254
#### [Portal](#tab/portal)
@@ -266,7 +266,9 @@ Use the portal, API Management [REST API](/rest/api/apimanagement/backend), or a
266266

267267
#### [Bicep](#tab/bicep)
268268

269-
Include a snippet similar to the following in your Bicep file for a load-balanced pool. Set the `type` property of the backend entity to `Pool` and specify the backends in the pool:
269+
Include a snippet similar to the following in your Bicep file for a load-balanced pool. Set the `type` property of the backend entity to `Pool` and specify the backends in the pool.
270+
271+
This example includes an optional `sessionAffinity` pool configuration for session awareness. It sets a cookie so that requests from a user session are directed to a specific backend in the pool.
270272

271273
```bicep
272274
resource symbolicname 'Microsoft.ApiManagement/service/backends@2023-09-01-preview' = {
@@ -286,14 +288,23 @@ resource symbolicname 'Microsoft.ApiManagement/service/backends@2023-09-01-previ
286288
priority: 1
287289
weight: 1
288290
}
289-
]
291+
],
292+
      "sessionAffinity": {
293+
        "sessionId": {
294+
          "source": "Cookie",
295+
          "name": "SessionId"
296+
        }
297+
      }
290298
}
291299
}
292300
}
293301
```
294302
#### [ARM](#tab/arm)
295303

296-
Include a JSON snippet similar to the following in your ARM template for a load-balanced pool. Set the `type` property of the backend resource to `Pool` and specify the backends in the pool:
304+
Include a JSON snippet similar to the following in your ARM template for a load-balanced pool. Set the `type` property of the backend resource to `Pool` and specify the backends in the pool.
305+
306+
This example includes an optional `sessionAffinity` pool configuration for session awareness. It sets a cookie so that requests from a user session are directed to a specific backend in the pool.
307+
297308

298309
```json
299310
{
@@ -315,7 +326,13 @@ Include a JSON snippet similar to the following in your ARM template for a load-
315326
"priority": "1",
316327
          "weight": "1"
317328
}
318-
]
329+
],
330+
      "sessionAffinity": {
331+
        "sessionId": {
332+
          "source": "Cookie",
333+
          "name": "SessionId"
334+
        }
335+
      }
319336
}
320337
}
321338
}

0 commit comments

Comments
 (0)