Hierarchical Partition Key

From Ilianko
Revision as of 15:07, 26 October 2026 by Anko (talk | contribs) (Recreated DP-420 term page: Hierarchical Partition Key (Data Modeling & Partitioning))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

← Back to DP-420 Terminology Reference

Category: Data Modeling & Partitioning

Summary: Up to 3 levels of partition keys for granular, multi-tenant partitioning.

Overview

A hierarchical partition key (also called a subpartitioned or multi-level partition key) allows you to define up to three levels of partition keys (e.g., tenantId, then userId, then sessionId), enabling more granular, efficient partitioning for multi-tenant workloads without manually building a synthetic key. It supports more effective partition pruning for queries that filter on the leading key(s).

{
  "id": "DeviceTelemetryContainer",
  "partitionKey": {
    "paths": [
      "/tenantId",
      "/deviceId",
      "/id"
    ],
    "kind": "MultiHash",
    "version": 2
  }
}

-- No Full Fan-Out: Instead of executing a costly cross-partition
-- scan across every physical partition in the container, the engine
-- targets only the specific subset of physical partitions (or sub-partitions)
-- that house that exact tenantId and deviceId subtree.
SELECT * 
FROM c 
WHERE c.tenantId = "ContosoCorp" 
  AND c.deviceId = "Sensor-99" 
  AND c.temperature > 75

More Info & Links

DP-420 Style Practice Questions

Q1. What is the main benefit of a hierarchical partition key over a single-level partition key for multi-tenant scenarios?

  • A. More granular, efficient partitioning across up to three key levels without a manual synthetic key
  • B. Unlimited logical partition storage
  • C. Automatic multi-region writes
  • D. Elimination of the need for indexing

Q2. How many levels of keys can a hierarchical partition key support?

  • A. Up to three
  • B. Exactly one
  • C. Unlimited
  • D. Exactly five

Answer Key

Answers are listed at the very end so you can attempt the questions first.

  • Q1 (Hierarchical Partition Key): A. More granular, efficient partitioning across up to three key levels without a manual synthetic key — Hierarchical partition keys let you define up to 3 levels of keys, improving partitioning granularity for scenarios like multi-tenancy.
  • Q2 (Hierarchical Partition Key): A. Up to three — Azure Cosmos DB supports hierarchical partition keys with up to three levels.

DP-420: Designing and Implementing Cloud-Native Applications Using Microsoft Azure Cosmos DB — term detail page