Documentation menu

resources

Cosmos DB

Overview

This example defines an Cosmos DB implementation for DocumentDB

{
	"cosmos_db": {
		"name": "cosmos-pepega-{env}",
		"default_consistency_level": "Session",
		"geo_redundant_locations": [
			{ "name": "northeurope", "priority": 0, "redundant": false }
		],
		"mode": "Provisioned",
		"databases": [
			{
				"name": "workge",
				"containers": [
					{
						"name": "ci-bzgdesign",
						"partition_key": "/partner_Id",
						"unique_keys": ["/skills", "/account"],
						"autoscale_throughput": { "max": 1000 },
						"indexing_policy": {
							"automatic": true,
							"included_paths": ["/*"],
							"excluded_paths": [
								"/partner_Id",
								"/skills",
								"/account"
							],
							"mode": "Consistent"
						}
					}
				]
			}
		],

		"system_managed_failover": true,
		"location": "northeurope",
		"external": false,
		"resource_group_name": "my-rg-name",
		"tags": { "example": "S0" }
	}
}

Cosmos DB Reference

Key Value Description
name (required) string The name of the Cosmos DB Account(see how to name)
default_consistency_level (required) Consistency Level The consistency level and configuration settings of the Cosmos DB Account
geo_redudant_locations (required) Geo Redundant Locations Locations for geo redundancy
mode (required) Mode Performance tier of the Cosmos DB Account
databases (required) Databases[] The databases definition for the Cosmos DB Account
system_managed_failover bool Enable system managed failover for regions, (defaults to true)
location string Resource Location (defaults to the resource group location)
external bool A reference to an existing Cosmos DB Account (defaults to false)
resource_group_name string The name of the resource group where the resource is located, only with external resources (defaults to the resource group of the deployment)
tags object Additional tags for the resource (defaults to no additional tags)

DefaultConsistencyLevel

Value Description
BoundedStaleness Bounded Staleness{}
ConsistentPrefix Similar to bounded staleness except, the operational or time lag guarantee
Eventual The first thing to consider in this model is that there is no guarantee on the order of the data and also no guarantee of how long the data can take to replicate
Session This level of consistency honors the client session. It ensures a strong consistency for an application session with the same session token
Strong The data is synchronously replicated to all the replicas in real-time

For a better understanding about the consistency levels, see this link


GeoRedundantLocations

This example defines only one location for redundancy

{
	"cosmos_db": {
		"geo_redundant_locations": [
			{ "name": "northeurope", "priority": 0, "redundant": true }
		]
	}
}

This example defines two locations for redundancy

{
	"cosmos_db": {
		"geo_redundant_locations": [
			{ "name": "northeurope", "priority": 0, "redundant": true },
			{ "name": "westeurope", "priority": 1, "redundant": false }
		]
	}
}
Value Value Description
name string The location of the region that you want to use
priority int The failover priority for the region. A failover priority of 0 indicates a write region (See detailed information about the priority here)
redundant bool Indicate whether or not this region is an Availability Zone region

Mode

Value Description
Provisioned It defines request unit per second (RUs) throughput. Every second, the configured RUs are available for database activity
Serverless It does not use any provisioned capacity. It charges based on RUs consumed

Databases

Value Value Description
name string The name of the database
containers Array of Containers[] Where the data is stored

Containers

Value Value Description
name string The name of the container
partition_key string Selecting your partition key is a simple but important design choice in Azure Cosmos DB Account. Once you select your partition key, it isn’t possible to change it in-place
unique_keys array With unique keys, you make sure that one or more values within a logical partition is unique. You also can guarantee uniqueness per partition key
autoscale_throughput object Maximum autoscale throughput for the container (only for Provisioned accounts)
indexing_policy Object of Indexing Policy Every container has an indexing policy that dictates how the container’s items should be indexed
mode Container Mode Defaults to Consistent

IndexingPolicy

Every container has an indexing policy that dictates how the container’s items should be indexed. The default indexing policy for newly created containers indexes every property of every item and enforces range indexes for any string or number. (See detailed information about indexing policies here)

Value Value Description
automatic bool Whether the indexing policy is automatic or not
included_paths object The paths included in the indexing process
excluded_paths object The paths excluded in the indexing process

ContainerMode

Value Description
Consistent The index is updated synchronously as you create, update or delete items
None The index is updated synchronously as you create, update or delete items

BoundedStaleness

Value Description
SingleRegionBoundedStaleness For a single-region account, Bounded Staleness provides the same write consistency guarantees as Session and Eventual Consistency. With Bounded Staleness, data is replicated to a local majority (three replicas in a four replica set) in the single region
MultiRegionBoundedStaleness For multi-region write accounts with two or more regions, application servers should direct reads and writes to the same region in which the application servers are hosted

SingleRegionBoundedStaleness

For a single-region account, Bounded Staleness provides the same write consistency guarantees as Session and Eventual Consistency. With Bounded Staleness, data is replicated to a local majority (three replicas in a four replica set) in the single region

Value Value Description
max_interval string Max lag time (minutes). Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400
max_prefix string Max stale requests. Valid ranges, Single Region: 10 to 2147483647. Multi Region: 100000 to 2147483647

This example defines only one region for the Bounded Staleness

{
	"cosmos_db": {
		"default_consistency_level": {
			"SingleRegionBoundedStaleness": {
				"max_interval": 5,
				"max_prefix": 10
			}
		},
		"geo_redundant_locations": [
			{ "name": "northeurope", "priority": 0, "redundant": true }
		]
	}
}

MultiRegionBoundedStaleness

For multi-region write accounts with two or more regions, application servers should direct reads and writes to the same region in which the application servers are hosted

Value Value Description
max_interval string Max lag time (minutes). Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400
max_prefix string Max stale requests. Valid ranges, Single Region: 10 to 2147483647. Multi Region: 100000 to 2147483647

This example defines two regions for the Bounded Staleness

{
	"cosmos_db": {
		"default_consistency_level": {
			"MultiRegionBoundedStaleness": {
				"max_interval": 300,
				"max_prefix": 100000
			}
		},
		"geo_redundant_locations": [
			{ "name": "northeurope", "priority": 0, "redundant": true },
			{ "name": "westeurope", "priority": 1, "redundant": true }
		]
	}
}