Azure Cosmos DB

What is Azure Cosmos DB?

Azure Cosmos DB is a globally distributed, multi-model database service from Microsoft Azure. It offers comprehensive SLAs on availability, latency, throughput, and consistency, providing robust support for various data models including document, key-value, graph, and column-family.

It's designed for mission-critical applications that require high availability, elastic scalability, and low-latency data access worldwide.

Key Features

Globally Distributed

Replicate your data across any number of Azure regions with active-active capabilities.

Elastic Scalability

Scale throughput and storage up or down on demand, independently per API.

Multi-Model Support

Support for multiple APIs including SQL (Core), MongoDB, Cassandra, Gremlin, and Table.

Guaranteed SLAs

Industry-leading Service Level Agreements for throughput, latency, availability, and consistency.

Enterprise Security

Robust security features including VNet integration, private endpoints, and role-based access control.

Low Latency

Single-digit millisecond latency for reads and writes at the 99th percentile.

Supported APIs

Cosmos DB offers a choice of APIs, allowing you to use the familiar query languages and SDKs:

Common Use Cases

Getting Started

Creating a Cosmos DB account is straightforward through the Azure portal, Azure CLI, or programmatically.

Example: Creating a SQL (Core) API Account (Azure CLI)

az cosmosdb create \ --name mycosmosdbaccount \ --resource-group myresourcegroup \ --kind GlobalDocumentDB \ --locations region=EastUS name=EastUS region=WestUS name=WestUS

Example: Inserting a Document (SQL API using JavaScript SDK)

// Initialize client

const { CosmosClient } = require("@azure/cosmos");

const endpoint = "YOUR_ENDPOINT";

const key = "YOUR_PRIMARY_KEY";

const client = new CosmosClient({ endpoint, key });


// Get container reference

const container = client.database("myDatabase").container("myContainer");


// Insert item

const newItem = { id: "item1", category: "personal", name: "groceries", description: "Monthly shopping" };

await container.items.create(newItem);

console.log("Item inserted successfully!");