πŸ”’ Guided

Pre-launch preview. Authorised access only.

Incorrect code

Guided by A Guide to Cloud
Explore AB-900 AI-901 aws-aif-c01
Guided DP-420 Domain 4
Domain 4 β€” Module 2 of 4 50%
19 of 28 overall

DP-420 Study Guide

Domain 1: Design and Implement Data Models

  • Cosmos DB β€” The Big Picture Free
  • Designing Your Data Model Free
  • Partition Key Strategy Free
  • Synthetic and Hierarchical Partition Keys Free
  • Relationships β€” Embedding vs Referencing Free
  • SDK Connectivity and Client Configuration Free
  • SDK CRUD Operations and Transactions Free
  • SQL Queries in Cosmos DB Free
  • SDK Query Pagination and LINQ Free
  • Server-Side Programming Free
  • Transactions in Practice Free

Domain 2: Design and Implement Data Distribution

  • Global Replication and Failover
  • Consistency Levels: Five Choices, Real Trade-Offs
  • Multi-Region Writes and Conflict Resolution

Domain 3: Integrate and Move Data

  • Change Feed with Azure Functions and Processors
  • Analytical Workloads: Synapse Link and Fabric Mirroring
  • Data Movement: ADF, Kafka, and Spark Connectors

Domain 4: Optimize Query and Operation Performance

  • Indexing Policies: Range, Spatial, and Composite
  • Request Units and Query Cost Optimization
  • Integrated Cache and Dedicated Gateway
  • Change Feed Patterns: Materialized Views and Estimator

Domain 5: Maintain an Azure Cosmos DB Solution

  • Monitoring: Metrics, Logs, and Alerts
  • Backup and Restore: Periodic vs Continuous
  • Network Security: Firewalls, VNets, and Private Endpoints
  • Data Security: Encryption, Keys, and RBAC
  • Cost Optimization: Throughput Modes and RU Strategy
  • DevOps: Infrastructure as Code and Deployments
  • Exam Strategy and Cross-Domain Review

DP-420 Study Guide

Domain 1: Design and Implement Data Models

  • Cosmos DB β€” The Big Picture Free
  • Designing Your Data Model Free
  • Partition Key Strategy Free
  • Synthetic and Hierarchical Partition Keys Free
  • Relationships β€” Embedding vs Referencing Free
  • SDK Connectivity and Client Configuration Free
  • SDK CRUD Operations and Transactions Free
  • SQL Queries in Cosmos DB Free
  • SDK Query Pagination and LINQ Free
  • Server-Side Programming Free
  • Transactions in Practice Free

Domain 2: Design and Implement Data Distribution

  • Global Replication and Failover
  • Consistency Levels: Five Choices, Real Trade-Offs
  • Multi-Region Writes and Conflict Resolution

Domain 3: Integrate and Move Data

  • Change Feed with Azure Functions and Processors
  • Analytical Workloads: Synapse Link and Fabric Mirroring
  • Data Movement: ADF, Kafka, and Spark Connectors

Domain 4: Optimize Query and Operation Performance

  • Indexing Policies: Range, Spatial, and Composite
  • Request Units and Query Cost Optimization
  • Integrated Cache and Dedicated Gateway
  • Change Feed Patterns: Materialized Views and Estimator

Domain 5: Maintain an Azure Cosmos DB Solution

  • Monitoring: Metrics, Logs, and Alerts
  • Backup and Restore: Periodic vs Continuous
  • Network Security: Firewalls, VNets, and Private Endpoints
  • Data Security: Encryption, Keys, and RBAC
  • Cost Optimization: Throughput Modes and RU Strategy
  • DevOps: Infrastructure as Code and Deployments
  • Exam Strategy and Cross-Domain Review
Domain 4: Optimize Query and Operation Performance Premium ⏱ ~16 min read

Request Units and Query Cost Optimization

Understand what drives RU consumption in Cosmos DB, read costs from response headers, and apply five optimisation techniques to reduce query costs.

What are Request Units?

β˜• Simple explanation

Think of RU/s as a currency for database operations. Every read, write, and query costs a certain number of β€œcoins” (RU). Cosmos DB gives you a budget (provisioned RU/s) per second. If you spend faster than your budget, requests get throttled (429 errors).

A simple point read of a 1KB document costs ~1 RU. Writing that same document costs ~5-10 RU. Complex queries can cost hundreds. Your job is to keep costs low.

A Request Unit (RU) is a normalised measure of computational cost. It abstracts CPU, memory, and I/O into a single number. Key facts:

  • 1 RU = the cost of a point read of a 1KB document using its id and partition key.
  • Every operation returns its RU cost in the response headers.
  • Provisioned throughput is measured in RU/s β€” your per-second budget.
  • 429 errors occur when you exceed your provisioned RU/s.

Amara’s cost problem

πŸ“‘ Amara at SensorFlow provisioned 100,000 RU/s for her sensor readings container. After a month, she notices some queries cost 500+ RU each β€” 500Γ— more than a point read. With 500M daily events, inefficient queries are burning through her budget.

Factors that affect RU cost

FactorImpactExample
Document sizeLarger documents cost more to read/write1KB = ~1 RU read; 10KB = ~10 RU read
Property countMore indexed properties = higher write cost5 indexed props vs 20 indexed props
Consistency levelStrong/Bounded = 2Γ— read costSession read = 1 RU; Strong read = 2 RU
Query complexityCross-partition, no index, aggregations cost morePoint read = 1 RU; cross-partition scan = 500+ RU
Index utilisationQueries using indexes cost far lessIndexed filter = 3 RU; full scan = 300 RU
Response sizeMore results = more RU10 items = 5 RU; 1000 items = 50 RU

Reading RU cost from response headers

Every Cosmos DB response includes the RU charge:

// Point read β€” check RU cost
ItemResponse<SensorReading> response = await container.ReadItemAsync<SensorReading>(
    id: "reading-123",
    partitionKey: new PartitionKey("device-A")
);
double ruCost = response.RequestCharge;
Console.WriteLine($"Point read cost: {ruCost} RU");  // ~1 RU for 1KB

// Query β€” check RU cost
QueryDefinition query = new QueryDefinition(
    "SELECT * FROM c WHERE c.deviceId = @deviceId AND c.temperature > @threshold")
    .WithParameter("@deviceId", "device-A")
    .WithParameter("@threshold", 80);

FeedIterator<SensorReading> iterator = container.GetItemQueryIterator<SensorReading>(query);

double totalRU = 0;
while (iterator.HasMoreResults)
{
    FeedResponse<SensorReading> page = await iterator.ReadNextAsync();
    totalRU += page.RequestCharge;
    Console.WriteLine($"Page RU: {page.RequestCharge}, Items: {page.Count}");
}
Console.WriteLine($"Total query cost: {totalRU} RU");
πŸ’‘ Exam tip: RequestCharge is per page

For queries that return multiple pages, RequestCharge is reported per page, not for the entire query. You must sum the charges across all pages to get the total cost. The exam tests this β€” a query returning 5 pages of results has a total cost that’s the sum of all 5 page charges.

Five optimisation techniques

1. Use point reads when possible

// Point read: ~1 RU for 1KB (cheapest possible operation)
var response = await container.ReadItemAsync<SensorReading>(
    id: "reading-123",
    partitionKey: new PartitionKey("device-A")
);

// vs. Query for the same document: ~3 RU
// SELECT * FROM c WHERE c.id = 'reading-123' AND c.deviceId = 'device-A'

Rule: If you know the id and partition key, always use a point read instead of a query.

2. Scope queries to a single partition

-- Single-partition query (cheap): targets one partition
SELECT * FROM c WHERE c.deviceId = 'device-A' AND c.temperature > 80

-- Cross-partition query (expensive): fans out to ALL partitions
SELECT * FROM c WHERE c.temperature > 80

3. Project only needed fields

-- Returns entire document (all 20+ fields)
SELECT * FROM c WHERE c.deviceId = 'device-A'

-- Returns only needed fields (smaller response = fewer RU)
SELECT c.deviceId, c.temperature, c.timestamp FROM c WHERE c.deviceId = 'device-A'

4. Optimise indexing policy

Ensure your query’s WHERE and ORDER BY fields are indexed (covered in Module 18).

5. Use pagination with MaxItemCount

QueryRequestOptions options = new QueryRequestOptions
{
    MaxItemCount = 100  // limit items per page to control memory and RU per page
};

The capacity calculator

Microsoft provides an online Cosmos DB Capacity Calculator to estimate RU/s needs:

InputWhat to provide
Document sizeAverage size in KB
Reads/secPoint reads + queries per second
Writes/secCreates + updates per second
RegionsNumber of read/write regions
IndexingDefault or custom policy
πŸ’‘ Exam tip: 429 response handling

When you exceed provisioned RU/s, Cosmos DB returns a 429 TooManyRequests response with a Retry-After header (in milliseconds). The official SDKs have built-in retry logic that automatically waits and retries.

Exam questions may ask: β€œWhat should you do when getting 429 errors?” β€” the answer depends on context:

  • Transient: Let the SDK retry (built-in)
  • Persistent: Increase provisioned RU/s or enable autoscale
  • Query-specific: Optimise the query to reduce per-request RU cost

🎬 Video walkthrough

🎬 Video coming soon

Request Units and Query Cost β€” DP-420 Module 19

Request Units and Query Cost β€” DP-420 Module 19

~16 min

Flashcards

Question

How much does a point read of a 1KB document cost?

Click or press Enter to reveal answer

Answer

~1 RU. A point read (using id + partition key) is the cheapest possible operation. It's the baseline β€” 1 RU for 1KB. Larger documents cost proportionally more.

Click to flip back

Question

How do you get the RU cost of a Cosmos DB operation?

Click or press Enter to reveal answer

Answer

From the response's RequestCharge property (response.RequestCharge in C#) or the x-ms-request-charge HTTP header. For multi-page queries, sum the RequestCharge across all pages.

Click to flip back

Question

Why do Strong and Bounded Staleness consistency reads cost 2Γ— RU?

Click or press Enter to reveal answer

Answer

They require quorum confirmation β€” the read must be verified against multiple replicas before returning. Session, Consistent Prefix, and Eventual reads go to a single replica, costing 1Γ— RU.

Click to flip back

Question

What is the cheapest way to read a single document if you know its id and partition key?

Click or press Enter to reveal answer

Answer

A point read (ReadItemAsync). It costs ~1 RU for 1KB β€” cheaper than any SQL query for the same document. Always prefer point reads over queries when you have both the id and partition key.

Click to flip back

Knowledge Check

Knowledge Check

Amara notices a query costing 500 RU per execution. The query is: SELECT * FROM c WHERE c.temperature > 80. What's the most likely cause of the high cost?

Knowledge Check

A developer reads a document using: SELECT * FROM c WHERE c.id = 'reading-123' AND c.deviceId = 'device-A'. The query costs 3.5 RU. How can they reduce the cost?

Knowledge Check

Amara's query returns results across 5 pages. Each page reports RequestCharge of 20 RU. What is the total RU cost?


Next up: Integrated Cache and Dedicated Gateway β€” how to add a server-side cache layer that reduces RU consumption for read-heavy workloads.

← Previous

Indexing Policies: Range, Spatial, and Composite

Next β†’

Integrated Cache and Dedicated Gateway

Guided

I learn, I simplify, I share.

A Guide to Cloud YouTube Feedback

© 2026 Sutheesh. All rights reserved.

Guided is an independent study resource and is not affiliated with, endorsed by, or officially connected to Microsoft. Microsoft, Azure, and related trademarks are property of Microsoft Corporation. Always verify information against Microsoft Learn.