Reducing RU Consumption in Azure Cosmos DB for NoSQL
You develop an AI application that stores telemetry documents in Azure Cosmos DB for NoSQL. Each document contains 30 properties. Queries filter only on deviceId and timestamp. Write operations consume more RUs than expected. You need to reduce RU consumption for write operations while maintaining query performance. What should you do?
Community Insight
The question tests the trade-off between index size and write overhead; the common trap is assuming all default indexes are necessary for query performance.
Optimize write performance in Azure Cosmos DB for NoSQL by configuring selective indexing to exclude unused properties. This approach reduces Request Unit (RU) costs while maintaining query efficiency on filtered fields.
Users often select 'Enable strong consistency' or 'Migrate partition key', failing to recognize that these actions do not address the specific overhead caused by maintaining unnecessary indexes.
Community Discussion (1 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
Azure Cosmos DB for NoSQL automatically indexes all properties by default, which significantly increases the RU cost of write operations as every property update requires index maintenance. By configuring selective indexing (Option B), you can explicitly define which properties to index—specifically 'deviceId' and 'timestamp' in this scenario—and exclude the other 27 unused properties. This directly reduces the storage footprint and the computational overhead during writes, achieving the goal of lower RU consumption without impacting the required query performance.Why the Other Options Are Wrong
Option A is technically similar but less precise; 'selective indexing' is the standard configuration method to achieve exclusion, making B the superior architectural answer. Option C addresses data distribution and hot partitions but does not reduce the per-document index overhead. Option D increases consistency checks, which typically raises RU consumption rather than reducing it.Community Comment Notes
Community feedback confirms that since queries only filter on two properties, indexing all 30 is wasteful. As noted by user sanitest, "Because your queries only filter on deviceId and timestamp, there is no benefit in indexing all 30 properties." This aligns with the best practice of minimizing indexed paths to optimize write throughput.Exam Strategy
Always analyze the query patterns first. If a document has many properties but queries only use a few, configure selective indexing to minimize write overhead.
Frequently Asked Questions
Why does indexing all properties increase write RUs?
Cosmos DB updates secondary indexes for every property change. More indexed properties mean more work per write operation.
Does selective indexing affect query speed?
No, as long as you include all properties used in WHERE clauses or JOINs, query performance remains optimal.