-
Notifications
You must be signed in to change notification settings - Fork 30
Add integrated cache best practice rule #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Bhuvansh (BHUVANSH855)
wants to merge
1
commit into
AzureCosmosDB:main
Choose a base branch
from
BHUVANSH855:issue-172-integrated-cache-rule
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "azure-cosmosdb", | ||
| "version": "1.2.0", | ||
| "version": "1.2.1", | ||
| "description": "Official Gemini extension for Azure Cosmos DB (NoSQL). Provides best practice skills for data modeling, partition key design, query optimization, indexing, vector search, full-text search, global distribution, security, and more.", | ||
| "skills": "./skills/" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
skills/cosmosdb-best-practices/rules/throughput-integrated-cache.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| --- | ||
| title: Use Integrated Cache for Read-Heavy Workloads with Dedicated Gateway | ||
| impact: MEDIUM | ||
| impactDescription: reduces RU consumption and latency for repeated reads | ||
| tags: throughput, integrated-cache, dedicated-gateway, performance, cost, read-heavy | ||
| --- | ||
|
|
||
| ## Use Integrated Cache for Read-Heavy Workloads with Dedicated Gateway | ||
|
|
||
| **Impact: MEDIUM (reduces RU consumption and latency for repeated reads)** | ||
|
|
||
| For workloads that repeatedly read the same items or execute the same queries, Azure Cosmos DB's integrated cache can significantly reduce RU consumption and improve response latency. The integrated cache is available only when using a **dedicated gateway**. Cached point reads and queries can be served without contacting backend replicas until the configured cache staleness window expires. | ||
|
|
||
| Use the `MaxIntegratedCacheStaleness` request option to control how stale cached results are allowed to be. Integrated cache is appropriate for read-heavy workloads where slightly stale data is acceptable, but it only applies to reads using **Session** or **Eventual** consistency. | ||
|
|
||
| **Incorrect (point reads without integrated cache):** | ||
|
|
||
| ```csharp | ||
| var client = new CosmosClient(connectionString); | ||
| var container = client.GetContainer("database", "container"); | ||
|
|
||
| var response = await container.ReadItemAsync<Product>( | ||
| "product-1", | ||
| new PartitionKey("electronics")); | ||
| ``` | ||
|
|
||
| Every repeated request is sent to the backend, consuming RUs even when the data has not changed. | ||
|
|
||
| **Correct (use dedicated gateway with integrated cache):** | ||
|
|
||
| ```csharp | ||
| var client = new CosmosClient( | ||
| dedicatedGatewayConnectionString, | ||
| new CosmosClientOptions | ||
| { | ||
| ConnectionMode = ConnectionMode.Gateway | ||
| }); | ||
|
|
||
| var container = client.GetContainer("database", "container"); | ||
|
|
||
| var options = new ItemRequestOptions | ||
| { | ||
| DedicatedGatewayRequestOptions = new DedicatedGatewayRequestOptions | ||
| { | ||
| MaxIntegratedCacheStaleness = TimeSpan.FromMinutes(5) | ||
| } | ||
| }; | ||
|
|
||
| var response = await container.ReadItemAsync<Product>( | ||
| "product-1", | ||
| new PartitionKey("electronics"), | ||
| options); | ||
| ``` | ||
|
|
||
| Guidance: | ||
|
|
||
| - Use integrated cache for read-heavy workloads with frequent repeated point reads or queries. | ||
| - Connect through the **dedicated gateway** endpoint to enable integrated cache. | ||
| - Configure `MaxIntegratedCacheStaleness` based on how much stale data your application can tolerate. | ||
| - Use integrated cache only when **Eventual** or **Session** consistency satisfies application requirements. | ||
| - Do not rely on integrated cache for workloads requiring **Strong**, **Bounded Staleness**, or **Consistent Prefix** consistency guarantees. | ||
|
|
||
| Reference: <https://learn.microsoft.com/azure/cosmos-db/integrated-cache> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.