DVA-C02 · Question #451
A company has an ecommerce platform. A developer is designing an Amazon DynamoDB table to store customer order data for the platform. The table uses the order ID as the partition key. The developer ne
The correct answer is D. Create a global secondary index (GSI) with the customer email address as the partition key.. A DynamoDB Global Secondary Index (GSI) with customer email as the partition key enables querying all orders for a given email and supports future attribute-based queries.
Question
A company has an ecommerce platform. A developer is designing an Amazon DynamoDB table to store customer order data for the platform. The table uses the order ID as the partition key. The developer needs to modify the table to get all order IDs that are associated with a given customer email address in a single query. The solution must give the developer the ability to query order IDs by other item attributes in the future. Which solution will meet these requirements?
Options
- AConfigure the partition key to use the customer email address as the sort key.
- BUpdate the table to use the customer email address as the partition key.
- CCreate a local secondary index (LSI) with the customer email address as the sort key.
- DCreate a global secondary index (GSI) with the customer email address as the partition key.
How the community answered
(14 responses)- A21% (3)
- B14% (2)
- C7% (1)
- D57% (8)
Why each option
A DynamoDB Global Secondary Index (GSI) with customer email as the partition key enables querying all orders for a given email and supports future attribute-based queries.
A partition key cannot simultaneously be the order ID and the customer email; the sort key alone cannot be used as the leading condition in a Query without specifying the partition key.
Changing the partition key to customer email would break all existing queries that look up orders by order ID, which is the primary access pattern.
A Local Secondary Index (LSI) shares the same partition key as the base table (order ID), so it cannot enable queries that start from a customer email address.
A GSI with the customer email address as the partition key allows a Query operation to return all order IDs belonging to a specific customer. GSIs are flexible and additional GSIs can be created later to support queries by other item attributes, satisfying the extensibility requirement.
Concept tested: DynamoDB Global Secondary Index for alternate query access patterns
Source: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html
Community Discussion
No community discussion yet for this question.