Skip to content

Commit 5c132e6

Browse files
KrylixZAmsfussell
andauthored
Adding write performance optimization section to Cosmos DB state stor… (#3934)
* Adding write performance optimization section to Cosmos DB state store documentation Signed-off-by: Simon Headley <[email protected]> * Applying suggestions as per PR review Signed-off-by: Simon Headley <[email protected]> * Switching from Markdown note to {{% alert %}} {$ /alert $}} as per PR review Signed-off-by: Simon Headley <[email protected]> * Putting example paragraph in a new line as per review Signed-off-by: Simon Headley <[email protected]> --------- Signed-off-by: Simon Headley <[email protected]> Co-authored-by: Mark Fussell <[email protected]>
1 parent 174c510 commit 5c132e6

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

daprdocs/content/en/reference/components-reference/supported-state-stores/setup-azure-cosmosdb.md

+36
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,42 @@ az cosmosdb sql role assignment create \
172172
--role-definition-id "$ROLE_ID"
173173
```
174174

175+
## Optimizing Cosmos DB for bulk operation write performance
176+
177+
If you are building a system that only ever reads data from Cosmos DB via key (`id`), which is the default Dapr behavior when using the state management API or actors, there are ways you can optimize Cosmos DB for improved write speeds. This is done by excluding all paths from indexing. By default, Cosmos DB indexes all fields inside of a document. On systems that are write-heavy and run little-to-no queries on values within a document, this indexing policy slows down the time it takes to write or update a document in Cosmos DB. This is exacerbated in high-volume systems.
178+
179+
For example, the default Terraform definition for a Cosmos SQL container indexing reads as follows:
180+
181+
```tf
182+
indexing_policy {
183+
indexing_mode = "consistent"
184+
185+
included_path {
186+
path = "/*"
187+
}
188+
}
189+
```
190+
191+
It is possible to force Cosmos DB to only index the `id` and `partitionKey` fields by excluding all other fields from indexing. This can be done by updating the above to read as follows:
192+
193+
```tf
194+
indexing_policy {
195+
# This could also be set to "none" if you are using the container purely as a key-value store. This may be applicable if your container is only going to be used as a distributed cache.
196+
indexing_mode = "consistent"
197+
198+
# Note that included_path has been replaced with excluded_path
199+
excluded_path {
200+
path = "/*"
201+
}
202+
}
203+
```
204+
205+
{{% alert title="Note" color="primary" %}}
206+
207+
This optimization comes at the cost of queries against fields inside of documents within the state store. This would likely impact any stored procedures or SQL queries defined and executed. It is only recommended that this optimization be applied only if you are using the Dapr State Management API or Dapr Actors to interact with Cosmos DB.
208+
209+
{{% /alert %}}
210+
175211
## Related links
176212

177213
- [Basic schema for a Dapr component]({{< ref component-schema >}})

0 commit comments

Comments
 (0)