Partition Throughput Monitoring
Complete the full lesson to earn 25 points — 50 with Pro
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks, the wait, and see fewer ads — read each lesson on a single page 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.
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.
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.
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.
- Navigate to your Cosmos DB Account: Open the Azure Portal and select your Cosmos DB resource.
- 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.
- Navigate to Throughput: Click on the "Throughput" tab within the Insights blade.
- 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. - Set Time Range: Adjust the time range to capture a typical business cycle (e.g., the last 24 hours or the last 7 days).
- 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.
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.
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
OrderIdorDeviceId) is far better than a key with low cardinality (likeStatusorRegion). 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
WHEREclause 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.
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.
Troubleshooting Step-by-Step: The "429" Workflow
When you receive an alert regarding 429 errors, follow this structured process to diagnose the issue:
- Isolate the Timeframe: Identify exactly when the 429s started. Was it after a deployment? A change in traffic volume? A new query?
- Check Partition Metrics: Open the "Insights" dashboard and filter by
PartitionKeyRangeId. Identify which ID is showing highNormalized RU Consumption. - Cross-Reference with Operations: Check the "Operations" metric. Are there specific write or query operations that correlate with the 429 spikes on that partition?
- Examine the Partition Key: Use the mapping logic provided earlier to determine which data falls into that
PartitionKeyRangeId. - Review Application Code: Check if the application is performing bulk operations or large cross-partition queries that might be overwhelming that specific partition.
- 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.
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 (
DataPlaneRequestsandQueryRuntimeStatistics) 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
NormalizedRUConsumptionis > 80% for anyPartitionKeyRangeIdover a 5-minute window. - The
ThrottledRequestscount 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).
Summary of Key Takeaways
- Throughput is Partitioned: Total provisioned throughput is divided among physical partitions. A bottleneck on one partition limits the entire container's performance.
- Normalization is Key: Always monitor
Normalized RU Consumptionrather than total RU usage to get a true picture of partition health. - Identify Hot Partitions: Use the
PartitionKeyRangeIddimension in Azure Monitor to detect when specific partitions are bearing an unequal load. - Design Matters: The most effective way to manage partition throughput is through a high-cardinality partition key that ensures even data distribution.
- Avoid Cross-Partition Queries: These queries are costly and scale poorly as your database grows. Always include the partition key in your
WHEREclauses. - 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.
- 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.
Reach the last section to complete this lesson and earn points — you're on section 1 of 10.
- Introduction to Cosmos DB Data Modeling
- Introduction to Cosmos DB Data Modeling Quiz5q
- Multiple Entity Types in Same Container
- Multiple Entity Types in Same Container Quiz5q
- Storing Related Entities in Same Document
- Storing Related Entities in Same Document Quiz5q
- Denormalizing Data Across Documents
- Denormalizing Data Across Documents Quiz5q
- Referencing Between Documents
- Referencing Between Documents Quiz5q
- Partition Keys and Document IDs
- Partition Keys and Document IDs Quiz5q
- Time to Live (TTL) Configuration
- Time to Live (TTL) Configuration Quiz5q
- Document Versioning Strategies
- Document Versioning Strategies Quiz5q
- Schema Versioning Patterns
- Schema Versioning Patterns Quiz5q
- Choosing Partition Strategies
- Choosing Partition Strategies Quiz5q
- Partition Key Selection Best Practices
- Partition Key Selection Best Practices Quiz5q
- Transactions and Partition Keys
- Transactions and Partition Keys Quiz5q
- Cross-Partition Query Costs
- Cross-Partition Query Costs Quiz5q
- Data Distribution Analysis
- Data Distribution Analysis Quiz5q
- Throughput Distribution Planning
- Throughput Distribution Planning Quiz5q
- Synthetic Partition Keys
- Synthetic Partition Keys Quiz5q
- Hierarchical Partition Keys
- Hierarchical Partition Keys Quiz5q
- Throughput and Storage Requirements
- Throughput and Storage Requirements Quiz5q
- Serverless vs Provisioned Throughput
- Serverless vs Provisioned Throughput Quiz5q
- Database-Level Provisioned Throughput
- Database-Level Provisioned Throughput Quiz5q
- Granular Scale Units
- Granular Scale Units Quiz5q
- Global Distribution Costs
- Global Distribution Costs Quiz5q
- Configuring Throughput in Portal
- Configuring Throughput in Portal Quiz5q
- Gateway vs Direct Connectivity Mode
- Gateway vs Direct Connectivity Mode Quiz5q
- Creating Database Connections
- Creating Database Connections Quiz5q
- Azure Cosmos DB Emulator
- Azure Cosmos DB Emulator Quiz5q
- Connection Error Handling
- Connection Error Handling Quiz5q
- Singleton Pattern for Clients
- Singleton Pattern for Clients Quiz5q
- Global Distribution Regions
- Global Distribution Regions Quiz5q
- Threading and Parallelism
- Threading and Parallelism Quiz5q
- Arrays and Nested Objects Queries
- Arrays and Nested Objects Queries Quiz5q
- Correlated Subqueries
- Correlated Subqueries Quiz5q
- Array and Type-Checking Functions
- Array and Type-Checking Functions Quiz5q
- Mathematical and String Functions
- Mathematical and String Functions Quiz5q
- Date Functions in Queries
- Date Functions in Queries Quiz5q
- Point Operations vs Query Operations
- Point Operations vs Query Operations Quiz5q
- CRUD Point Operations
- CRUD Point Operations Quiz5q
- Patch Operations for Updates
- Patch Operations for Updates Quiz5q
- Transactional Batch Operations
- Transactional Batch Operations Quiz5q
- Bulk Operations with SDK
- Bulk Operations with SDK Quiz5q
- Optimistic Concurrency with ETags
- Optimistic Concurrency with ETags Quiz5q
- Query Pagination and Continuation
- Query Pagination and Continuation Quiz5q
- Cosmos DB Mirroring for Fabric
- Cosmos DB Mirroring for Fabric Quiz5q
- Mirroring vs Spark Connector
- Mirroring vs Spark Connector Quiz5q
- Enabling Analytical Store
- Enabling Analytical Store Quiz5q
- Synapse Spark and SQL Queries
- Synapse Spark and SQL Queries Quiz5q
- Change Data Capture in Analytical Store
- Change Data Capture in Analytical Store Quiz5q
- Azure Functions and Event Hubs Integration
- Azure Functions and Event Hubs Integration Quiz5q
- Denormalization with Change Feed
- Denormalization with Change Feed Quiz5q
- Referential Integrity with Change Feed
- Referential Integrity with Change Feed Quiz5q
- Azure AI Search Integration
- Azure AI Search Integration Quiz5q
- Azure Functions Change Feed Trigger
- Azure Functions Change Feed Trigger Quiz5q
- Consuming Change Feed with SDK
- Consuming Change Feed with SDK Quiz5q
- Change Feed Estimator
- Change Feed Estimator Quiz5q
- Denormalization via Change Feed
- Denormalization via Change Feed Quiz5q
- Aggregation Persistence with Change Feed
- Aggregation Persistence with Change Feed Quiz5q
- Read-Heavy vs Write-Heavy Indexing
- Read-Heavy vs Write-Heavy Indexing Quiz5q
- Index Type Selection
- Index Type Selection Quiz5q
- Custom Indexing Policies
- Custom Indexing Policies Quiz5q
- Composite Index Implementation
- Composite Index Implementation Quiz5q
- Index Performance Optimization
- Index Performance Optimization Quiz5q
- Response Status Codes and Metrics
- Response Status Codes and Metrics Quiz5q
- Normalized RU Consumption Monitoring
- Normalized RU Consumption Monitoring Quiz5q
- Server-Side Latency Metrics
- Server-Side Latency Metrics Quiz5q
- Data Replication Monitoring
- Data Replication Monitoring Quiz5q
- Azure Monitor Alerts Configuration
- Azure Monitor Alerts Configuration Quiz5q
- Resource Logs Implementation
- Resource Logs Implementation Quiz5q
- Partition Throughput Monitoring
- Partition Throughput Monitoring Quiz5q
- Encryption Key Management
- Encryption Key Management Quiz5q
- Network-Level Access Control
- Network-Level Access Control Quiz5q
- Data Encryption Configuration
- Data Encryption Configuration Quiz5q
- Azure RBAC for Control Plane
- Azure RBAC for Control Plane Quiz5q
- Microsoft Entra ID for Data Plane
- Microsoft Entra ID for Data Plane Quiz5q
- CORS Settings Configuration
- CORS Settings Configuration Quiz5q
- Customer-Managed Keys
- Customer-Managed Keys Quiz5q
- Always Encrypted Implementation
- Always Encrypted Implementation Quiz5q
- Data Movement Strategy Selection
- Data Movement Strategy Selection Quiz5q
- SDK Bulk Operations for Data Movement
- SDK Bulk Operations for Data Movement Quiz5q
- Azure Data Factory Pipelines
- Azure Data Factory Pipelines Quiz5q
- Kafka Connector Integration
- Kafka Connector Integration Quiz5q
- Azure Stream Analytics Integration
- Azure Stream Analytics Integration Quiz5q
- Cosmos DB Spark Connector
- Cosmos DB Spark Connector Quiz5q
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles the points you earn on every lesson and quiz so you progress twice as fast, unlocks half of every practice exam — plus full case studies — with the Learn & Exam study modes, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× points per lesson & quiz
- ✓ 50% of every exam unlocked
- ✓ Learn & Exam modes
- ✓ Distraction-free lessons