Overview of the Partition Key

Learn how to choose a partition key for Cosmos DB containers based on specific needs.

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.

Press + to interact
Panel in the Azure portal that illustrates the required partition key path
Panel in the Azure portal that illustrates the required partition key path

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.

Press + to interact
az cosmosdb sql container create
--account-name
--database-name
--name
--partition-key-path
--resource-group

Query

...