Introduction
In my first article in Cosmos DB, I talked about the basic information about How to provision Cosmos DB, and today we will complete our discussion in How Cosmos DB Partitioning work, and What are the Logical Partition and Physical Partition then in the upcoming posts we will talk more and more about Designing and Architecture Layers for Cosmos DB Such as Consistency levels in Cosmos DB Which Consistency levels are suitable with your APP, What are Cosmos API choices, Disaster Recovery and High Availability in Cosmos DB Keep Following ..
- Cosmos DB Physical Partition
- Cosmos DB Logical Partition
- Cosmos DB Partition Key
- How to Choose the Right Partition Key
- Resources
Cosmos DB Physical Partition
We have two kinds of Partitioning in Cosmos DB Logical and Physical so Firstly let us agree that the Physical Partition is something behind the scenes that’s mean we as admins we don’t have control on Physical Partition it is managed by Azure Cosmos DB internally, so most of our focus will be in Logical Partition, Based on Microsoft documentation one or more than one Logical Partition can be mapped into one Single Physical Partition and there is no Limit for the Physical Partition in the Azure Cosmos DB Container because Physical Partition count depends on many things such as provisioned throughput and Total data storage, every single Physical Partition can provide Throughput of up to 10,000 request units per second and it can store up to 50 GB, and still you have the visibility to know How many Physical Partition used in the container in Cosmos DB with using Storage Matrices.
Cosmos DB Logical Partition
When we come to the logical Partition it the link between Container and Physical Partition using Partition Key and the logical Partition created per container, and Cosmos DB can contain multiple containers so this means we have database > Contain Container > Container has Partition Key > Partition Key Spited the data into logical Partition and the Logical Partition mapped to Physical Partition and Each logical partition can store up to 20 GB of data.

How to Choose the Right Partition Key
It is the same concept of SQL Server Partition you should have first the correct value that you will build your Partition key on it for example if I have a table of invoices and most of the APP queries is selecting the data based on the invoice Create Date at this time Creating Partition Key on Create Date it will be great but in the same scenario, it will be bad when I have total 1000 invoices 90% 900 invoices out of total invoices created in the same month this means 90% from all of your data will be hosted in one logical Partition, that’s why we need to do more checks before designing and Choosing the right Partition Key. based on that you need to consider below things to take the Full benefits from Azure Cosmos DB Partition.
- The Top Quires, most important Quires, a heavy query in your APP and try to understand them very well to take distributed value from them you can build on it your Partition
- Changing on the Queries what is the kind of the changing can happen on the APP query to check if it will be working fine with Partition Key Design.
Important Notes : Once you created your Partition Key you can not change it if you need to change it you should move your data to a new container with new Partition Key design

Resources
- Partitioning in Azure Cosmos DB
- Partitioning and horizontal scaling in Azure Cosmos DB
- Azure Cosmos DB capacity calculator
Keep Following
Cloud Tech Website blog survey
IF you found this blog is helpful and sharing useful content please take few second to do rate the website blog from here