Contoso is designing a new Azure Cosmos DB for NoSQL container for a multitenant retrieval workload. Each item has id, tenantId, departmentId, region, and an embedding property with a diskANN vector index. The Azure Cosmos DB team has already configured the account so that vector search uses the hierarchical partitioning scheme.
Facts and requirements:
- Contoso serves thousands of tenants. The largest tenant stores about 90 GB.
- Within that tenant, the largest department stores about 35 GB.
- The
regionproperty has only three distinct values. - Vector queries that filter only on
tenantIdmust be routed to the physical partitions that hold that tenant's data, not fanned out across the container. - The design must respect the 20-GB logical partition limit.
- The key must support distributing writes across thousands of tenants.
Which partition key design should you use?
The 90-GB tenant exceeds the 20-GB logical partition limit, so a single tenant key cannot work. A hierarchical key extends the tenant model instead. Placing tenant first keeps tenant-only vector queries routed to that tenant's subset of physical partitions. Ending with the item identifier gives the lowest level the high cardinality it needs, so even a 35-GB department is split. Starting with region also prevents a tenant-only filter from targeting a partition key prefix.
- Correct: Hierarchical key: /tenantId, /departmentId, /id. Tenant at the first level lets tenant-only filters route to that tenant's subset of physical partitions. The item identifier at the lowest level gives the high cardinality the lowest level needs, which keeps logical partitions within the 20-GB limit.
- Not correct: Hierarchical key: /tenantId, /departmentId. Tenant-first routing works, but the tenant and department together identify one logical partition. The 35-GB department would exceed that partition's 20-GB limit.
- Not correct: Single key: /tenantId. Tenant-only queries would route well, but a 90-GB tenant exceeds the 20-GB logical partition limit. That is the case a hierarchical key is meant to address.
- Not correct: Hierarchical key: /region, /tenantId, /id. A filter on tenantId alone skips the first key level, so it cannot use prefix routing to limit the query to that tenant's physical partitions.