1 · When Cosmos DB Fits

  • Global distribution — replicate data to 60+ Azure regions with a single click
  • Multi-model — document, key-value, graph, column-family, table
  • <10 ms latency — SLA-backed P99 reads <10 ms, writes <15 ms
  • Elastic scale — millions of RU/s, petabytes of storage
  • Schema-agnostic — automatic indexing of all properties by default

Choose Cosmos DB when your workload is globally distributed, high-throughput, and latency-sensitive with flexible schemas.

2 · Available APIs

API
Wire Protocol
Best For
NoSQL (Core)
REST / SDK
New cloud-native apps; richest feature set
MongoDB
MongoDB wire protocol
Lift-and-shift MongoDB workloads
Cassandra
CQL v4
Wide-column; existing Cassandra apps
Gremlin
Apache TinkerPop
Graph traversals (social, fraud)
Table
Azure Table Storage
Key-value; Table Storage migration
PostgreSQL
PostgreSQL wire
Distributed relational via Citus
🎯 Exam Tip: "NoSQL API" (formerly SQL API) is the default and supports the most Cosmos DB features (change feed, stored procedures, UDFs).

3 · Partition Keys & Data Modeling

Partition Key Best Practices

  • High cardinality — many distinct values (e.g., /userId, /tenantId)
  • Even distribution — avoid keys that funnel traffic to one partition (hot partition)
  • Query affinity — most queries include the partition key → single-partition reads

Anti-Patterns

  • ❌ Low-cardinality keys (/status with 3 values) → hot partitions
  • ❌ Timestamp as key → write-heavy on latest partition
  • ❌ Frequent cross-partition queries → high RU cost, fan-out

Hierarchical partition keys (preview): combine up to 3 levels (e.g., /tenantId + /userId) for finer distribution.

4 · Consistency Levels

LevelGuaranteeRU CostUse Case
StrongLinearizable reads2× writesFinancial ledgers
Bounded StalenessReads lag by ≤K versions or T time2× writesLeaderboards, inventory counts
SessionRead-your-own-writes within sessionUser profiles, carts (most apps)
Consistent PrefixNo out-of-order readsSocial feeds, status updates
EventualNo ordering guaranteeLikes, view counts, telemetry
🎯 Exam Tip: Strong consistency is NOT available with multi-region writes. Bounded Staleness is the strongest option for multi-write configurations.

5 · RU/s & Throughput Models

A Request Unit (RU) = cost of reading a 1-KB item by ID. Writes ≈ 5× reads; queries vary by complexity.

Model
Characteristics
Best For
Provisioned
Set RU/s manually; billed per hour
Predictable, steady workloads
Autoscale
Scales 10%–100% of max RU/s
Variable traffic with spiky peaks
Serverless
Pay per RU consumed; no minimum
Dev/test, low/intermittent traffic

RU Planning Tips

  • Use the Capacity Calculator or SDK's x-ms-request-charge header
  • Index fewer paths → lower write RU cost
  • Point reads (ID + partition key) = cheapest operation (1 RU for 1 KB)
  • Cross-partition queries cost proportionally to partitions touched

6 · Multi-Region Writes & Conflict Resolution

  • Single-region write — one write region, multiple read replicas; automatic failover
  • Multi-region write — all regions accept writes; lower write latency globally

Conflict Resolution Policies

  • Last Writer Wins (LWW) — default; uses _ts or custom path
  • Custom (stored procedure) — app-defined merge logic
  • Async — conflicts queued in a feed for manual resolution

Multi-region writes add ~25% cost (additional RU charge per replica write).

7 · Cost Optimization

  • TTL (Time to Live) — auto-expire items; no RU cost for deletion
  • Analytical Store — column-oriented store for OLAP; no impact on transactional RUs
  • Reserved Capacity — 1-yr or 3-yr reservations; up to 65% savings
  • Shared throughput — database-level RU/s shared across containers (400 RU minimum)
  • Composite indexes — reduce ORDER BY / multi-filter RU cost
  • Exclude unused paths from indexing policy

8 · When NOT Cosmos DB

  • ❌ Complex relational joins & multi-table transactions → Azure SQL
  • ❌ Full-text search as primary need → Azure AI Search
  • ❌ Budget-constrained, single-region, simple key-value → Table Storage / Redis
  • ❌ Large analytical queries over TBs → Synapse Analytics
  • ❌ Need stored procedures in T-SQL → SQL Database

9 · Real-World: Global E-Commerce Product Catalog

Scenario

An online retailer serves customers in North America, Europe, and Asia-Pacific. The product catalog has 5M items; reads hit 50K RPS at peak; writes are batch-imported nightly.

Design

  • API: NoSQL (Core) — flexible product schemas, change feed for search sync
  • Partition key: /categoryId (high cardinality, query-aligned)
  • Consistency: Session — shoppers see their own recently-viewed items
  • Throughput: Autoscale 10K–100K RU/s; spikes during flash sales
  • Regions: East US, West Europe, Southeast Asia (single-write, multi-read)
  • Cost levers: TTL on session/cart data (24 h); reserved capacity for baseline; analytical store feeds BI dashboards

Result

P99 read latency <8 ms globally; 55% cost reduction vs. provisioned-fixed after reserved capacity + autoscale.

10 · Knowledge Check

Q1: Which consistency level is the default for new Cosmos DB accounts?

Session consistency is the default — it guarantees read-your-own-writes per session with optimal RU cost.

Q2: A partition key with only 3 possible values causes which problem?

Low-cardinality keys concentrate traffic on few logical partitions, causing hot partitions and 429 throttling.

Q3: Which throughput model is best for a dev/test workload with sporadic usage?

Serverless charges only for consumed RUs with no minimum — ideal for intermittent/dev workloads.

Q4: With multi-region writes enabled, what is the strongest consistency level available?

Strong consistency is unavailable with multi-region writes. Bounded Staleness is the strongest supported level.

Q5: What is the RU cost of a point read (1 KB item by ID + partition key)?

A point read of a 1-KB document costs exactly 1 RU — the baseline unit of measurement.