Partition Throughput Monitoring

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 10 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Lesson: Partition Throughput Monitoring in Azure Cosmos DB

Introduction: The Criticality of Partition Throughput

In the architecture of Azure Cosmos DB, throughput is the currency of your database performance. When you provision throughput, you are essentially purchasing a specific capacity of Request Units (RUs) per second to handle your database operations. However, Cosmos DB is a distributed system, and this throughput is not a monolithic pool sitting idle; it is distributed across physical partitions. Understanding how your throughput is consumed at the partition level is the difference between a high-performing, cost-efficient application and one plagued by latency, throttled requests, and unexpected costs.

Partition throughput monitoring is the practice of observing how your workload interacts with the physical underlying storage structures of your database. If your data is not distributed evenly across these partitions, or if your access patterns favor one specific partition over others, you will encounter a "hot partition." A hot partition occurs when one physical partition reaches its throughput limit while others remain largely idle. Because the database engine cannot reallocate unused throughput from one partition to another in real-time, the entire database or container may suffer from performance degradation despite having plenty of total provisioned RUs.

This lesson explores how to monitor these dynamics, identify imbalances, and take corrective actions. We will move beyond basic metrics and look into the granular telemetry that allows you to maintain a healthy, scalable Cosmos DB environment. Whether you are managing a small development instance or a global, multi-region production deployment, mastering partition monitoring is a core competency for any cloud engineer.


Not read yet

The Mechanics of Partitioning and Throughput

Before diving into monitoring, we must briefly revisit how Cosmos DB handles data distribution. When you create a container, you choose a partition key. This key acts as a logical identifier that the database uses to route data to specific physical partitions. Azure Cosmos DB automatically manages the splitting and merging of these physical partitions as your data grows or your throughput requirements change.

Each physical partition is allocated a fixed slice of the total provisioned throughput. For example, if you provision 10,000 RU/s and your data is spread across 10 physical partitions, each partition effectively gets 1,000 RU/s. If your application sends a query that only targets data residing on "Partition A," the maximum speed that query can achieve is 1,000 RU/s, even if the other 9,000 RU/s are sitting completely unused.

Callout: The "Hot Partition" Concept A hot partition is the most common cause of 429 (Too Many Requests) errors in Cosmos DB. It occurs when the logical distribution of your data—or the way your application queries it—results in a disproportionate amount of traffic hitting a single physical partition. Unlike traditional relational databases where you might simply add an index to speed up a query, in Cosmos DB, you must ensure that your data access is spread evenly across all physical partitions to maximize the utility of your provisioned RUs.


Not read yet

Key Metrics for Partition Monitoring

To effectively monitor partition throughput, you must look at specific metrics within Azure Monitor. Relying solely on the "Total Request Units" metric is insufficient because it aggregates data across all partitions, effectively masking the spikes that occur on individual partitions.

1. Total Requests (by Partition Key Range ID)

The TotalRequests metric broken down by PartitionKeyRangeId is your most important tool. A PartitionKeyRangeId corresponds to a physical partition. By splitting your view by this dimension, you can see if one ID is processing significantly more requests than others. If you see a line spiking while others remain flat, you have identified a hot partition.

2. Throttled Requests (429 Errors)

The TotalRequests metric should be viewed alongside the ThrottledRequests metric. If you see a spike in requests for a specific PartitionKeyRangeId and a corresponding spike in throttled requests, you have definitive proof that your partition key strategy is causing performance bottlenecks.

3. Data Distribution (Storage per Partition)

While this is a storage metric, it is highly relevant to throughput. If one partition contains 90% of your data, it is statistically likely to receive a higher volume of requests. Monitoring the storage footprint per partition helps you predict potential throughput hotspots before they actually become an issue for your application.


Not read yet

Step-by-Step: Setting Up Monitoring in Azure Portal

To begin monitoring your partition throughput, follow these steps to configure an Azure Monitor Workbook or dashboard.

  1. Navigate to your Cosmos DB Account: Open the Azure Portal and select your Cosmos DB resource.
  2. Open Insights: In the left-hand navigation menu, select "Insights." This is a pre-built set of dashboards provided by Azure that covers most common monitoring needs.
  3. Navigate to Throughput: Click on the "Throughput" tab within the Insights blade.
  4. Split by Partition Key Range: Look for the filter or grouping options. You will want to group the "Normalized RU Consumption" or "Total Requests" by PartitionKeyRangeId.
  5. Set Time Range: Adjust the time range to capture a typical business cycle (e.g., the last 24 hours or the last 7 days).
  6. Analyze the Chart: Look for a "staircase" or "divergent" pattern where one line is consistently higher than the others.

Tip: If you are using Autoscale throughput, monitoring becomes even more critical. Autoscale is triggered by the highest usage across any single partition. If one partition is hot, the entire system might scale up to its maximum limit, costing you more money without actually solving the performance issue on the other partitions.


Not read yet

Identifying Hot Partitions with Code

While the Azure Portal is excellent for visualization, you can also extract this data programmatically using the Azure SDK or by querying the underlying diagnostic logs. Below is a conceptual example using the Azure Monitor Query library in C#.

// This snippet demonstrates how to query the diagnostic logs for 429 errors 
// grouped by partition key range.
var client = new MonitorQueryClient(new DefaultAzureCredential());

string query = @"
AzureDiagnostics
| where ResourceProvider == 'MICROSOFT.DOCUMENTDB'
| where OperationName == 'DataPlaneRequests'
| where StatusCode == 429
| summarize Count=count() by PartitionKeyRangeId_s, bin(TimeGenerated, 5m)
| order by Count desc";

var response = await client.QueryWorkspaceAsync(workspaceId, query, QueryTimeRange.All(TimeSpan.FromHours(1)));

Understanding the Diagnostic Log Data

When you analyze these logs, you are looking for the PartitionKeyRangeId_s field. This field identifies the physical partition. If you notice that a specific ID appears repeatedly in your 429 error logs, you should immediately investigate what data is currently mapped to that partition.

To map a PartitionKeyRangeId to an actual partition key value, you can use the Cosmos DB SDK to list the partition key ranges:

// Using the CosmosClient to inspect partition ranges
var container = cosmosClient.GetContainer("database", "container");
var ranges = await container.GetPartitionKeyRangesAsync().ToListAsync();

foreach(var range in ranges)
{
    Console.WriteLine($"Range ID: {range.Id}, Min: {range.MinInclusive}, Max: {range.MaxExclusive}");
}

This mapping helps you understand which "range" of your partition key values is being impacted. If your partition key is a UserId, and your range covers a specific subset of IDs, you can correlate that back to your application logic.


Not read yet

Best Practices for Maintaining Healthy Partitions

Monitoring is only half the battle; maintaining a healthy partition distribution requires proactive design and maintenance.

  • Choose a High-Cardinality Partition Key: A key with many distinct values (like OrderId or DeviceId) is far better than a key with low cardinality (like Status or Region). With low cardinality, you end up with "fat" partitions that contain too many records, leading to uneven distribution.
  • Avoid "Timestamp" Keys for Write-Heavy Workloads: Using a timestamp or date as the primary partition key often results in all new data being written to a single partition (the "current" time). This creates a temporal hotspot that moves forward in time. If you must use a date, consider a synthetic key that combines the date with a high-cardinality value.
  • Monitor Normalized RU Consumption: This is a metric provided by Azure that shows the percentage of your provisioned RU/s being used by a partition. A value of 100 means you are hitting the limit. You should set up an Azure Monitor Alert to notify you when this value consistently stays above 80% for any partition.
  • Use Synthetic Partition Keys: If your data does not have a natural high-cardinality key, create one. You can append a random number or a hash to your existing key to spread data across multiple physical partitions.
  • Review Query Patterns: Sometimes, the partition key is fine, but the query is bad. A "cross-partition query" that doesn't include the partition key in the WHERE clause must hit every physical partition. This consumes RU/s across the entire database, not just one partition. Always include the partition key in your queries whenever possible.

Warning: Do not attempt to "manually" split a partition. Azure Cosmos DB handles partition splitting automatically based on storage size and throughput pressure. If you attempt to force changes by deleting and recreating data, you will likely cause unnecessary downtime and data loss without fixing the underlying distribution issue.


Not read yet

Comparison Table: Monitoring Approaches

Feature Azure Portal Insights Diagnostic Logs (KQL) SDK-based Monitoring
Ease of Use Very High Medium Low
Granularity High (Visual) Very High (Raw Data) High (Real-time)
Alerting Simple Complex / Advanced Requires Custom Service
Best For Quick Troubleshooting Trend Analysis & Auditing Automated Scaling/Logic

Common Pitfalls and How to Avoid Them

1. Misinterpreting Total RU Usage

Many teams look at the total RU consumption of their database and conclude they have plenty of "headroom." However, as discussed, if 90% of that usage is concentrated on one partition, the other 10% of your capacity is irrelevant. Always drill down into the partition-level metrics.

2. Ignoring Cross-Partition Queries

A common mistake is assuming that because the database is "fast," the queries are efficient. Cross-partition queries are a silent killer of throughput. They scale linearly with the number of physical partitions. If your database grows from 10 to 100 partitions, a cross-partition query that was once fine will suddenly become 10 times more expensive.

3. Over-Provisioning to Solve Hotspots

When developers see 429 errors, their first instinct is often to increase the total provisioned throughput. While this might stop the 429s temporarily, it is an expensive way to solve a design problem. If you have a hot partition, increasing total throughput only provides a marginal benefit, as the hot partition will eventually hit its new, higher limit while other partitions remain idle.

4. Forgetting to Monitor "Normalized RU Consumption"

This specific metric is often overlooked in favor of "Total Requests." Normalized RU consumption is the most accurate indicator of whether a partition is under stress relative to its specific capacity. It is the gold standard for setting alert thresholds.


Not read yet

Troubleshooting Step-by-Step: The "429" Workflow

When you receive an alert regarding 429 errors, follow this structured process to diagnose the issue:

  1. Isolate the Timeframe: Identify exactly when the 429s started. Was it after a deployment? A change in traffic volume? A new query?
  2. Check Partition Metrics: Open the "Insights" dashboard and filter by PartitionKeyRangeId. Identify which ID is showing high Normalized RU Consumption.
  3. Cross-Reference with Operations: Check the "Operations" metric. Are there specific write or query operations that correlate with the 429 spikes on that partition?
  4. Examine the Partition Key: Use the mapping logic provided earlier to determine which data falls into that PartitionKeyRangeId.
  5. Review Application Code: Check if the application is performing bulk operations or large cross-partition queries that might be overwhelming that specific partition.
  6. Apply Mitigation:
    • If it is a query issue, optimize the query to include the partition key.
    • If it is a data distribution issue, consider changing the partition key (this requires a container migration).
    • If it is a volume issue, ensure you are using the SDK's built-in retry policy to handle transient 429s gracefully.

Not read yet

Advanced Monitoring: Integrating with External Systems

For large-scale enterprise environments, sending logs to an Azure Log Analytics Workspace is just the start. You might need to integrate this data into external SIEM (Security Information and Event Management) or observability platforms like Datadog, Splunk, or New Relic.

Sending Logs to Event Hub

You can configure diagnostic settings in your Cosmos DB account to stream DataPlaneRequests directly to an Azure Event Hub. From there, your observability platform can consume the stream, aggregate the partition-level metrics, and trigger custom alerts based on your internal business logic.

Note: Streaming logs to Event Hub incurs additional costs based on the volume of data. Ensure you are only streaming the necessary categories (DataPlaneRequests and QueryRuntimeStatistics) to keep costs manageable.

Custom Alerts in Azure Monitor

You should configure alert rules that go beyond simple thresholds. For example, create an alert that triggers if:

  • The NormalizedRUConsumption is > 80% for any PartitionKeyRangeId over a 5-minute window.
  • The ThrottledRequests count is > 0 for more than 3 consecutive minutes.

These alerts should be sent to your on-call team via Action Groups (Email, SMS, or ITSM integration like ServiceNow).


Not read yet

Summary of Key Takeaways

  1. Throughput is Partitioned: Total provisioned throughput is divided among physical partitions. A bottleneck on one partition limits the entire container's performance.
  2. Normalization is Key: Always monitor Normalized RU Consumption rather than total RU usage to get a true picture of partition health.
  3. Identify Hot Partitions: Use the PartitionKeyRangeId dimension in Azure Monitor to detect when specific partitions are bearing an unequal load.
  4. Design Matters: The most effective way to manage partition throughput is through a high-cardinality partition key that ensures even data distribution.
  5. Avoid Cross-Partition Queries: These queries are costly and scale poorly as your database grows. Always include the partition key in your WHERE clauses.
  6. Use SDK Retries: Ensure your application uses the latest Cosmos DB SDK, which includes built-in retry logic for handling 429 errors during transient spikes.
  7. Alert Proactively: Set alerts on normalized consumption and throttled requests to catch issues before they impact end-users.

By focusing on these areas, you move from a reactive stance of "fixing performance" to a proactive stance of "architecting for scale." Cosmos DB is a powerful tool, but its true potential is only unlocked when you respect the underlying physical distribution of your data. Remember that monitoring is not a one-time setup; it is a continuous process of observing, analyzing, and refining your data access patterns as your application evolves.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.