This post is a part of the AI-200: Developing AI Cloud Solutions on Azure Exam Prep Hub.
This topic falls under these sections:
Develop AI solutions by using Azure data management services (25–30%)
--> Develop AI solutions by using Azure Cosmos DB for NoSQL
--> Optimize query performance and Request Units (RUs) consumption by using indexing policies and consistency levels
Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.
Overview
Azure Cosmos DB for NoSQL is designed to provide globally distributed, low-latency access to JSON data at scale. A key part of developing efficient Cosmos DB solutions is understanding how queries consume Request Units (RUs) and how indexing policies and consistency levels affect query performance, throughput, latency, and cost.
For the AI-200 exam, you should understand how to:
- Explain what RUs represent.
- Identify factors that increase or decrease RU consumption.
- Understand how indexes improve query performance.
- Configure indexing policies.
- Include or exclude property paths from indexing.
- Understand range and composite indexes.
- Recognize when a query is likely to require a full scan.
- Understand the relationship between partition keys and query performance.
- Understand the five Cosmos DB consistency levels.
- Choose an appropriate consistency level based on application requirements.
- Understand how consistency affects read throughput.
- Use query metrics to investigate expensive queries.
A useful way to think about optimization is:
Efficient Cosmos DB queries minimize the amount of data that must be examined and returned while using an indexing and consistency strategy appropriate for the application’s requirements.
1. Understanding Request Units (RUs)
Azure Cosmos DB uses Request Units (RUs) as a normalized measure of the resources required to perform database operations.
Instead of pricing or throttling individual operations according to CPU time, disk operations, memory, and other implementation details, Cosmos DB abstracts those resources into RUs.
For example, operations such as:
- Creating an item
- Reading an item
- Updating an item
- Deleting an item
- Running a query
consume RUs.
The amount of RU consumption depends on the work required to perform the operation.
Important exam concept
The number of items returned is not the only factor determining RU consumption.
A query can return a small number of items while still consuming significant RUs if Cosmos DB has to examine a large amount of data.
Conversely, an efficiently indexed query may examine a relatively small amount of data and consume fewer RUs.
2. What Determines RU Consumption?
Several factors influence the RU charge of a request.
Common factors include:
- Size of the items being read or written
- Number of items involved
- Number of properties being indexed
- Query complexity
- Whether indexes can be used efficiently
- Whether the query is single-partition or cross-partition
- Number of partitions involved
- Amount of data returned
- Consistency level
- Type of operation
For example, consider:
SELECT *FROM cWHERE c.customerId = "C1001"
If customerId is efficiently indexed and the query can target the appropriate partition, the query can be relatively inexpensive.
A query such as:
SELECT *FROM cWHERE c.description = "some value"
may be considerably more expensive if the query requires examining many partitions or cannot efficiently use an appropriate index.
3. Why Indexing Matters
Azure Cosmos DB for NoSQL automatically indexes properties by default.
This means developers generally don’t have to create indexes manually before executing common queries.
The default indexing policy indexes every property of every item, using range indexes for string and numeric values.
This default behavior provides good general-purpose query performance.
However, an application may benefit from a custom indexing policy.
For example, suppose documents contain:
{ "id": "1001", "customerId": "C1001", "name": "Norm", "description": "...", "largeMetadata": { "property1": "...", "property2": "...", "property3": "..." }}
If the application frequently queries:
WHERE c.customerId = "C1001"
but never queries largeMetadata, indexing every property may provide little benefit while increasing index storage and indexing work.
A custom indexing policy can exclude paths that aren’t needed for queries.
4. Indexing and Write Costs
Indexes aren’t free.
When an item is created or modified, Cosmos DB must maintain the indexes associated with that item.
Therefore, extensive indexing can increase:
- Write RU consumption
- Index storage
- Index maintenance work
This creates an important optimization tradeoff:
| Strategy | Potential benefit | Potential cost |
|---|---|---|
| Index many properties | Better query flexibility | More index storage and write overhead |
| Index fewer properties | Lower indexing overhead | Some queries may require scans |
| Use composite indexes | Efficient supported multi-property queries | Additional index maintenance |
| Use default policy | Simple and broadly effective | May index properties the application never queries |
The goal isn’t to minimize indexes at all costs.
The goal is to index the paths required by the application’s query workload.
5. Indexing Modes
Azure Cosmos DB for NoSQL supports indexing modes that determine how indexes are maintained.
The important mode for normal querying is:
Consistent
The index is updated synchronously as items are created, updated, or deleted.
This provides predictable query behavior and is the normal indexing mode for queryable containers.
A container can also have indexing disabled by setting the indexing mode to none.
This can be useful for workloads where secondary indexing isn’t needed, such as certain key-value-style scenarios or some bulk-loading scenarios.
However, queries against a container without the necessary indexes may require scans and can therefore consume significantly more RUs.
6. Included and Excluded Paths
One of the most important ways to customize an indexing policy is through included paths and excluded paths.
An indexing policy can essentially answer:
Which JSON properties should Cosmos DB index?
For example:
{ "indexingMode": "consistent", "includedPaths": [ { "path": "/*" } ], "excludedPaths": [ { "path": "/largeMetadata/*" } ]}
This approach indexes the document generally while excluding a portion that isn’t queried.
A useful rule is:
Exclude properties that don’t need to participate in queries, especially large or frequently changing properties, when doing so is appropriate for the workload.
The indexing-policy documentation recommends using an include-root/exclude-specific-path strategy when you want new properties added to the data model to be indexed automatically unless explicitly excluded.
7. The Partition Key Is Critical to Query Performance
Indexing alone does not guarantee an inexpensive query.
The partition key is also extremely important.
Consider a container partitioned by:
/customerId
A query such as:
SELECT *FROM cWHERE c.customerId = "C1001"
can potentially be targeted to a single logical partition.
Compare that with:
SELECT *FROM cWHERE c.city = "Orlando"
If city isn’t the partition key, Cosmos DB may need to execute the query across multiple partitions.
This is called a cross-partition query.
Cross-partition queries can consume more RUs because multiple partitions may need to participate.
Exam takeaway
When analyzing a query, don’t ask only:
“Is the property indexed?”
Also ask:
“Can the query be directed to the appropriate partition?”
A well-designed partition key and appropriate indexing policy work together.
8. Partition Key Indexing
There is an important detail that can appear in exam questions.
A partition key property isn’t automatically indexed merely because it is the partition key.
If the partition key isn’t /id, it should generally be included in the indexing policy when queries filter on it. Otherwise, queries using that property can be forced into full scans, increasing RU consumption.
For example, if the partition key is:
/customerId
and the application frequently queries:
WHERE c.customerId = "C1001"
the indexing policy should support that path.
9. Types of Indexes
Azure Cosmos DB supports several index types.
For AI-200, you should understand at least the major concepts surrounding:
- Range indexes
- Composite indexes
- Spatial indexes
- Vector indexes
The most important indexes for traditional query optimization are range and composite indexes.
10. Range Indexes
Range indexes are based on an ordered structure and can support many common query operations.
They can support operations such as:
=
>
<
>=
<=
as well as certain ORDER BY, JOIN, and string-function scenarios.
For example:
SELECT *FROM cWHERE c.price > 100
can benefit from an appropriate range index on price.
Similarly:
SELECT *FROM cORDER BY c.price
requires a range index on the ordered property.
11. Composite Indexes
A composite index indexes multiple properties together.
Composite indexes are particularly useful for queries involving multiple properties and certain combinations of filtering and sorting.
For example:
SELECT *FROM cWHERE c.category = "AI"ORDER BY c.timestamp DESC
may benefit from an appropriate composite index involving:
/category/timestamp
The order of properties in a composite index matters.
For example, these are not necessarily interchangeable:
(category ASC, timestamp DESC)
and:
(timestamp DESC, category ASC)
The appropriate ordering depends on the query workload.
Exam tip
If a question describes a query using multiple properties with filtering and/or ordering, think:
Could a composite index make this query more efficient?
12. Index Utilization
Cosmos DB’s query engine can use indexes in different ways.
The query engine can perform operations ranging from highly efficient index seeks to full scans.
Generally, the progression is:
- Index seek
- Precise index scan
- Expanded index scan
- Full index scan
- Full scan
An index seek is particularly efficient because the query engine can identify the relevant index entries without examining the entire dataset.
A full scan is considerably more expensive because Cosmos DB must inspect the underlying data rather than efficiently locating matching records through an appropriate index.
13. Why SELECT * Can Cost More
The amount of data returned affects RU consumption.
Consider:
SELECT *FROM cWHERE c.customerId = "C1001"
versus:
SELECT c.id, c.nameFROM cWHERE c.customerId = "C1001"
The second query may consume fewer RUs because it returns less data.
This leads to an important optimization principle:
Return only the properties your application needs.
Avoid retrieving large documents when only a few properties are required.
14. Avoid Unnecessary Cross-Partition Queries
Suppose a container has:
Partition key: /customerId
This query can potentially target a partition:
SELECT c.id, c.nameFROM cWHERE c.customerId = "C1001"
But this query may involve many partitions:
SELECT c.id, c.nameFROM cWHERE c.status = "Active"
If status isn’t the partition key, Cosmos DB may need to query multiple partitions.
Cross-partition queries aren’t inherently bad.
They are sometimes necessary.
The important point is:
Don’t accidentally create expensive cross-partition queries when the application can supply the partition key.
15. Measuring Query RU Consumption
The Cosmos DB SDKs provide information about the RU charge associated with operations.
For example, application code can inspect the response from a query and determine how many RUs were consumed.
This is valuable because optimization should be based on actual workload measurements rather than assumptions.
When troubleshooting an expensive query, examine:
- RU charge
- Query execution time
- Number of returned documents
- Index utilization
- Number of partitions involved
- Query predicates
- Requested properties
- Partition-key usage
16. Index Transformation
Changing an indexing policy can cause Cosmos DB to perform an index transformation.
For example, adding an indexed path requires Cosmos DB to build the new index for existing data.
Index transformation is asynchronous and consumes RUs. Queries begin using a newly added indexed path after the index transformation has completed.
This is important operationally.
If you replace one index with another, a good strategy is generally:
- Add the new index.
- Wait for the transformation to complete.
- Verify the workload.
- Remove the old index if it is no longer required.
Removing an indexed path takes effect immediately, so removing an index before the replacement is ready can temporarily cause queries to fall back to scans.
17. Understanding Consistency Levels
Indexing affects how efficiently data can be located.
Consistency affects what version of the data a read is allowed to return.
Azure Cosmos DB provides five consistency levels, ordered from strongest to weakest:
- Strong
- Bounded staleness
- Session
- Consistent prefix
- Eventual
Choosing the consistency level is a business and application decision.
You should not automatically select the strongest consistency level.
18. Strong Consistency
Strong consistency guarantees that reads return the latest committed version of the data.
This provides the strongest read guarantee.
The tradeoff is that strong consistency can increase write latency and reduce availability in some globally distributed scenarios because replicas must satisfy the stronger synchronization requirements.
Appropriate scenarios
Strong consistency may be appropriate for scenarios where stale data is unacceptable, such as:
- Certain financial transactions
- Critical inventory decisions
- Applications requiring immediate globally consistent reads
Exam clue
If a question says:
“The application must always read the most recently committed value.”
Think:
Strong consistency.
19. Bounded Staleness
Bounded staleness guarantees that reads aren’t allowed to become older than a configured limit based on:
- Time
- Number of versions/operations
This is useful when the application can tolerate a controlled amount of replication lag but needs a stronger guarantee than eventual consistency.
For example:
“Data can be up to a few seconds old, but never older than that.”
This points toward bounded staleness.
Bounded staleness is particularly relevant to globally distributed applications that need near-strong consistency without the full cost of strong consistency.
20. Session Consistency
Session consistency is commonly useful for interactive applications.
It provides guarantees such as:
- Read-your-writes
- Monotonic reads
- Monotonic writes
In practical terms, a user who writes data should be able to read that data within the same session.
For example:
- User updates their profile.
- User immediately refreshes the profile.
- The application should see the user’s update.
Session consistency is often a good balance between strong consistency and scalability.
21. Consistent Prefix
Consistent prefix guarantees that reads see writes in the order they occurred, without observing them out of sequence.
The application may not immediately see every write, but it won’t see writes in an inconsistent order.
For example, suppose writes occur in this order:
A → B → C → D
A reader might see:
AA, BA, B, CA, B, C, D
but shouldn’t see:
A, C
while missing B.
22. Eventual Consistency
Eventual consistency provides the weakest consistency guarantee.
Different replicas may temporarily return different values, but replicas eventually converge.
The major advantages include:
- Lower coordination requirements
- High availability
- Good performance
- Lower latency in many distributed scenarios
Eventual consistency may be appropriate for:
- Social feeds
- Recommendation systems
- Analytics dashboards
- Non-critical status information
- Content where temporary staleness is acceptable
23. Consistency and Read Throughput
Consistency isn’t simply about correctness.
It can also affect read throughput.
For strong and bounded staleness consistency, reads are performed against two replicas in a four-replica set to satisfy the consistency guarantees.
Session, consistent prefix, and eventual consistency use single-replica reads.
Consequently, for the same number of provisioned RUs, strong and bounded staleness consistency provide approximately half the read throughput of the weaker consistency levels.
This is a very important AI-200 exam concept.
Remember:
Stronger consistency can consume more read capacity.
Therefore, if an application does not require strong consistency, relaxing the consistency requirement can improve read scalability.
24. Consistency Does Not Change Write RU Charges
For the same type of write operation, write RU consumption is generally identical across consistency levels.
However, stronger consistency can have other performance implications, particularly around replication and latency.
Therefore, don’t confuse:
Consistency → read behavior and read throughput
with:
Indexing → query efficiency and index maintenance
Both affect application performance, but in different ways.
25. Choosing the Right Consistency Level
A useful decision framework is:
| Requirement | Recommended consideration |
|---|---|
| Must always see the latest committed value | Strong |
| Can tolerate a precisely bounded amount of staleness | Bounded staleness |
| Users need read-your-writes behavior | Session |
| Writes must appear in order but can be delayed | Consistent prefix |
| Temporary inconsistency is acceptable | Eventual |
The key is to choose the weakest consistency level that still satisfies the application’s requirements.
This can improve scalability and reduce unnecessary coordination.
26. Combining Indexing and Consistency Optimization
Indexing and consistency should be considered separately.
Suppose an application has an expensive query.
You might investigate:
Indexing
- Is the filtered property indexed?
- Is an appropriate range index available?
- Is a composite index appropriate?
- Is the partition key included in the indexing policy?
- Is the query performing a full scan?
- Are unnecessary properties being indexed?
Query design
- Is the partition key supplied?
- Is the query unnecessarily cross-partition?
- Is
SELECT *returning unnecessary data? - Can the query be simplified?
Consistency
- Does the application actually require strong consistency?
- Could session consistency satisfy the requirement?
- Could eventual consistency satisfy the requirement?
This distinction is important:
Don’t try to solve every RU problem by changing the indexing policy.
Likewise:
Don’t weaken consistency when the application actually requires stronger guarantees.
27. A Practical Optimization Example
Imagine an AI-powered customer-support application.
The container contains millions of support conversations.
The partition key is:
/customerId
The application runs:
SELECT *FROM cWHERE c.customerId = "C1001"AND c.status = "Open"ORDER BY c.createdDate DESC
Several optimization questions should be considered.
Question 1: Can the query target a partition?
Yes.
It specifies:
customerId = C1001
which is the partition key.
Question 2: Are the relevant properties indexed?
The query uses:
customerIdstatuscreatedDate
The indexing policy should support the query.
Question 3: Would a composite index help?
Potentially.
The query combines filtering and sorting across multiple properties, so a composite index may be appropriate depending on the exact query workload and index requirements.
Question 4: Does the application need every property?
Perhaps not.
Instead of:
SELECT *
the application could retrieve only:
SELECT c.id, c.status, c.createdDate, c.subject
Question 5: Does the application need strong consistency?
If the support application can tolerate some temporary staleness, a weaker consistency level may provide better read scalability.
This illustrates an important principle:
Query performance is usually the result of several design decisions working together.
28. Common AI-200 Exam Traps
Trap 1: “Indexes always reduce RU consumption.”
Not necessarily.
Indexes can reduce the amount of data that must be examined for queries, but maintaining indexes also adds write and storage overhead.
Trap 2: “The partition key automatically makes the property indexed.”
Not necessarily.
The partition key should be considered separately from the indexing policy. A partition key property should be included in the indexing policy when queries need to efficiently filter on it.
Trap 3: “Strong consistency is always better.”
Strong consistency provides stronger guarantees, but it can reduce read throughput and increase latency/availability tradeoffs.
Choose it only when required.
Trap 4: “Eventual consistency means data is permanently inconsistent.”
No.
Eventual consistency means replicas may temporarily disagree, but they eventually converge.
Trap 5: “A query returning one item must be inexpensive.”
Not necessarily.
Cosmos DB may have to examine many items or partitions to discover that single matching item.
Trap 6: “Cross-partition queries are always wrong.”
No.
Cross-partition queries are sometimes necessary.
The goal is to avoid unnecessary cross-partition queries and design the partition key appropriately for the workload.
Trap 7: “Removing an index is harmless.”
Removing an index can cause queries that depended on it to fall back to less efficient execution, potentially increasing RU consumption.
29. AI-200 Exam Quick Reference
| Concept | Remember |
|---|---|
| RU | Normalized unit of Cosmos DB resource consumption |
| Index | Helps locate matching data efficiently |
| Default indexing | Automatically indexes properties by default |
| Custom indexing | Can include/exclude paths |
| Range index | Equality, range, ordering, and other supported operations |
| Composite index | Multiple-property query patterns |
| Full scan | Potentially expensive; examines underlying data broadly |
| Partition key | Determines data distribution and can enable targeted queries |
| Cross-partition query | May require querying multiple partitions |
SELECT * | Can return more data and increase RU consumption |
| Strong consistency | Latest committed value |
| Bounded staleness | Controlled maximum staleness |
| Session | Read-your-writes and session guarantees |
| Consistent prefix | Writes observed in order |
| Eventual | Temporary inconsistency allowed |
| Strong/bounded read throughput | Lower than weaker levels for same RU allocation |
| Index transformation | Asynchronous and consumes RUs |
| Best practice | Choose indexes and consistency based on workload requirements |
Practice Exam Questions
Question 1
An application stores customer records in Azure Cosmos DB for NoSQL. The container is partitioned by /customerId. The application frequently executes the following query:
SELECT *FROM cWHERE c.customerId = "C1005"
The developer wants to minimize RU consumption.
Which approach is most appropriate?
A. Add a spatial index to the customerId property.
B. Disable indexing so the query engine can scan the container faster.
C. Change the consistency level to Strong regardless of the application’s requirements.
D. Ensure the customerId path is appropriately indexed and provide the partition key value when executing the query.
Answer: D
Explanation
The query uses the partition key, allowing Cosmos DB to target the appropriate logical partition. The property should also be appropriately indexed when queries filter on it. This combination can significantly improve query efficiency.
Disabling indexing would generally make query execution less efficient. Spatial indexes are intended for geospatial data, not customer identifiers. Strong consistency does not inherently optimize this query.
Question 2
A globally distributed application displays product recommendations. Recommendations can be temporarily stale as long as replicas eventually converge.
Which consistency level is generally the most appropriate?
A. Strong
B. Bounded staleness
C. Session
D. Eventual
Answer: D
Explanation
The application explicitly permits temporary staleness and does not require read-your-writes or strict ordering guarantees. Eventual consistency is therefore appropriate.
Strong consistency provides stronger guarantees than necessary. Bounded staleness provides a specific staleness guarantee that isn’t required by the scenario. Session consistency would provide stronger session-level guarantees than needed.
Question 3
A Cosmos DB container contains documents with hundreds of properties. An application queries only /customerId, /status, and /createdDate. Many large metadata properties are never queried.
The development team wants to reduce indexing overhead and index storage.
What should they consider?
A. Enable strong consistency.
B. Customize the indexing policy to exclude properties that don’t need to be queried.
C. Remove the partition key.
D. Replace all range indexes with spatial indexes.
Answer: B
Explanation
A custom indexing policy can exclude properties that don’t participate in queries. This can reduce index size and indexing maintenance overhead.
Changing consistency doesn’t address unnecessary indexes. Removing the partition key is not an appropriate optimization, and spatial indexes aren’t appropriate for ordinary scalar properties such as customer IDs and status values.
Question 4
An application requires that a user immediately see an item after the user creates it, but the application does not require globally strong consistency for every user.
Which consistency level is generally the best fit?
A. Eventual
B. Consistent prefix
C. Session
D. Strong
Answer: C
Explanation
Session consistency provides read-your-writes behavior and is well suited to interactive applications where a user expects to see their own changes.
Eventual consistency doesn’t provide the same session guarantees. Consistent prefix guarantees write ordering but doesn’t provide the same read-your-writes behavior. Strong consistency is stronger than necessary for the stated requirement.
Question 5
A query returns only one document but consumes a surprisingly large number of RUs. The query doesn’t specify the partition key and runs against a container with many physical partitions.
What is the most likely explanation?
A. Cosmos DB charges a fixed RU amount for every returned document.
B. The query must always use a spatial index.
C. The query may be executing across multiple partitions and examining significant amounts of data before finding the matching document.
D. Returning one document always requires Strong consistency.
Answer: C
Explanation
The number of returned documents isn’t the only determinant of RU consumption. A cross-partition query can require Cosmos DB to examine multiple partitions, potentially consuming significant RUs even if only one document ultimately matches.
There is no fixed RU charge per returned document, spatial indexing is unrelated, and consistency doesn’t automatically become Strong because one document is returned.
Question 6
A query uses:
SELECT *FROM cWHERE c.category = "AI"ORDER BY c.timestamp DESC
The application frequently executes this query and wants to optimize its performance.
Which index type should the developer investigate first?
A. Composite index
B. Spatial index
C. Vector index
D. No index; ORDER BY queries cannot use indexes
Answer: A
Explanation
The query uses multiple properties in filtering and ordering. A composite index can be useful for query patterns involving multiple properties and sorting.
Spatial indexes are designed for geospatial operations. Vector indexes are designed for vector search. Cosmos DB can use indexes for ORDER BY operations.
Question 7
An application currently uses Strong consistency. Performance testing shows that read throughput is insufficient. The application requirements state that users only need read-your-writes behavior within their own sessions.
What should the developer consider?
A. Add a spatial index.
B. Change the partition key to /id without analyzing the workload.
C. Disable all indexes.
D. Use Session consistency if it satisfies the application’s requirements.
Answer: D
Explanation
Session consistency provides read-your-writes behavior and other session-level guarantees while avoiding the stronger coordination requirements of Strong consistency.
Changing the partition key or disabling indexes doesn’t directly address the stated consistency requirement. Spatial indexing is unrelated.
Question 8
A developer removes an indexed path from a Cosmos DB indexing policy because the property is no longer queried. An existing query unexpectedly begins consuming substantially more RUs.
What is the most likely explanation?
A. Removing an indexed path causes all writes to become strongly consistent.
B. The query may no longer be able to use the removed index and may fall back to a less efficient scan.
C. Removing an index automatically converts the container into a different API.
D. Cosmos DB stops supporting partitioning when an index is removed.
Answer: B
Explanation
When an indexed path is removed, queries that relied on that index may no longer be able to use it and can fall back to a full scan or another less efficient execution strategy. This can substantially increase RU consumption.
The other options describe behaviors that don’t occur as a result of removing an indexed path.
Question 9
A company wants to ensure that reads never return a value older than a configured amount of time or number of updates, but it doesn’t require Strong consistency.
Which consistency level should the developer select?
A. Eventual
B. Session
C. Bounded staleness
D. Consistent prefix
Answer: C
Explanation
Bounded staleness is specifically designed for scenarios where the application can tolerate a controlled amount of staleness based on time or the number of versions/operations.
Eventual consistency provides no such bounded staleness guarantee. Session consistency focuses on session-level guarantees, while consistent prefix guarantees write ordering rather than a specific staleness bound.
Question 10
A Cosmos DB account has a workload dominated by read operations. The application doesn’t require Strong or Bounded Staleness consistency. The team wants to maximize read throughput for the same provisioned RU capacity.
Which approach is most appropriate?
A. Use Session, Consistent Prefix, or Eventual consistency according to the application’s requirements.
B. Increase indexing on every possible property.
C. Change every query to SELECT *.
D. Use Strong consistency for all queries.
Answer: A
Explanation
Strong and Bounded Staleness consistency use more replicas for reads and therefore provide approximately half the read throughput of Session, Consistent Prefix, and Eventual consistency for the same RU allocation.
If the application doesn’t require the stronger guarantees, using an appropriate weaker consistency level can improve read scalability.
Increasing indexes can help particular queries but doesn’t address the consistency-related read-throughput issue. SELECT * can actually increase data returned and RU consumption, while Strong consistency would move in the opposite direction from the desired optimization.
Final Exam Takeaways
For AI-200, the most important concepts to remember are:
- RUs represent the resources consumed by Cosmos DB operations.
- Indexes can make queries substantially more efficient, but maintaining indexes has a cost.
- The default indexing policy indexes properties automatically.
- Custom indexing policies can include or exclude property paths.
- Range indexes support many common equality, range, and ordering operations.
- Composite indexes are important for appropriate multi-property query patterns.
- A partition-key-aware query is generally more efficient than an unnecessary cross-partition query.
- The partition key should be considered separately from indexing.
- Returning unnecessary data, such as with
SELECT *, can increase RU consumption. - Strong consistency provides the strongest read guarantee but has performance and availability tradeoffs.
- Bounded staleness provides a controlled staleness guarantee.
- Session consistency provides important read-your-writes behavior for interactive applications.
- Consistent prefix preserves write ordering.
- Eventual consistency provides the weakest guarantees but can maximize scalability and availability.
- Strong and bounded staleness provide lower read throughput for the same RU allocation than Session, Consistent Prefix, and Eventual consistency.
- Index transformations consume RUs and occur asynchronously.
- When optimizing Cosmos DB, consider the combination of partitioning, indexing, query design, returned data, and consistency—not any one factor in isolation.
Go to the AI-200 Exam Prep Hub main page
