Blueprint: CosmosDB and Global Replication

The global, scalable, cloud-native environment is designed with key characteristics. Those characteristics help establish a resilient, self-healing, and automated environment. This blueprint discusses 6 common areas of design;

  1. Overall plan

  2. Integration Scenario Workflow

  3. Core cloud components

  4. Base configuration

  5. Testing, monitoring, support

  6. Training and delivery

Each blueprint will present these 5 key areas of design and will ensure we have the ability to scale and automate the delivery of the blueprint in a short amount of time.

Overall Plan

The plan with Cosmos DB is simple. We will create a new module that deploys a basic Cosmos running the Document Store API. That document store will contain a database and a container running eventual consistency. The RU values are very important in this setup so we will set initial RU to 1000 and set auto-scaling. That means that Cosmos will run at a base value less than 1000 and will scale up if needed.

If someone is using Cosmos and encounter 429 error messages, we need to set the base RU values because a 429 is saying the capacity of the compute is exceeded. The steps of increase are as follows.

  1. base = 1000 RU

  2. 2nd level = 10000 RU

  3. 3rd level (performance/production) = 25000 RU

Core Cloud Components

  • Subscription

    • Instance

      • Container

        • Database

          • Collection

Base Configuration

  • 1000 RU

  • Auto Scale

  • Eventual Consistency

  • Document Store

  • SQL API

  • Serverless

Development and Staging Subscriptions

Development and staging use low scale clusters and configuration due to the lack of use and/or sampling process. There is no need to scale up the services on either of these environments. When the team is ready to scale up and test the load and performance, they will deploy to a performance environment, do their testing, take note of baselines, load and latency, and destroy the performance subscription.

Cosmos is a multi-region, multi-model database. That means that you can have an instance running in multiple places at the same time. The structure for SQL is as follows.

  1. Account

  2. Database

  3. Container

  4. Tables

  5. Data

There is also a document database type of Cosmos. That is structured like:

  1. Account

  2. Database

  3. Container

  4. Documents

We will default to the document store.

Development and Staging Defaults

resource "azurerm_resource_group" "rg" {
  name     = <set by user>
  location = var.resource_group_location
}

resource "random_integer" "ri" {
  min = 10000
  max = 99999
}

resource "azurerm_cosmosdb_account" "db" {
  name                      = "<name>-${random_integer.ri.result}"
  location                  = azurerm_resource_group.rg.location
  resource_group_name       = azurerm_resource_group.rg.name
  offer_type                = "Standard"
  kind                      = "GlobalDocumentDB"
  enable_automatic_failover = false
  autoscale_settings        = 1000
  }

capabilities {
    name = EnableServerless
  }

backup {
    type = Continuous
  }

identity {
    type = SystemAssigned
  }

  consistency_policy {
    consistency_level       = "Eventual"
  }
}

Performance and Production Defaults

resource "azurerm_resource_group" "rg" {
  name     = <set by user>
  location = var.resource_group_location
}

resource "random_integer" "ri" {
  min = 10000
  max = 99999
}

resource "azurerm_cosmosdb_account" "db" {
  name                      = "<name>-${random_integer.ri.result}"
  location                  = azurerm_resource_group.rg.location
  resource_group_name       = azurerm_resource_group.rg.name
  offer_type                = "Standard"
  kind                      = "GlobalDocumentDB"
  enable_automatic_failover = false
  autoscale_settings        = 1000
  }

capabilities {
    name = EnableServerless
  }

backup {
    type = Continuous
  }

identity {
    type = SystemAssigned
  }

  consistency_policy {
    consistency_level       = "Eventual"
  }
}

Tags

  • Owner: DevOps

  • Source: DevOps

  • PTSO: DevOps

  • Region: westus2

Testing - Monitoring - Support

Set

Training - Delivery

References

(Terraform Registry)[https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/cosmosdb_account]