Bird
0
0

How can you design a DynamoDB table to efficiently support queries for recent orders by multiple customers without scanning the entire table?

hard🚀 Application Q9 of 15
DynamoDB - Access Patterns and Query Optimization
How can you design a DynamoDB table to efficiently support queries for recent orders by multiple customers without scanning the entire table?
ACreate a GSI with OrderDate as PartitionKey and CustomerId as SortKey
BUse a composite primary key with CustomerId as PartitionKey and OrderDate as SortKey
CUse OrderDate as PartitionKey only
DStore all orders in one partition
Step-by-Step Solution
Solution:
  1. Step 1: Understand query needs

    Query recent orders across customers means querying by OrderDate first.
  2. Step 2: Use GSI for alternate access

    Main table keys group by CustomerId; GSI with OrderDate as PartitionKey and CustomerId as SortKey supports recent orders query efficiently.
  3. Final Answer:

    Create a GSI with OrderDate as PartitionKey and CustomerId as SortKey -> Option A
  4. Quick Check:

    GSI supports alternate query patterns efficiently [OK]
Quick Trick: Use GSI to query by different keys [OK]
Common Mistakes:
MISTAKES
  • Using only main table keys for all queries
  • Scanning instead of indexing
  • Ignoring SortKey ordering in GSI

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes