Azure

Cosmos DB Partition Key Design Guide: Synthetic Keys, Hierarchical Partition Keys & Hot Partition Mitigation

2026-05-24
NicheeLab Editorial Team

Partition Key design in Cosmos DB is the single most important design decision for performance, scalability, and cost. The Partition Key cannot be changed later (you have to recreate the Container), so the quality of the initial design shapes everything that follows in production. This article walks through the criteria for a good Partition Key, Synthetic Key patterns, Hierarchical Partition Keys, Hot Partition mitigations, and how to pick the right RU/s throughput mode.

Partition Key Basics

A Partition Key is the JSON property used to distribute documents inside a Cosmos DB Container across logical partitions.

  • Cosmos DB physically distributes data across multiple Physical Partitions (up to 20 GB / 10,000 RU/s each)
  • The hash of the Partition Key value determines which Physical Partition a document lands on
  • Documents that share the same Partition Key value are co-located on the same Physical Partition
  • The Partition Key cannot be changed after creation (you must recreate the Container)

The Four Criteria of a Good Partition Key

Ideally, the Partition Key satisfies all four of the following criteria.

  1. High cardinality: many distinct values — 1,000+ distinct values recommended
  2. Evenly distributed access patterns: avoid Hot Partitions; no concentration on a small set of values
  3. Frequently used as a query filter: included in the WHERE clause so most queries stay in-partition
  4. Evenly distributed writes: avoid throttling; write-heavy keys cause Hot Write Partitions

Anti-Patterns

Example choiceProblem
Constant value (e.g. "constant")All data lands on a single partition and slams into the 20 GB / 10,000 RU limits
Sequential IDs (e.g. orderId 1, 2, 3...)Writes concentrate on the most recent partition — Hot Write
Date (e.g. yyyymmdd)Writes concentrate on today's partition — Hot Write
Low-cardinality tenant IDs (e.g. only 5 tenants)Insufficient cardinality; a single large tenant creates a Hot Partition
A property never used in queriesEvery query becomes cross-partition, multiplying cost

Good Partition Key Examples

Use caseRecommended Partition KeyWhy it works
Multi-tenant SaaStenantIdMany tenant-scoped queries and well-distributed writes
IoT sensor datadeviceIdPer-device reads with distributed writes
User profilesuserIdPer-user access and high cardinality
E-commerce order historycustomerIdPer-customer history queries and distributed writes
Game player sessionsgameId + playerIdAccess patterns scoped by both game and player

Synthetic Partition Key

A Synthetic Partition Key concatenates multiple properties to artificially boost cardinality.

Example patterns

  • tenantId_yyyymm: tenant ID + year-month for monthly partitioning
  • userId_random0-99: user ID + random 0-99 for 100x fan-out
  • deviceId_yyyymmdd: device ID + date for daily partitioning
  • categoryId_year: category + year for historical fan-out

Implementation pattern

  • Build the synthetic key in the write-side application (e.g. doc.partitionKey = `${doc.tenantId}_${getCurrentMonth()}`)
  • Designate the new partitionKey property as the Container's Partition Key
  • Reconstruct the same synthetic key on the read path for filtering

Trade-offs

  • The write-side application must be modified
  • Certain range queries may become cross-partition
  • An effective Hot Partition mitigation when multi-tenant SaaS workloads mix large and small tenants

Hierarchical Partition Key (2023 GA)

Hierarchical Partition Keys, GA'd in 2023, let you declare up to 3 levels of Partition Key.

Example: TenantId / UserId / SessionId

  • Filter on TenantId only → query spans all users and sessions for that tenant (cross-partition but scoped)
  • Filter on TenantId + UserId → all of that user's sessions
  • TenantId + UserId + SessionId → fully in-partition query

What used to require a Synthetic Key for hierarchical fan-out can now be expressed declaratively and more efficiently. It is ideal for multi-tenant SaaS workloads with multi-level query patterns like "tenant-level aggregations, user-level operations, session-level details." For new projects that match this hierarchy, adopting a Hierarchical Partition Key is the modern best practice.

Mitigating Cross-Partition Queries

Cross-partition queries fan out across every Physical Partition, multiplying cost and significantly increasing latency.

Mitigations

  1. Design high-traffic user-facing queries to be in-partition (require the Partition Key as a filter)
  2. Tolerate cross-partition queries on low-traffic admin dashboards
  3. Offload cross-partition aggregation queries to Synapse Link to keep load off Cosmos DB itself
  4. Measure actual RU consumption via the x-ms-request-charge header to detect unintended cross-partition queries early
  5. Build derived datasets via Materialized Views or the Cosmos DB Change Feed when needed

The 20 GB / 10,000 RU Limits

Each Cosmos DB Physical Partition is capped at 20 GB of data and 10,000 RU/s of throughput.

  • If a logical partition hot-spots and hits 10,000 RU/s, you get throttling (HTTP 429)
  • As data approaches 20 GB, Cosmos DB automatically splits into a new Physical Partition (Split)
  • There is no downtime during a split, though query performance may dip temporarily

Hot Partition Mitigations

  1. Revisit the Partition Key design to spread load
  2. Use a Synthetic Key for artificial fan-out
  3. Provision more RU (up to the limit) if the workload is read-heavy
  4. Batch or queue writes at the application layer if writes are concentrated
  5. Continuously monitor partition utilization in Cosmos DB Insights and reconsider the design once usage exceeds 80%

Choosing the Right RU/s Mode

ModePricingBest forConstraints
Manual ProvisionedFixed monthly RU/sSteady workloadsMin 400 RU/s
Autoscale ProvisionedMax RU/s × 1.5Variable workloads (30%+)Auto-scales between 10-100%
ServerlessPay-per-useDev / low-traffic workloads~5,000 RU/s ceiling, 1 TB data

In production, Reserved Capacity (1-3 year terms) yields 20-65% discounts and should be a core part of cost optimization.

Operational Monitoring Tips

  1. Cosmos DB Insights: continuously monitor Throttled Requests, Storage Usage, and per-partition utilization
  2. x-ms-request-charge response header: send the actual RU consumption of each query to Application Insights
  3. Hot Partition alerts: notify Slack / Teams once any partition exceeds 80% utilization
  4. Cross-partition query detection: periodically analyze high-RU queries via Diagnostic Logs
  5. Capacity Planning: review data growth trends and the validity of the partition strategy on a monthly basis

Related Certifications

Frequently Asked Questions

What is a Partition Key?

A Partition Key is a JSON property that distributes documents inside a Cosmos DB Container (the equivalent of a table) across logical partitions. Cosmos DB stores data physically across multiple Physical Partitions (up to 20 GB / 10,000 RU/s each), and the hash of the Partition Key value determines which physical partition a document lands on. Choosing the Partition Key is the single most important design decision in Cosmos DB — it affects performance, scalability, and cost, and it cannot be changed after the fact (you have to recreate the Container). A good Partition Key: 1) has high cardinality (1,000+ distinct values recommended), 2) spreads access patterns evenly (avoiding Hot Partitions), 3) appears in frequently filtered queries (avoiding cross-partition queries), and 4) distributes writes (avoiding throttling).

What makes a good Partition Key?

Ideally a Partition Key satisfies all four conditions: 1) high cardinality (lots of distinct values, 1,000+ recommended); 2) even access patterns (no Hot Partition, no concentration on a few values); 3) frequently used as a query filter (so most queries are in-partition rather than cross-partition); and 4) evenly distributed writes (so you avoid throttling on a Hot Write Partition). For example, in a multi-tenant SaaS, using tenantId as the Partition Key can cause a Hot Partition when one large tenant generates 10x the traffic — in that case a synthetic key like tenantId + bucketId is needed. If you cannot find a single key that satisfies all four conditions, you must consider a Hierarchical Partition Key (up to 3 levels) or a Synthetic Key from the start.

What is a Synthetic Partition Key?

A Synthetic Partition Key combines multiple properties into a single key to artificially boost cardinality. Examples: tenantId_yyyymm (tenant ID + year-month for monthly buckets), userId_random0-99 (user ID + random 0-99 to spread by 100x), or deviceId_yyyymmdd (device ID + date for daily buckets). On the write path, you build the synthetic key in JavaScript by concatenating the source properties, store it as a new property, and designate it as the Partition Key. On the read path, queries must reconstruct the same synthetic key for filtering. Trade-offs: the write-side application has to be modified, and certain range queries may become cross-partition. It is a particularly effective way to avoid Hot Partitions in multi-tenant SaaS where large and small tenants are mixed together.

What is a Hierarchical Partition Key?

Hierarchical Partition Keys, GA'd in 2023, let you declare up to 3 partitioning levels. For example, with TenantId / UserId / SessionId you get three query modes: (1) filter on TenantId alone — cross-partition but scoped to one tenant; (2) filter on TenantId + UserId — all of one user's sessions; (3) filter on TenantId + UserId + SessionId — fully in-partition. What previously required a Synthetic Key can now be expressed declaratively and run more efficiently. It is ideal for multi-tenant SaaS workloads with multi-level query patterns like 'tenant-level aggregations, user-level operations, session-level details.' For new projects that match this hierarchy, adopting a Hierarchical Partition Key is the modern best practice.

Should you avoid cross-partition queries?

Avoid them where they matter most: cost and latency rise sharply, but eliminating every cross-partition query is unrealistic, so the rule is 'avoid them on the hot path.' Cross-partition queries fan out across every Physical Partition, multiplying cost and latency. In-partition queries (those that include the Partition Key in the WHERE clause) hit just one Physical Partition, with low cost and low latency. The standard pattern: design high-traffic user-facing queries as in-partition (require the Partition Key as a filter), tolerate cross-partition queries on low-traffic admin dashboards, and offload cross-partition aggregations to Synapse Link to keep the load off Cosmos DB. In production, monitor the x-ms-request-charge response header so you can detect unintended cross-partition queries early.

What is the 20 GB / 10,000 RU limit?

Each Cosmos DB Physical Partition is capped at 20 GB of data and 10,000 RU/s of throughput. The Partition Key value determines the logical partition, and multiple logical partitions map onto a single Physical Partition. If a logical partition becomes a hot spot and hits 10,000 RU/s, you get throttling (HTTP 429). As data approaches 20 GB, Cosmos DB automatically Splits into a new Physical Partition. To deal with Hot Partitions: 1) revisit the Partition Key design to spread load, 2) use a Synthetic Key to fan out artificially, 3) provision more RU (up to the limit) if the workload is read-heavy, or 4) batch/queue writes at the application layer if writes are concentrated. In production, watch partition utilization in Cosmos DB Insights and reconsider the design once any partition exceeds 80%.

How do you choose the RU/s billing mode?

Cosmos DB offers three throughput modes: 1) Manual Provisioned — fixed RU/s, the most predictable cost, ideal for steady workloads, starting at 400 RU/s; 2) Autoscale Provisioned — you set a max RU/s (e.g. 10,000), and Cosmos DB scales between 10% (1,000) and 100% (10,000); the monthly bill is capped at 1.5x the max RU, suited to variable workloads; 3) Serverless — pay only for what you consume, no throughput floor (effective ceiling around 5,000 RU/s and up to 1 TB of data), ideal for dev/test and low-traffic workloads. Rule of thumb: steady → Manual, ±30%+ variance → Autoscale, low-traffic/dev → Serverless. In production, Reserved Capacity (1-3 year terms) yields 20-65% discounts and should be a core part of your cost optimization plan.

Which certifications cover this material?

DP-420 (Cosmos DB Developer Specialty) is the headline exam for this area and tests Partition Key design in depth. AZ-204 (Developer Associate, retiring 2026-07) covers Cosmos DB SDK operations in Domain 2 (Storage, 15-20%). AZ-305 (Solutions Architect Expert) Domain 2 covers data storage selection (API choice and consistency levels). DP-700 (Fabric Data Engineer) covers real-time analytics integration via Synapse Link. AI-103 (GA 2026-06) covers patterns for using Cosmos DB as a generative AI / RAG backend. Cosmos DB is Azure's flagship NoSQL database, and Partition Key design is an essential skill for every engineer working in this space.

Related Articles & Deeper Dives

Azure AI エンジニア キャリアロードマップ|AI-901 → AI-103 → 生成 AI アーキテクトへの道【2026 年版】

Azure AI エンジニアになるための認定取得ロードマップ完全版。AI-901 (2026-06 GA、AI-900 後継) → AI-103 (2026-06 GA、AI-102 後継) の最新ルート、Azure AI Foundry / Agent Service / OpenAI 中心の生成 AI 時代の構成、Databricks GenAI / OpenAI Direct との二刀流戦略、年収レンジまで日本語で網羅。

DP-420 完全ガイド|Microsoft Cosmos DB Developer Specialty 出題範囲・学習リソース・合格戦略【2026 年版】

Microsoft Certified: Cosmos DB Developer Specialty (DP-420) の完全ガイド。5 ドメインの出題範囲、Cosmos DB for NoSQL の Partition Key 設計、Consistency Level、RU/s 最適化、Change Feed、Synapse Link 統合、3 ヶ月の合格ロードマップ、AZ-305 / AI-103 への展開ルートを日本語で網羅。

AI-103 完全ガイド|Developing AI Apps and Agents on Azure【2026 年 6 月 GA・AI-102 後継】

Microsoft Certified: Developing AI Apps and Agents on Azure (AI-103) の完全ガイド。AI-102 の後継として 2026 年 6 月 30 日 GA。Azure AI Foundry / Agent Service / OpenAI / AI Search を中心に、RAG パターン・Agent オーケストレーション・Responsible AI・Semantic Kernel SDK の実装スキル、3-4 ヶ月の合格ロードマップを日本語で網羅。

Azure データエンジニア キャリアロードマップ|DP-900 → DP-700 → AI-103 シニアデータエンジニアへの道【2026 年版】

Azure データエンジニアになるための認定取得ロードマップ完全版。DP-900 → DP-700 → DP-600 / DP-300 の Fabric 時代の王道ルート、Databricks 認定との二刀流、AI-103 統合戦略、DP-203 リタイア後の選択、12-18 ヶ月の学習プラン、年収レンジまで日本語で網羅。

The technical information in this article is based on the Azure Cosmos DB Partitioning Documentation. This article is not an official Microsoft Corporation product and there is no partnership or sponsorship relationship. Microsoft, Azure, and Azure Cosmos DB are trademarks of the Microsoft group of companies. Information is based on official public materials as of May 24, 2026. Always check the official pages for the latest details.

Check what you learned with practice questions

Practice with certification-focused question sets

Explore Azure exam prep
Author

NicheeLab Editorial Team

NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.


Related articles
Azure

AZ-900 Azure Fundamentals: Complete Exam Guide (2026)

Pass AZ-900 — cloud concepts, Azure architecture, management...

Azure

Azure Certification Roadmap: Which Cert to Take Next (2026)

Choose your Azure certification path — Fundamentals, Associa...

Azure

AI-901 Azure AI Fundamentals (Beta): Complete Guide (2026)

Pass AI-901 — Microsoft Foundry, generative AI, responsible ...

Azure

Microsoft Entra ID Fundamentals for Azure Certs (2026)

Entra ID basics every cert candidate needs — tenants, identi...

Azure

DP-900 Azure Data Fundamentals: Complete Guide (2026)

Pass DP-900 — relational, non-relational, analytics, Power B...

Browse all Azure articles (104)
© 2026 NicheeLab All rights reserved.