Before we understand provisioning throughput, the first step is to understand Cosmos DB Pricing. Cosmos DB pricing is based on requested units.
The cost of all database operations is normalized by Azure Cosmos DB and is expressed by Request Units (or RUs, for short).You can think of RUs per second as the currency for throughput. RUs per second is a rate-based currency. It abstracts the system resources such as CPU, IOPS, and memory that are required to perform the database operations supported by Azure Cosmos DB.
Cosmos DB provides more than one way to provision throughput
- Dedicated collection level throughput
- Shared Database level throughput
Collection level throughput provides the dedicated request unit /second for that collection . for e..g if you have data coming from multiple IoT devices and one of them sends data at say 500 data points per second , then you need to provision a dedicated capacity to that collection .
Database Throughput = sum( dedicated throughput for each collection within the database)Each collection in its own database, and the max throughput for each collection is determined by the dedicated capacity provisioned
Shared Database level throughput is used when you have have few collections and they are not used with a high frequency, for e.g. reference data that is read every single time there is another transaction that occurs once per second , if you have multiple reference data collection, it does not require a high dedicated throughput , then we can use shared database throughput.
The biggest difference in collection level and database provisioned throughput is the difference of marginal aggregation. Mathematically,
Collection throughput = Database throughput – sum(current throughput used by other collections)Each collection gets the max available throughput provisioned at the database level,
Provisioning throughput using Collection
The RUs are setup while the DB and the collections are provisioned and can be scaled up or down on need basis.
Creating a collection within a new or existing DB
Alternatively, Cosmos DB provides Azure CLI to create the collections along with the throughput option
Provisioning throughput using Database
Alternatively Cosmos DB provides provisioning of throughput using Azure CLI
Scaling the throughput at database level is also just like the way we scale the collection level throughput
In Azure CLI, The throughput sub-entity supports two methods viz., show and update, the show method provides the current throughput and the update helps to scale the throughput at the database level
After started to write this article, i realized i should cover on migration from collection throughput to database throughput. I will try to write the migration steps in my next article