Azure Cosmos DB

Introduction to Microsoft's Globally Distributed, Multi-Model Database

Azure Cosmos DB Logo

What is Azure Cosmos DB?

Azure Cosmos DB is Microsoft's globally distributed, multi-model database service. It enables you to build highly available, globally distributed applications with unparalleled service levels.

Cosmos DB is designed for applications that require low latency, high throughput, and global distribution. It's a NoSQL database that supports multiple data models, including document, key-value, graph, and column-family, making it a versatile choice for a wide range of modern applications.

Key Features and Benefits

Global Distribution

Easily scale your application's reach by distributing data across any number of Azure regions worldwide. Cosmos DB offers turnkey global distribution with no code changes.

Multi-Model Support

Use the data model that best suits your application: document (SQL API), key-value (Table API), graph (Gremlin API), or column-family (Cassandra API). It also supports MongoDB API.

Elastic Scalability

Scale throughput and storage elastically and independently. Cosmos DB provides predictable performance and handles fluctuating workloads with ease.

Guaranteed High Availability

Achieve virtually 100% availability with robust SLAs. Cosmos DB provides automatic failover and multi-region replication for maximum resilience.

Low Latency

Deliver lightning-fast response times for your users, with single-digit millisecond read and write latencies at the 99th percentile, anywhere in the world.

Multiple APIs

Interact with your data using familiar APIs like SQL (document), MongoDB, Cassandra, Gremlin (graph), and Table (key-value). This flexibility simplifies migration and development.

Core Concepts

Resources and URIs

Cosmos DB resources are organized hierarchically. The top-level resource is an account, which contains databases, and each database contains containers. A unique URI identifies each resource.

Request Units (RUs)

Request Units (RUs) are a normalized measure of the throughput provided by a database operation. Cosmos DB uses RUs to abstract the underlying resources (CPU, memory, IOPS, etc.). You provision RUs to meet your application's performance needs.

Containers

Containers are the fundamental unit of scalability and disposability. They can store a collection of items (documents, rows, etc.). You define a partition key for each container to distribute data and requests across logical partitions.

Partition Key

The partition key is a property within your items whose value is used to determine the logical partition where the item is stored. Choosing an effective partition key is crucial for performance and scalability.

Getting Started

To start using Azure Cosmos DB, you'll need an Azure subscription. You can then create a Cosmos DB account in the Azure portal and choose the API that best suits your needs. Here's a simple example of creating an item using the SQL API:


POST https://your-cosmosdb-account.documents.azure.com/dbs/your_database/colls/your_container/docs
Content-Type: application/json
Authorization: type="master", res=&sig=

{
  "id": "newItem1",
  "category": "Electronics",
  "name": "Smartwatch",
  "price": 199.99,
  "tags": ["wearable", "smart", "tech"]
}
            

Azure Cosmos DB offers a powerful and flexible solution for building modern, scalable, and highly available applications. Its global distribution, multi-model capabilities, and guaranteed SLAs make it a top choice for developers worldwide.