Skip to content

Added Priority Based Execution for Sync and Async Clients - #43917

Merged
Andrew Mathew (andrewmathew1) merged 10 commits into
Azure:mainfrom
andrewmathew1:users/andrewmathew1/prioritylevelfeature
Nov 14, 2025
Merged

Andrew Mathew (andrewmathew1) merged 10 commits into
Azure:mainfrom
andrewmathew1:users/andrewmathew1/prioritylevelfeature

Conversation

@andrewmathew1

Copy link
Copy Markdown
Contributor

Description

Priority-based execution is a capability which allows users to specify priority for the request sent to Azure Cosmos DB. Based on the priority specified by the user, if there are more requests than the configured RU/s in a second, then Azure Cosmos DB will throttle low priority requests to allow high priority requests to execute. Previously this was only available at the request level now entire clients can be set to a low or high priority level. The request priority level will take precedence over the client priority level in case both are set.

Copilot AI review requested due to automatic review settings November 10, 2025 19:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds client-level priority configuration for Azure Cosmos DB clients (both sync and async), allowing users to set a default priority level for all requests made by a client. This complements the existing request-level priority feature, with request-level priority taking precedence when both are set.

  • Added priority_level parameter to CosmosClient constructors in both sync and async implementations
  • Client-level priority is stored in default headers and applied to all requests
  • Comprehensive documentation and examples demonstrating client-level priority, request-level priority, and precedence behavior

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py Implements client-level priority by adding priority_level parameter and storing it in default_headers
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py Async implementation of client-level priority, mirroring the sync implementation
sdk/cosmos/azure-cosmos/tests/test_headers.py Adds tests for client-level priority and request-level precedence in sync client
sdk/cosmos/azure-cosmos/tests/test_headers_async.py Adds tests for client-level priority and request-level precedence in async client
sdk/cosmos/azure-cosmos/samples/examples.py Demonstrates client-level priority usage and precedence with practical examples
sdk/cosmos/azure-cosmos/samples/examples_async.py Demonstrates async client-level priority usage and precedence with practical examples

@andrewmathew1

Copy link
Copy Markdown
Contributor Author

/azp run python - cosmos - tests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@simorenoh

Copy link
Copy Markdown
Member

/azp run python - cosmos - tests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@simorenoh Simon Moreno (simorenoh) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments but overall the changes seem to be good, thanks Andrew!

Comment thread sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py Outdated
Comment thread sdk/cosmos/azure-cosmos/samples/examples.py
Comment thread sdk/cosmos/azure-cosmos/tests/test_headers_async.py Outdated
Comment thread sdk/cosmos/azure-cosmos/tests/test_headers_async.py Outdated
@andrewmathew1

Copy link
Copy Markdown
Contributor Author

/azp run python - cosmos - tests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment thread sdk/cosmos/azure-cosmos/CHANGELOG.md Outdated
Co-authored-by: Simon Moreno <30335873+simorenoh@users.noreply.github.com>
@andrewmathew1 Andrew Mathew (andrewmathew1) changed the title Added priority_level for Sync and Async Clients Added Priority Based Execution for Sync and Async Clients Nov 12, 2025
@andrewmathew1

Copy link
Copy Markdown
Contributor Author

/azp run python - cosmos - tests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@andrewmathew1

Copy link
Copy Markdown
Contributor Author

/azp run python - cosmos - tests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@andrewmathew1

Copy link
Copy Markdown
Contributor Author

/azp run python - cosmos - tests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@andrewmathew1

Copy link
Copy Markdown
Contributor Author

/azp run python - cosmos - tests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@andrewmathew1
Andrew Mathew (andrewmathew1) merged commit ae6a5c2 into Azure:main Nov 14, 2025
36 checks passed
Yuchao Yan (msyyc) pushed a commit that referenced this pull request Nov 25, 2025
* Added priority level for clients

* added to changelog and docstring

* changed item to queried_item for pylint

* made suggested changes

* fixed sample bug

* Update sdk/cosmos/azure-cosmos/CHANGELOG.md

Co-authored-by: Simon Moreno <30335873+simorenoh@users.noreply.github.com>

* Changed test pipeline from West US to West Central US

* added changes to vector index policy tests

* bugfixes for vector policy tests

---------

Co-authored-by: Andrew Mathew <andrewmathew@microsoft.com>
Co-authored-by: Simon Moreno <30335873+simorenoh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants