Azure Cosmos DB
An Azure NoSQL database service for app development.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello ,How to decide the primary key on CosmosDB
Thanks
Himanshu
In Cosmos DB, the primary key is defined by the partition key and the unique ID (id) of each document:
id: A unique identifier for each item in a container.partition key: Determines how data is distributed across partitions.✅ How to Choose the Right Partition Key
Understand Your Access Patterns
userId, then userId is a good candidate.- The partition key should have **many unique values** to avoid hot partitions.
- Avoid keys like `country` or `status` if they have few distinct values.
**Balance Read/Write Load**
- Distribute traffic evenly across partitions.
- If one key (e.g., `productId`) gets 90% of traffic, it will cause throttling.
**Avoid Large Items in One Partition**
- Cosmos DB limits partition size to **20 GB**.
- If all items with the same key exceed this, you’ll hit limits.
userId|orderId).In Cosmos DB, the primary key is defined by the partition key and the unique ID (id) of each document:id: A unique identifier for each item in a container.partition key: Determines how data is distributed across partitions.userId, then userId is a good candidate.country or status if they have few distinct values.productId) gets 90% of traffic, it will cause throttling.userId|orderId).