{"id":21036961,"url":"https://github.com/azurecosmosdb/prioritybasedexceution","last_synced_at":"2026-03-19T18:34:01.487Z","repository":{"id":155893404,"uuid":"569375973","full_name":"AzureCosmosDB/PriorityBasedExceution","owner":"AzureCosmosDB","description":null,"archived":false,"fork":false,"pushed_at":"2024-01-08T17:28:29.000Z","size":25,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-01-20T16:19:23.025Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AzureCosmosDB.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-11-22T17:26:35.000Z","updated_at":"2023-07-11T01:55:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"7b28314d-c551-43ce-bda5-66c8d84c6abc","html_url":"https://github.com/AzureCosmosDB/PriorityBasedExceution","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzureCosmosDB%2FPriorityBasedExceution","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzureCosmosDB%2FPriorityBasedExceution/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzureCosmosDB%2FPriorityBasedExceution/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AzureCosmosDB%2FPriorityBasedExceution/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AzureCosmosDB","download_url":"https://codeload.github.com/AzureCosmosDB/PriorityBasedExceution/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243482878,"owners_count":20297897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T13:23:24.388Z","updated_at":"2026-01-02T04:37:40.801Z","avatar_url":"https://github.com/AzureCosmosDB.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Priority Based Execution\n\nPriority based execution is a capability which allows users to specify priority to the request sent to Cosmos DB. Based on the priority specified by the user, if there are more requests than the configured RU/S in a second, then Cosmos DB will throttle low priority requests to allow high priority requests to execute. \n\nThis capability allows a user to perform more important tasks while delaying lesser important tasks when there are higher number of requests than what a container with configured RU/s can handle at a given time. The lesser important tasks will be continuously retried by any client using SDK based on the retry time and will be executed once the requirement of important (high priority) tasks are satisfied. \n\nThis feature is not guaranteed to always throttle low priority requests in favour of high priority requests and there are no SLA’s associated with the feature. This is a best effort scenario and there is a time associated with the start of throttling of low priority requests which is dependent on the rate at which high priority requests are sent to Cosmos DB. \n\n## Supported API's and SDK's:\n### API\n- NoSQL\n### SDK\n- .NET\n- Java\n- Python\n- Javascript\n\n## How to get started: \nStep 1: Whitelist your account by completing the nomination form : [priority based throttling - preview request](https://forms.microsoft.com/Pages/ResponsePage.aspx?id=v4j5cvGGr0GRqy180BHbR_kUn4g8ufhFjXbbwUF1gXFUMUQzUzFZSVkzODRSRkxXM0RKVDNUSDBGNi4u)\n\nStep2: Download the SDK latest version\n- .NET: [Azure Cosmos DB dotnetv3 SDK- 3.33.0-preview](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.33.0-preview)\n- Java: [Azure Cosmos DB Java SDK - 4.45.0](https://mvnrepository.com/artifact/com.azure/azure-cosmos/4.45.0)\n- Python: [Azure Cosmos DB Python SDK - 4.5.2b2](https://pypi.org/project/azure-cosmos/4.5.2b2/)\n\nStep3: Send us your feedback, comments, questions using the Issues tab on this repo. \n\n## Sample Code\n\n### C#\n```C#\nDocument doc = new Document() \n{ \n    Id = \"id\", \n    Address = \"address1\", \n    Pkey = \"pkey1\" \n}; \n\n// this code will insert an item in Cosmos DB container with low priority\n\nusing Microsoft.Azure.Cosmos.PartitionKey;\nusing Microsoft.Azure.Cosmos.PriorityLevel;\n \nRequestOptions requestOptions = new ItemRequestOptions{PriorityLevel = PriorityLevel.Low};\nItemResponse\u003cDocument\u003e response = await container.CreateItemAsync\u003cDocument(doc, new PartitionKey(\"pkey1\"), requestOptions); \n```\n### Java\n\n```java\n\nimport com.azure.cosmos.ThroughputControlGroupConfig;\nimport com.azure.cosmos.ThroughputControlGroupConfigBuilder;\nimport com.azure.cosmos.models.CosmosItemRequestOptions;\nimport com.azure.cosmos.models.PriorityLevel;\n\nclass Family{\n   String id;\n   String lastName;\n}\n\n//define throughput control group with low priority\nThroughputControlGroupConfig groupConfig = new ThroughputControlGroupConfigBuilder()\n                .groupName(\"low-priority-group\")\n                .priorityLevel(PriorityLevel.LOW)\n                .build();\ncontainer.enableLocalThroughputControlGroup(groupConfig);\n\nCosmosItemRequestOptions requestOptions = new CosmosItemRequestOptions();\n        requestOptions.setThroughputControlGroupName(groupConfig.getGroupName());\n\nFamily family = new Family();\nfamily.setLastName(\"Anderson\");\n\n\n// Insert this item with low priority in the container using request options.\ncontainer.createItem(family, new PartitionKey(family.getLastName()), requestOptions)\n    .doOnSuccess((response) -\u003e {\n        logger.info(\"inserted doc with id: {}\", response.getItem().getId());\n    }).doOnError((exception) -\u003e {\n        logger.error(\"Exception. e: {}\", exception.getLocalizedMessage(), exception);\n    }).subscribe();\n\n```\n\n### Python\n\n```python\nimport azure.cosmos.cosmos_client as cosmos_client\nfrom azure.cosmos.partition_key import PartitionKey\n\n# Define your Cosmos DB account and database details\nendpoint = \"\u003ccosmos-db-endpoint\u003e\"\nkey = \"\u003ccosmos-db-key\u003e\"\ndatabase_id = \"\u003cdatabase-name\u003e\"\ncontainer_id = \"\u003ccontainer-name\u003e\"\n\n# Create a Cosmos DB client\nclient = cosmos_client.CosmosClient(endpoint, key)\n\n# Create or get a database\ndatabase = client.create_database_if_not_exists(id=database_id)\n\n# Create or get a container\ncontainer = database.create_container_if_not_exists(\n    id=container_id,\n    partition_key=PartitionKey(path=\"/pkey\"),\n)\n\n# Insert a document into the container with custom headers\ndocument = {\n    \"id\": \"3\",\n    \"name\": \"John Doe\",\n    \"city\": \"New York\",\n}\n\n# Define custom headers directly in the options\nheaders = {\n    \"x-ms-cosmos-priority-level\": \"Low\"\n}\n\ncontainer.create_item(body=document, headers = headers)\n\n# Query documents in the container\nquery = \"SELECT * FROM c\"\nitems = list(container.query_items(query=query, enable_cross_partition_query=True, headers = headers))\n\nfor item in items:\n    print(item)\n```\n\n## FAQ’s \n\n1. #### How many priority levels can be specified in the request?\u003cbr/\u003e\n    Currently, there are only 2 priority, high and low. \n\n2. #### What is the default priority of a request?\u003cbr/\u003e\n   By default, all requests are of high priority. \n\n3. #### Does enabling priority based throttling means reserving a fraction of RU/s for high priority requests?\u003cbr/\u003e\n   No, there is no reservation of RU/s. The user can use all their provisioned throughput irrespective of the priority of requests they send.  \n\n4. #### What are the pricing changes associated with this feature?\u003cbr/\u003e\n   There is no cost associated with this feature, its free of charge. \n   \n   \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazurecosmosdb%2Fprioritybasedexceution","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazurecosmosdb%2Fprioritybasedexceution","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazurecosmosdb%2Fprioritybasedexceution/lists"}