DEA-C01 Question 265
Single answerYou are designing a data model for an e-commerce application using Amazon DynamoDB. The application needs to store information about customer orders. Each order has attributes such as OrderID, CustomerID, OrderDate, and OrderStatus. The application frequently queries all orders for a specific customer sorted by OrderDate. Which primary key design should you choose for optimal performance?
- A
Use OrderID as the partition key and OrderDate as the sort key.
- B
Use CustomerID as the partition key and OrderDate as the sort key.
- C
Use CustomerID as the partition key and OrderID as the sort key.
- D
Use OrderDate as the partition key and OrderID as the sort key.
Show answer and explanation
Correct answer: B
Explanation
In Amazon DynamoDB, designing the primary key involves selecting a partition key (and optionally a sort key) that aligns with the application's query patterns. Since the application frequently queries all orders for a specific customer sorted by OrderDate, using CustomerID as the partition key ensures all orders for each customer are grouped together. Using OrderDate as the sort key enables efficient sorting of orders by date within each customer group. This design optimally supports the application's query pattern.
- A. Incorrect.
Using OrderID as the partition key and OrderDate as the sort key will not optimize queries for retrieving all orders for a specific customer. OrderID does not group the data by customer.
- B. Correct.
Using CustomerID as the partition key and OrderDate as the sort key is the best choice because it groups all orders by customer and allows efficient sorting by OrderDate.
- C. Incorrect.
Using CustomerID as the partition key and OrderID as the sort key groups orders by customer but fails to optimize sorting by OrderDate, which is a frequent query requirement.
- D. Incorrect.
Using OrderDate as the partition key and OrderID as the sort key will not group data by customer, making it inefficient for customer-specific queries.