Understanding Request Units in Azure Cosmos DB

Azure Cosmos DB is a globally distributed, multi-model database service. One of the key concepts for understanding and managing performance in Azure Cosmos DB is Request Units (RUs).

What are Request Units?

A Request Unit (RU) represents a normalized measure of throughput provided by a system. It abstracts the different database operations (like reads, writes, queries) and their associated costs into a single unit. An RU is a logical construct that encapsulates the resources required to perform a database operation. This includes CPU, memory, and IOPS (input/output operations per second).

Think of it this way: every operation you perform against your Cosmos DB account consumes a certain number of RUs. The total number of RUs consumed per second determines the throughput of your database or container.

How are RUs Calculated?

The RU consumption for an operation depends on several factors:

For example:

Request Unit Provisioning

You provision throughput for your Azure Cosmos DB resources (databases or containers) in terms of Request Units per second (RU/s). You can choose between two models:

1. Manual Throughput Provisioning

In this model, you specify the exact number of RU/s you want to provision. Azure Cosmos DB guarantees this throughput for your resource. If your actual consumption exceeds the provisioned throughput, your requests may be throttled (receive a 429 Too Many Requests error). If your consumption is consistently lower, you might be overpaying for throughput you don't use.

Note: Manual throughput provisioning is suitable for predictable workloads where you have a good understanding of your application's RU consumption.

2. Autoscale Throughput Provisioning

Autoscale allows Azure Cosmos DB to automatically scale your throughput up and down based on your workload's actual needs. You specify a maximum RU/s, and the service scales the provisioned throughput within a range (typically between 10% and 100% of the maximum). This model is ideal for unpredictable or variable workloads, helping to optimize costs by paying only for what you use while ensuring performance.

Tip: Autoscale throughput is a cost-effective option for most applications with fluctuating traffic patterns.

Monitoring RU Consumption

It's crucial to monitor your RU consumption to ensure optimal performance and cost-efficiency. You can use the following tools:

Here's a sample of what you might see in the Azure Portal:

Azure Cosmos DB RU Consumption Chart

Figure 1: Example of monitoring Request Unit consumption in Azure Cosmos DB.

Optimizing RU Consumption

To manage and optimize your RU costs:

Warning: Regularly review your RU consumption and adjust your provisioned throughput accordingly. Ignoring high RU consumption can lead to unexpected costs and performance degradation.

Conclusion

Understanding Request Units is fundamental to effectively using and managing Azure Cosmos DB. By provisioning appropriate throughput and optimizing your application's operations, you can achieve high performance and cost-efficiency for your globally distributed database solutions.

For more detailed information on specific RU costs for different operations, please refer to the official Azure Cosmos DB RU Cost Documentation.