If your app needs to get product reviews by product ID and filter by rating, which access pattern fits best?
medium📝 query result Q5 of 15
DynamoDB - Access Patterns and Query Optimization
If your app needs to get product reviews by product ID and filter by rating, which access pattern fits best?
ANo keys, use Scan with filter
BPartition key on ProductID, sort key on Rating
CPartition key on ReviewID only
DPartition key on Rating, sort key on ProductID
Step-by-Step Solution
Solution:
Step 1: Identify query needs
App queries by product ID and filters by rating, so ProductID should be partition key and Rating as sort key.
Step 2: Evaluate options
Partition key on ProductID, sort key on Rating matches query pattern. Partition key on Rating, sort key on ProductID reverses keys, making queries inefficient. Partition key on ReviewID only lacks sort key for filtering. No keys, use Scan with filter is inefficient.
Final Answer:
Partition key on ProductID, sort key on Rating -> Option B
Quick Check:
Partition key = main query, sort key = filter [OK]
Quick Trick:Partition key for main query, sort key for filtering [OK]
Common Mistakes:
MISTAKES
Swapping partition and sort keys
Using only partition key without sort key
Relying on Scan instead of Query
Master "Access Patterns and Query Optimization" in DynamoDB
9 interactive learning modes - each teaches the same concept differently