A DynamoDB table stores product reviews. Each item contains a Review ID (partition key), Product ID, User ID, Product Rating (1-5), and an optional comment. The most common query is: for a given Product ID, return the top 10 reviews with the highest ratings. Which index will give the fastest responses for this query?
Choose an answer
Tap an option to check your answer.
Correct answer: A global secondary index (GSI) with Product ID as the partition key and Product Rating as the sort key.
Why this is the answer
The correct answer is a global secondary index (GSI) with Product ID as the partition key and Product Rating as the sort key. This configuration directly supports the query's requirements: filtering by Product ID (partition key) and then ordering by Product Rating (sort key) to easily retrieve the top 10 highest-rated reviews. GSIs are suitable for queries that don't use the base table's partition key. Option B is incorrect because using Review ID as the sort key would not allow sorting by rating, which is crucial for finding the "top 10 reviews with the highest ratings." Option C is incorrect because Local Secondary Indexes (LSIs) must share the same partition key as the base table. While Product ID is a good partition key for the LSI in this scenario, LSIs are limited to the same partition key as the base table, and the base table's partition key is Review ID. Option D is incorrect because an LSI with Review ID as the partition key and Product ID as the sort key would not allow efficient querying by Product ID or sorting by Product Rating.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed