Will cosmos db put the data, which come from different containers but share the same partition key, to the same logical partition?

Lavender Liu 21 Reputation points Microsoft Employee
2022-10-03T02:36:25.633+00:00

Hi,

If I have three containers with the same partition key (say /projectid), will cosmos db put them into the same logical partition? What is the scope of the logical partition? Is it container scope only or it is database scope?

Thanks for the help.

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,470 questions
{count} votes

Accepted answer
  1. Mark Brown - MSFT 2,766 Reputation points Microsoft Employee
    2022-10-03T12:21:04.417+00:00

    A logical partition is defined as the partition key value within a container. Your data will be stored in a minimum of three logical partitions * the number of partition key values across all three containers, even where the logical partition key values are the same. If you are new to Cosmos DB and horizontal partitioning/sharding, here is a Gist with some information to get you started. The second video is a good start. https://gist.github.com/markjbrown/114179b3d530abe0eaa25fb9ac54b609

    PS: your scenario of having the same partition key in multiple containers is an anti-pattern. Generally speaking, when designing for Cosmos DB, an objective is to store data in the same container when it shares the same partition key and is frequently accessed together. If this fits your scenario. you should reconsider your design. Exceptions to this tend to include multi-tenant scenarios when trying to avoid noisy neighbor problem.


0 additional answers

Sort by: Most helpful