Azure Cosmos DB – Core Concepts

Overview

Azure Cosmos DB is a fully managed, globally distributed, multi‑model database service designed for low latency and high availability. It provides turnkey global distribution, elastic scalability of throughput and storage, and comprehensive service level agreements (SLAs) for latency, throughput, consistency, and availability.

Global Distribution

Data can be replicated to any Azure region with a single click. Cosmos DB automatically handles multi‑master replication, conflict resolution, and read/write routing, ensuring 99.999% availability across the globe.

Multi‑Model Support

Cosmos DB natively supports multiple APIs and data models:

  • Core (SQL) API – JSON documents with SQL‑like query language.
  • Mongodb API – Wire‑compatible with MongoDB drivers.
  • Cassandra API – Compatible with Apache Cassandra.
  • Gremlin API – Graph data model.
  • Table API – Azure Table storage model.

Consistency Levels

Cosmos DB offers five well‑defined consistency models, allowing you to balance performance and data freshness:

LevelGuarantee
StrongLinearizability – reads see the most recent writes.
Bounded StalenessReads are guaranteed to be within a configured lag (operations or time).
SessionMonotonic reads and writes per client session.
Consistent PrefixReads never see out‑of‑order writes.
EventualLowest latency, no ordering guarantees.

Partitioning

To achieve horizontal scalability, Cosmos DB partitions data based on a partition key. Each partition is a replica set that can independently scale throughput. Choose a high‑cardinality key to avoid hot partitions.

// Example partition key definition in a .NET SDK
container.CreateItemAsync(item, new PartitionKey(item.Category));

Request Units (RU/s)

Throughput is provisioned in Request Units per second (RU/s). A single RU represents the cost of a simple read operation. Complex queries, writes, and indexed operations consume more RUs. Monitoring RU consumption helps control costs.

// Estimate RU for a query (Azure Portal > Metrics)
SELECT * FROM c WHERE c.status = 'active'

Security & Compliance

  • Encryption at rest and in transit.
  • Integrated with Azure Active Directory and RBAC.
  • Private endpoints via Azure Private Link.
  • Compliance certifications (ISO, SOC, HIPAA, GDPR, etc.).

Pricing Model

Cosmos DB pricing is based on provisioned throughput (RU/s) and storage consumption. You can also opt for serverless consumption‑based pricing for infrequent workloads.

Learn more about pricing

Best Practices

  1. Design a suitable partition key early.
  2. Use Session consistency for most applications.
  3. Leverage indexing policies to reduce RU consumption.
  4. Monitor metrics and set alerts on RU throttling.
  5. Enable multi‑region writes only when needed.