Overview of the Partition Key
Explore the role of partition keys in Azure Cosmos DB and how they enable efficient data distribution and query performance. Learn to choose the right partition key based on high cardinality and resource spreading to avoid hot partitions and costly queries. This lesson helps you understand why partition keys are immutable and critical for scalable and low-latency databases.
The heart of Cosmos DB
To leverage the full power of Cosmos DB, we need to spread RUs and data storage evenly across all partitions and avoid hot partitions.
Partition key
Let’s start with what makes partitioning possible: partition keys. Cosmos DB asks us where to find the partition key in a document (the path) when we create a new container. The partition key cannot be modified after the creation.
For example, in a purchases container, the partition key can be /userId or user/id in the case of a nested object.
Note: Cosmos DB uses consistent hashing on partition keys to spread their values and reduce remapping when the hash table grows.