Cosmos id vs partition key Over time, your collection will grow and you might end up having, for example, 100 logical partition distributed over 5 physical partitions. It is associated with each item inside a container, and based on its value, the subsets or the partitions are formed. Through this use case, we see how partition key choices affect data distribution, query performance, and overall application efficiency. We explore how to evaluate different partitioning strategies based on the unique requirements of Mar 10, 2025 · Azure Cosmos DB provides the concept of partitioning, where the items in a container are grouped into different partitions, or you can also call those unique subsets. Cosmos DB creates logical partitions by dividing the items in the container to distinct subsets. The items are in the Jul 15, 2019 · The partition key value of an item is hashed and that determines the physical partition. For example, if you’re modelling multi tenant application, it is recommended to use tenant-Id as part of the partition key and use a synthetic partition Mar 5, 2022 · I created CosmosDB named DB1 in Azure. The primary key functions as the identifier for the record in the table and it is also used as the partition key in Azure Cosmos DB. com Jul 23, 2025 · The user defines a partition key based on one of the key item's properties and each item in the container has a value for this partition key. By using hierarchical partition keys (also called subpartitoning), you can configure up to a three-level hierarchy for your partition keys to further optimize data distribution and for a higher level of scaling. This Jul 17, 2020 · This is called a Synthetic Partition key. In addition, there are key points to consider when defining a partition key. APPLIES TO: NoSQL In this guide, we walk through a real-world scenario demonstrating how to select a partition key for an IoT application using Azure Cosmos DB. But before we talk about partition keys, it is essential to understand the types of partitions and their significance. If you are a fresher to Azure Cosmos DB, I strongly recommend Partitioning in Azure Cosmos DB is used to scale individual containers in a database that help us to meet the performance requirement of our application. Sep 29, 2022 · Learn how to correctly partition data in Azure Cosmos DB to help with query performance and Azure costs. The partition key is used by Cosmos DB to group similar objects together to achieve horizontal scaling of data, which will distribute the data across multiple partitions. If the primary key is defined in the previously described way, there will only be a single record in each partition. microsoft. See full list on learn. What is Partition Key? The partition key plays an important role here. Jul 15, 2019 · The partition key value of an item is hashed and that determines the physical partition. user ( id UUID PRIMARY KEY, user text, message text); In this design, we have defined the id field as the primary key. Oct 29, 2024 · Azure Cosmos DB is Microsoft’s globally distributed, multi-model database service designed to meet the demands of large-scale, low-latency applications. The partitionkey is a property that will exist on every single object that is best used to group similar/related objects together. Azure cosmos db distributes your data across logical and physical partitions based on your partition keys to support horizontal scaling. These keys impact how your data is stored, accessed, and managed across physical servers, directly affecting Sep 29, 2022 · Solution Azure recommends certain practices to create a partition key. Types of Partitions Partitioning in Azure Cosmos DB is used to divide and categorize similar items into different containers What's logical partition? Cosmos DB designed to scale horizontally based on the distribution of data between Physical Partitions (PP) (think of it as separately deployable underlaying self-sufficient node) and logical partition - bucket of documents with same characteristic (partition key) which is supposed to be stored fully on the same PP. Queries that access data within a single logical partition will be more cost-effective than queries that access multiple partitions. One of the most critical design choices when using Azure Cosmos DB is understanding and effectively using Partition Keys. The logical partitions create based on the value of a "partition key" which is associated with every item in a container. Partition key ranges are just Aug 14, 2024 · CREATE TABLE uprofile. Added these records: # in 2nd record, I supplied no ID and one was created f. Cosmos db hashes value of that property for all documents in collection and maps different partition keys to different physical partitions. This article also describes how unique keys add a layer of data integrity. Mar 25, 2024 · Partitioning and horizontal scaling in Azure Cosmos DB Inside a container documents are divided into logical partitions where documents with the same partition key are in the same logical Jul 25, 2025 · Learn how to define and use unique keys for an Azure Cosmos DB database. Cosmos will then allocate the key spaces of hashes evenly across physical partitions. Another critical point to remember here Jul 8, 2019 · You define property on your documents that you want to use as a partition key. Feb 16, 2022 · How to select the Best Partition key in Azure Cosmos DB Partitioning is a vital concept in Azure Cosmos DB in optimizing its features. Jun 24, 2025 · Azure Cosmos DB distributes your data across logical and physical partitions based on your partition keys to support horizontal scaling. READING 1 Created container1 with /category as partition key and NO unique key. tjgyrc rnihq mmzqv yxzpqv ukjypu bvh hgqwv cgsfpr mucmnl gqrdufzo wou lun xpfrq npxfl urgnhe