Skip to content

Commit a6cc19e

Browse files
Merge pull request #230970 from jcocchi/update-integrated-cache
Cosmos DB: update integrated cache docs
2 parents 17881fa + 56e6ae6 commit a6cc19e

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

articles/cosmos-db/dedicated-gateway.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,20 @@ The dedicated gateway is available in the following sizes. The integrated cache
6969
| **D8s** | **8** | **32 GB** |
7070
| **D16s** | **16** | **64 GB** |
7171

72-
> [!NOTE]
72+
> [!TIP]
7373
> Once created, you can add or remove dedicated gateway nodes, but you can't modify the size of the nodes. To change the size of your dedicated gateway nodes you can deprovision the cluster and provision it again in a different size. This will result in a short period of downtime unless you change the connection string in your application to use the standard gateway during reprovisioning.
7474
7575
There are many different ways to provision a dedicated gateway:
7676

77-
- [Provision a dedicated gateway using the Azure Portal](how-to-configure-integrated-cache.md#provision-the-dedicated-gateway)
77+
- [Provision a dedicated gateway using the Azure portal](how-to-configure-integrated-cache.md#provision-the-dedicated-gateway)
7878
- [Use Azure Cosmos DB's REST API](/rest/api/cosmos-db-resource-provider/2022-05-15/service/create#sqldedicatedgatewayservicecreate)
7979
- [Azure CLI](/cli/azure/cosmosdb/service?view=azure-cli-latest&preserve-view=true#az-cosmosdb-service-create)
8080
- [ARM template](/azure/templates/microsoft.documentdb/databaseaccounts/services?tabs=bicep)
8181
- Note: You cannot deprovision a dedicated gateway using ARM templates
8282

83+
> [!NOTE]
84+
> You can provision a dedicated gateway in Azure Cosmos DB accounts with [availability zones](../availability-zones/az-region.md) by request. Reach out to [email protected] for more information.
85+
8386
## Dedicated gateway in multi-region accounts
8487

8588
When you provision a dedicated gateway cluster in multi-region accounts, identical dedicated gateway clusters are provisioned in each region. For example, consider an Azure Cosmos DB account in East US and North Europe. If you provision a dedicated gateway cluster with two D8 nodes in this account, you'd have four D8 nodes in total - two in East US and two in North Europe. You don't need to explicitly configure dedicated gateways in each region and your connection string remains the same. There are also no changes to best practices for performing failovers.
@@ -91,7 +94,6 @@ Like nodes within a cluster, dedicated gateway nodes across regions are independ
9194
The dedicated gateway has the following limitations:
9295

9396
- Dedicated gateways are only supported on API for NoSQL accounts
94-
- You can't provision a dedicated gateway in Azure Cosmos DB accounts with [availability zones](../availability-zones/az-region.md).
9597
- You can't use [role-based access control (RBAC)](how-to-setup-rbac.md) to authenticate data plane requests routed through the dedicated gateway
9698

9799

articles/cosmos-db/integrated-cache.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ ms.service: cosmos-db
66
ms.subservice: nosql
77
ms.custom: ignite-2022
88
ms.topic: conceptual
9-
ms.date: 08/29/2022
9+
ms.date: 03/15/2023
1010
ms.author: sidandrews
1111
ms.reviewer: jucocchi
1212
---
1313

1414
# Azure Cosmos DB integrated cache - Overview
1515
[!INCLUDE[NoSQL](includes/appliesto-nosql.md)]
1616

17-
The Azure Cosmos DB integrated cache is an in-memory cache that helps you ensure manageable costs and low latency as your request volume grows. The integrated cache is easy to set up and you don’t need to spend time writing custom code for cache invalidation or managing backend infrastructure. Your integrated cache uses a [dedicated gateway](dedicated-gateway.md) within your Azure Cosmos DB account. The integrated cache is the first of many Azure Cosmos DB features that will utilize a dedicated gateway for improved performance. You can choose from three possible dedicated gateway sizes based on the number of cores and memory needed for your workload.
17+
The Azure Cosmos DB integrated cache is an in-memory cache that helps you ensure manageable costs and low latency as your request volume grows. The integrated cache is easy to set up and you don’t need to spend time writing custom code for cache invalidation or managing backend infrastructure. The integrated cache uses the [dedicated gateway](dedicated-gateway.md) within your Azure Cosmos DB account. When provisioning your dedicated gateway, you can choose the number of nodes and the node size based on the number of cores and memory needed for your workload. Each dedicated gateway node has a separate integrated cache from the others.
1818

1919
An integrated cache is automatically configured within the dedicated gateway. The integrated cache has two parts:
2020

2121
* An item cache for point reads
2222
* A query cache for queries
2323

24-
The integrated cache is a read-through, write-through cache with a Least Recently Used (LRU) eviction policy. The item cache and query cache share the same capacity within the integrated cache and the LRU eviction policy applies to both. In other words, data is evicted from the cache strictly based on when it was least recently used, regardless of whether it's a point read or query.
24+
The integrated cache is a read-through, write-through cache with a Least Recently Used (LRU) eviction policy. The item cache and query cache share the same capacity within the integrated cache and the LRU eviction policy applies to both. Data is evicted from the cache strictly based on when it was least recently used, regardless of whether it's a point read or query. The cached data within each node depends on the data that was recently [written or read](integrated-cache.md#item-cache) through that specific node. If an item or query is cached on one node, it isn't necessarily cached on the others.
2525

2626
> [!NOTE]
2727
> Do you have any feedback about the integrated cache? We want to hear it! Feel free to share feedback directly with the Azure Cosmos DB engineering team:
@@ -31,16 +31,16 @@ [email protected]
3131

3232
The main goal of the integrated cache is to reduce costs for read-heavy workloads. Low latency, while helpful, isn't the main benefit of the integrated cache because Azure Cosmos DB is already fast without caching.
3333

34-
Point reads and queries that hit the integrated cache will have an RU charge of 0. Cache hits will have a much lower per-operation cost than reads from the backend database.
34+
Point reads and queries that hit the integrated cache have an RU charge of 0. Cache hits have a much lower per-operation cost than reads from the backend database.
3535

36-
Workloads that fit the following characteristics should evaluate if the integrated cache will help lower costs:
36+
Workloads that fit the following characteristics should evaluate if the integrated cache helps lower costs:
3737

3838
- Read-heavy workloads
3939
- Many repeated point reads on large items
4040
- Many repeated high RU queries
4141
- Hot partition key for reads
4242

43-
The biggest factor in expected savings is the degree to which reads repeat themselves. If your workload consistently executes the same point reads or queries within a short period of time, it's a great candidate for the integrated cache. When using the integrated cache for repeated reads, you only use RUs for the first read. Subsequent reads routed through the same dedicated gateway node (within the `MaxIntegratedCacheStaleness` window and if the data hasn't been evicted) won't use throughput.
43+
The biggest factor in expected savings is the degree to which reads repeat themselves. If your workload consistently executes the same point reads or queries within a short period of time, it's a great candidate for the integrated cache. When using the integrated cache for repeated reads, you only use RUs for the first read. Subsequent reads routed through the same dedicated gateway node (within the `MaxIntegratedCacheStaleness` window and if the data hasn't been evicted) don't use throughput.
4444

4545
Some workloads shouldn't consider the integrated cache, including:
4646

@@ -49,65 +49,71 @@ Some workloads shouldn't consider the integrated cache, including:
4949

5050
## Item cache
5151

52-
You can use the item cache for point reads (in other words, key/value look ups based on the Item ID and partition key).
52+
Item cache is used for point reads (key/value look ups based on the Item ID and partition key).
5353

5454
### Populating the item cache
5555

56-
- New writes, updates, and deletes are automatically populated in the item cache
57-
- If your app tries to read a specific item that wasn’t previously in the cache (cache miss), the item would now be stored in the item cache
56+
- New writes, updates, and deletes are automatically populated in the item cache of the node that the request is routed through
57+
- Items from point read requests where the item isn’t already in the cache (cache miss) of the node the request is routed through are added to the item cache
58+
- Requests that are part of a [transactional batch](./nosql/transactional-batch.md) or written in [bulk mode](./nosql/how-to-migrate-from-bulk-executor-library.md#enable-bulk-support) don't populate the item cache
5859

5960
### Item cache invalidation and eviction
6061

62+
Because each node has an independent cache, it's possible items are invalidated or evicted in the cache of one node and not the others. Items in the cache of a given node are invalidated and evicted based on the below criteria:
63+
6164
- Item update or delete
6265
- Least recently used (LRU)
6366
- Cache retention time (in other words, the `MaxIntegratedCacheStaleness`)
6467

6568
## Query cache
6669

67-
The query cache can be used to cache queries. The query cache transforms a query into a key/value lookup where the key is the query text and the value is query results. The integrated cache doesn't have a query engine, it only stores the key/value lookup for each query.
70+
The query cache is used to cache queries. The query cache transforms a query into a key/value lookup where the key is the query text and the value is the query results. The integrated cache doesn't have a query engine, it only stores the key/value lookup for each query. Query results are stored as a set, and the cache doesn't keep track of individual items. A given item can be stored in the query cache multiple times if it appears in the result set of multiple queries. Updates to the underlying items won't be reflected in query results unless the [max integrated cache staleness](#maxintegratedcachestaleness) for the query is reached and the query is served from the backend database.
6871

6972
### Populating the query cache
7073

71-
- If the cache doesn't have a result for that query (cache miss), the query is sent to the backend. After the query is run, the cache will store the results for that query
74+
- If the cache doesn't have a result for that query (cache miss) on the node it was routed through, the query is sent to the backend. After the query is run, the cache will store the results for that query
75+
- Queries with the same shape but different parameters or request options that affect the results (ex. max item count) will be stored as their own key/value pair
7276

7377
### Query cache eviction
7478

79+
Query cache eviction is based on the node the request was routed through. It's possible queries could be evicted or refreshed on one node and not the others.
80+
7581
- Least recently used (LRU)
7682
- Cache retention time (in other words, the `MaxIntegratedCacheStaleness`)
7783

7884
### Working with the query cache
7985

8086
You don't need special code when working with the query cache, even if your queries have multiple pages of results. The best practices and code for query pagination are the same whether your query hits the integrated cache or is executed on the backend query engine.
8187

82-
The query cache will automatically cache query continuation tokens where applicable. If you have a query with multiple pages of results, any pages that are stored in the integrated cache will have an RU charge of 0. If your subsequent pages of query results require backend execution, they'll have a continuation token from the previous page so they can avoid duplicating previous work.
88+
The query cache automatically caches query continuation tokens where applicable. If you have a query with multiple pages of results, any pages that are stored in the integrated cache have an RU charge of 0. If subsequent pages of query results require backend execution, they'll have a continuation token from the previous page so they can avoid duplicating previous work.
8389

84-
> [!NOTE]
90+
> [!IMPORTANT]
8591
> Integrated cache instances within different dedicated gateway nodes have independent caches from one another. If data is cached within one node, it is not necessarily cached in the others. Multiple pages of the same query are not guaranteed to be routed to the same dedicated gateway node.
8692
8793
## Integrated cache consistency
8894

89-
The integrated cache supports read requests with session and eventual [consistency](consistency-levels.md) only. If a read has consistent prefix, bounded staleness, or strong consistency, it will always bypass the integrated cache and be served from the backend.
95+
The integrated cache supports read requests with session and eventual [consistency](consistency-levels.md) only. If a read has consistent prefix, bounded staleness, or strong consistency, it bypasses the integrated cache and is served from the backend.
9096

9197
The easiest way to configure either session or eventual consistency for all reads is to [set it at the account-level](consistency-levels.md#configure-the-default-consistency-level). However, if you would only like some of your reads to have a specific consistency, you can also configure consistency at the [request-level](how-to-manage-consistency.md#override-the-default-consistency-level).
9298

9399
> [!NOTE]
94-
> Write requests with other consistencies will still populate the cache, but in order to read from the cache the request must have either session or eventual consistency.
100+
> Write requests with other consistencies still populate the cache, but in order to read from the cache the request must have either session or eventual consistency.
95101
96102
### Session consistency
97103

98-
[Session consistency](consistency-levels.md#session-consistency) is the most widely used consistency level for both single region as well as globally distributed Azure Cosmos DB accounts. When using session consistency, single client sessions can read their own writes. When using the integrated cache, clients outside of the session performing writes will see eventual consistency.
104+
[Session consistency](consistency-levels.md#session-consistency) is the most widely used consistency level for both single region and globally distributed Azure Cosmos DB accounts. With session consistency, single client sessions can read their own writes. Clients outside of the session performing writes will see eventual consistency when they are using the integrated cache.
99105

100106
## MaxIntegratedCacheStaleness
101107

102108
The `MaxIntegratedCacheStaleness` is the maximum acceptable staleness for cached point reads and queries, regardless of the selected consistency. The `MaxIntegratedCacheStaleness` is configurable at the request-level. For example, if you set a `MaxIntegratedCacheStaleness` of 2 hours, your request will only return cached data if the data is less than 2 hours old. To increase the likelihood of repeated reads utilizing the integrated cache, you should set the `MaxIntegratedCacheStaleness` as high as your business requirements allow.
103109

104-
It's important to understand that the `MaxIntegratedCacheStaleness`, when configured on a request that ends up populating the cache, doesn't impact how long that request will be cached. `MaxIntegratedCacheStaleness` enforces consistency when you try to use cached data. There's no global TTL or cache retention setting, so data will only be evicted from the cache if either the integrated cache is full or a new read is run with a lower `MaxIntegratedCacheStaleness` than the age of the current cached entry.
110+
It's important to understand that the `MaxIntegratedCacheStaleness`, when configured on a request that ends up populating the cache, doesn't affect how long that request is cached. `MaxIntegratedCacheStaleness` enforces consistency when you try to use cached data. There's no global TTL or cache retention setting, so data is only evicted from the cache if either the integrated cache is full or a new read is run with a lower `MaxIntegratedCacheStaleness` than the age of the current cached entry.
105111

106-
This is an improvement from how most caches work and allows the following additional customization:
112+
This is an improvement from how most caches work and allows for the following other customizations:
107113

108114
- You can set different staleness requirements for each point read or query
109115
- Different clients, even if they run the same point read or query, can configure different `MaxIntegratedCacheStaleness` values
110-
- If you wanted to modify read consistency for cached data, changing `MaxIntegratedCacheStaleness` will have an immediate effect on read consistency
116+
- If you wanted to modify read consistency for cached data, changing `MaxIntegratedCacheStaleness` has an immediate effect on read consistency
111117

112118
> [!NOTE]
113119
> The minimum `MaxIntegratedCacheStaleness` value is 0 and the maximum value is 10 years. When not explicitly configured, the `MaxIntegratedCacheStaleness` defaults to 5 minutes.
@@ -142,7 +148,7 @@ It's helpful to monitor some key metrics for the integrated cache. These metrics
142148
- `IntegratedCacheItemHitRate` – The proportion of point reads that used the integrated cache (out of all point reads routed through the dedicated gateway with session or eventual consistency). This value is an average of integrated cache instances across all dedicated gateway nodes.
143149
- `IntegratedCacheQueryHitRate` – The proportion of queries that used the integrated cache (out of all queries routed through the dedicated gateway with session or eventual consistency). This value is an average of integrated cache instances across all dedicated gateway nodes.
144150

145-
All existing metrics are available, by default, from the **Metrics** blade (not Metrics classic):
151+
All existing metrics are available, by default, from **Metrics** in the Azure portal (not Metrics classic):
146152

147153
:::image type="content" source="./media/integrated-cache/integrated-cache-metrics.png" alt-text="Screenshot of the Azure portal that shows the location of integrated cache metrics." border="false":::
148154

0 commit comments

Comments
 (0)