Microsoft Certified: Azure Developer Associate (AZ-204)Develop for Azure storageHard
A company stores customer profile data in Azure Table Storage. Each customer profile has a unique CustomerID and is associated with a Region. Queries frequently involve retrieving a specific customer's profile by CustomerID and also retrieving all customers within a specific Region. To optimize both query types, what is the most effective way to design the PartitionKey and RowKey for the table?
- APartitionKey = CustomerID, RowKey = Region
- BPartitionKey = CustomerID + Region (composite), RowKey = CustomerID
- CPartitionKey = Region, RowKey = CustomerID
- DPartitionKey = CustomerID, RowKey = '' (empty string)
Show answer & explanationAnswer & explanation
Correct answer: C. PartitionKey = Region, RowKey = CustomerID
PartitionKey = Region allows efficient retrieval of all customers within a region. RowKey = CustomerID, when combined with the PartitionKey, enables efficient point queries for a specific customer. Azure Table Storage queries on RowKey within a PartitionKey are very fast.
Why the other options are wrong
- A. PartitionKey = CustomerID would scatter customers from the same region across many partitions, making 'all customers in a region' queries inefficient.
- B. A composite PartitionKey like CustomerID + Region would make 'all customers in a region' queries inefficient as it wouldn't group by region.
- D. An empty RowKey means all entities for a CustomerID would be in the same PartitionKey, but it doesn't help with querying by Region. If CustomerID is PartitionKey, getting all by Region is still inefficient.
Azure Table Storage Keys
PartitionKey and RowKey form the unique primary key for entities in Azure Table Storage, determining data distribution and query performance.
- PartitionKey groups related entities.
- RowKey uniquely identifies an entity within a partition.
- Queries on PartitionKey and RowKey are most efficient.
- A good design balances write distribution and read performance.
Memory trick: Think of 'P'artition as the 'P'rimary grouping, and 'R'ow as the 'R'ecord within.