Azure Cosmos DB Concepts

Understanding the core principles of Azure Cosmos DB

Request Units in Azure Cosmos DB

What are Request Units (RUs)?

Azure Cosmos DB is a globally distributed, multi-model database service. To abstract the complexities of various database operations and hardware, it uses a normalized unit of measure called a Request Unit (RU). A Request Unit represents the normalized throughput required to perform various database operations.

Every operation performed on your Azure Cosmos DB database consumes a certain number of RUs. This includes reading an item, writing an item, executing a query, or performing a stored procedure. The number of RUs consumed depends on factors like:

How RUs Work

When you provision throughput for your Azure Cosmos DB container or database, you specify the number of RUs per second (RU/s) you want to allocate. This provisioned throughput acts as a ceiling for the number of RUs your operations can consume within any given second.

For example, if you provision 1000 RU/s for a container:

Azure Cosmos DB automatically scales your provisioned throughput if you're using autoscale or manual scaling settings.

Estimating RU Consumption

Understanding RU consumption is crucial for managing costs and performance. Azure Cosmos DB provides tools and documentation to help estimate RU costs:

Example RU Consumption

Here's a simplified example of RU costs for common operations on a 1KB item:

-- Operation Type      | RU Cost (approx.)
            -----------------------|-------------------
            Point Read (Item)      | 1 RU
            Point Write (Item)     | 1 RU
            Query (no filter/sort) | 1 RU per item returned
            Query (with filter/sort)| Varies based on complexity
            
Key Takeaway: Request Units abstract database operations into a normalized measure, allowing for consistent performance management and cost control across different APIs and hardware.

Optimizing RU Consumption

To optimize your RU consumption and reduce costs, consider these strategies:

Autoscale vs. Manual Throughput

Azure Cosmos DB offers two primary models for managing throughput: