What’s Logical Partition in CosmosDB?
In Cosmos DB, a logical partition is a logical unit of data organization within a container. It represents a subset of the data stored in the container and is defined based on a chosen partition key.
Here are some key characteristics of a logical partition in Cosmos DB:
- Partition Key: A logical partition is determined by a partition key, which is a property within each item stored in the container. The partition key value is used to group items together within the same logical partition.
- Data Grouping: All items that share the same partition key value are stored together within the same logical partition. This grouping ensures that related data is colocated, allowing for efficient queries and transactions involving those items.
- Atomic Unit: A logical partition is the smallest granularity at which operations are atomic in Cosmos DB. This means that all operations performed within a single logical partition are executed in an atomic, consistent, isolated, and durable (ACID) manner.
- Throughput: Each logical partition can have a maximum throughput capacity determined by the provisioned throughput (measured in Request Units per Second or RUs/s) of the container. The overall throughput of the container is divided among the logical partitions, allowing for scaling of throughput based on workload patterns.
- Scalability: Cosmos DB allows for the scaling of throughput by increasing the number of logical partitions. As the workload increases, you can split a logical partition into multiple partitions to distribute the data and workload across more physical partitions and achieve higher performance.
It’s important to choose an appropriate partition key that evenly distributes the data and aligns with the access patterns of your application. Careful consideration of the partition key is crucial to achieving optimal performance and scalability in Cosmos DB.