Instiq
Chapter 2 · Develop for Azure Storage·v2.0.0·Updated 6/3/2026·~9 min

What's changed: Deepened AZ-204 Chapter 2 to Associate depth (tables, scenarios, FAQ, traps; localized figures)

2.2Developing for Cosmos DB

Key points

Understand developing for Azure Cosmos DB: partition-key design, throughput (RU/s; provisioned/serverless), consistency levels (strong to eventual), and the change feed.

Azure Cosmos DB is a globally distributed, low-latency NoSQL database. Development centers on partition keys, RU/s, and consistency levels.

2.2.1Keys, throughput, consistency

Diagram showing Cosmos DB (globally distributed NoSQL) with a partition key (distributes data; pick well), RU/s (throughput; provisioned/serverless), and consistency levels (strong to eventual), noting good key choice, RU/s billing, and the consistency trade-off.
Cosmos DB essentials
  • Partition key: distributes data physically; design it to avoid skew and hot partitions.
  • RU/s (request units): the throughput unit; provisioned (fixed/autoscale) or serverless.
  • Consistency levels: five levels from strong to eventual; stronger is more accurate but higher latency/cost.
  • Change feed: read container changes in order for event-driven processing (e.g., with Functions).
Exam point

Common on AZ-204: distribution = partition key (skew → hot partition / RU exhaustion), throughput = RU/s (intermittent = serverless), consistency is a strong↔eventual trade-off, read changes in order = change feed.

Cosmos DB is globally distributed, low-latency NoSQL. The design core is the partition key—pick a high-cardinality value that spreads reads/writes evenly; skew causes hot partitions and 429s. Throughput is RU/s (request units): choose provisioned (manual/autoscale; predictable load) or serverless (intermittent, pay-per-use), with database shared RU across containers. Consistency levels span five—strong / bounded staleness / session (default) / consistent prefix / eventual—stronger being more accurate but higher latency/cost (session is a good balance for many apps). Multi-region writes lower latency globally, and APIs include NoSQL/MongoDB/Cassandra/Gremlin/Table. The change feed reads container changes in order for Functions integration. On 429 (TooManyRequests), retry with exponential backoff and revisit RU/key design. The axes: "distribution = partition key," "intermittent load = serverless," "consistency trades off with latency," "read changes = change feed."

Requirement/issueApproach
Distribute data evenlyHigh-cardinality partition key
Intermittent load, min costServerless
Good balance for many appsSession consistency (default)
Process changes in orderChange feed → Functions
Example

Scenario: a global e-commerce cart needing low latency without skew to specific users. Use userId as the partition key (high cardinality, well distributed). Use serverless for unpredictable staging and autoscale RU/s in production. Choose session consistency (read-your-writes). Propagate inventory changes via change feed → Functions. On 429, back off exponentially in the app and revisit RU/key if it persists.

Note

Q. Key to distribution? Partition key (high cardinality). Q. Intermittent load, min cost? Serverless. Q. Default consistency? Session. Q. Process changes in order? Change feed. Q. Handle 429? Backoff + revisit RU/key. Q. Global low-latency writes? Multi-region writes.

Warning

Watch the mix-ups: (1) The partition key is hard to change later—choose cardinality/distribution carefully up front. (2) Skew causes hot partitions/RU exhaustion (429)—pick an evenly distributing key. (3) Stronger consistency isn’t always better (latency/cost/availability trade-off). (4) Insufficient RU/s is the main 429 cause—use autoscale or revisit the key.

Tip

On RU exhaustion (429: TooManyRequests), retry with exponential backoff in the app, and revisit throughput or key design if needed.

2.2.2Section summary

  • Partition key (distribute) / RU/s (throughput) / consistency levels
  • Read changes in order = change feed; 429 = backoff

Sign in to track progress — Log in.

Quick check

(just a quick review)

Q1. Which design element distributes data physically and drives Cosmos DB performance?

Q2. What unit expresses Cosmos DB throughput?

Q3. Which Cosmos DB feature reads container changes in order for event-driven processing?

Check your understandingPractice questions for Chapter 2: Develop for Azure Storage