Microsoft AZ-204: Azure Cosmos DB — Study Guide

Part of the Microsoft Azure Developer Associate AZ-204 — Study Guide. Practice with verified answers in the Microsoft exam hub, or take timed practice tests on ExamRoll.io.

Overview

Azure Cosmos DB is a fully managed, globally distributed, multi-model database designed for low-latency, elastically scalable applications. It exposes multiple APIs over a common, partitioned storage and replication engine, provides five tunable consistency levels, and offers comprehensive SLAs for availability, latency, throughput, and consistency. Data is organized into accounts, databases, and containers (or collections/tables/graphs depending on API). Containers are horizontally partitioned and scaled by a partition key, and all operations are metered in Request Units (RUs), a normalized currency that abstracts CPU, IOPS, and memory.

APIs and Programmability

Cosmos DB supports several wire-compatible APIs so you can use native SDKs and drivers without rewriting your data model:

Common SDK operations across APIs include CRUD, optimistic concurrency with ETags, upserts, server-side scripts (stored procedures, triggers), and UDFs (SQL API). Queries are parameterized to reduce RUs and improve security. Bulk operations and streaming APIs minimize client overhead and RU costs for high-throughput ingestion.

Consistency, Indexing, and Query Semantics

Cosmos DB offers five well-defined consistency levels per account (overridable per request in many SDKs):

Indexing is automatic and consistent by default for the SQL API. Every item and property is indexed without schema management, so writes update the index immediately (indexing mode Consistent). You can refine the indexing policy to:

Be mindful of item size and query shape. The SQL API enforces an item size limit (for example, 2 MB), and cross-partition queries, large projections, and complex predicates increase RU consumption. Use selective projections, appropriate filters, and partition-aware queries to minimize RU cost.

Partitioning and Throughput (RUs)

Cosmos DB separates logical and physical partitions:

Choose an effective partition key with high cardinality and even access distribution over time. Good keys correlate with your primary access path (for example, userId, deviceId, tenantId, or orderId). Avoid low-cardinality or time-bucketed keys that cause skew (for example, country, status, or day). When no single property is suitable:

Throughput models:

RU optimization techniques include point reads by id+partition key, parameterized queries, selective projections, denormalizing to reduce JOIN-like patterns, and using change feed for derived views rather than complex multi-container queries. Use ETags with If-Match for concurrency control to avoid RU-expensive retries. Monitor RU metrics and throttling (HTTP 429) and implement retry policies with jitter in SDKs.

Global Distribution and Change Feed

Cosmos DB’s turnkey, multi-region distribution lets you add or remove regions at any time. All regions are readable; enabling multi-region writes allows concurrent writes everywhere with sub-10-ms read latency at the 99th percentile in proximate regions. Client SDKs should be configured with preferred regions to route traffic locally and fail over gracefully. In .NET, supply preferred regions via CosmosClientOptions ApplicationPreferredRegions (or the equivalent in other SDKs). Multi-region writes require a conflict resolution policy:

The change feed provides an ordered, append-only log of changes per logical partition key. It is ideal for:

Practical Problem Scenario

Spotify needs to deliver a globally available personalization service that ingests user interactions in real time, updates per-user recommendations, and serves low-latency reads from the nearest region. Writes can occur from mobile clients worldwide, and recommendation updates must fan out to downstream systems.

  1. Choose Cosmos DB SQL (Core) API with multi-region writes
  1. Define a high-cardinality partition key and hierarchical keys
  1. Configure autoscale throughput on the primary containers
  1. Set consistency to Session at the account level
  1. Implement change feed processing with Azure Functions and the Change Feed Processor
  1. Create a derived recommendations container with a tailored indexing policy
  1. Enable global distribution with preferred regions in SDKs
  1. Configure conflict resolution and observability

This architecture delivers globally low-latency reads and writes, resilient event processing via the change feed, cost-efficient autoscaling, and robust consistency semantics suitable for personalization workloads.


Azure Storage and Blob Storage · All domains · Azure Container Solutions

Practice these questions → · Timed practice on ExamRoll.io →

Pass the whole exam — not just this question

You found this answer. Get every verified question and explanation in one place, and save hours of prep. Free to start.

Pass your exam →

Browse Microsoft →

Related guides

All-in-one access

One subscription. Every exam.

Every plan unlocks unlimited answer search, practice tests, AI explanations, and the full resource library — in 20+ languages.

Monthly
24.87
Just €0.83/day
Everything included:
  • Unlimited answer search
  • Unlimited practice tests
  • AI-powered explanations
  • Full resource library
  • 20+ languages
  • Weekly content updates
  • Rewards & referrals
  • Priority support
Start free trial

No credit card required*

Best value
12 months
179.87
Just €0.49/daySave 40%
Everything included:
  • Unlimited answer search
  • Unlimited practice tests
  • AI-powered explanations
  • Full resource library
  • 20+ languages
  • Weekly content updates
  • Rewards & referrals
  • Priority support
Start free trial

No credit card required*

✓ Free plan included · ✓ Cancel anytime · ✓ All plans unlock the full product