Bitzu

AZ-305 ยท Semi-structured and unstructured data design

Cosmos DB partition keys and consistency levels

Choosing a partition key (high cardinality, even distribution, hot partitions), the five consistency levels and their latency/availability trade-offs.

Key points

  • Logical partition: same key value, up to 20 GB, at most 10,000 RU/s.
  • Good key: high cardinality, even RUs and storage, never changes, in query filters.
  • Low cardinality: hot partitions. Key change means a new container.
  • Consistency, strongest first: Strong, Bounded staleness, Session (most used), Consistent prefix, Eventual.
  • Stronger: more latency and read RUs; Strong not allowed with multiple write regions.

Source: https://learn.microsoft.com/en-us/azure/cosmos-db/partitioning-overview

Practice questions

Single choice

What is the maximum amount of data a single logical partition can hold in Azure Cosmos DB?

  1. 10 GB
  2. 20 GB
  3. 50 GB
  4. There is no limit
Show answer

Answer: B. 20 GB

Each logical partition can store up to 20 GB. The 50 GB figure is the storage limit of a physical partition, which can host many logical partitions.

Select all that apply

Which characteristics describe a good partition key for a large Azure Cosmos DB container?

  1. High cardinality: a wide range of distinct values
  2. Spreads RU consumption and storage evenly
  3. Its value never changes for an item
  4. Few distinct values so related data stays together
  5. A large numeric value rather than a string
Show answer

Answer: A. High cardinality: a wide range of distinct values, B. Spreads RU consumption and storage evenly, C. Its value never changes for an item

A good key has many distinct values, spreads request units and storage evenly, and holds a value that never changes for an item (partition key values are immutable). Low cardinality causes hot partitions, and keys should be strings rather than numbers that may exceed double precision.

True or false

An Azure Cosmos DB account with multiple write regions can use strong consistency.

Show answer

Answer: False

False. Accounts with multiple write regions cannot use strong consistency, because a distributed system cannot offer both zero RPO and zero RTO, and strong consistency would not improve write latency anyway since every write must commit in all regions.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More AZ-305 topics in this module