Bird
0
0

Which approach gives the best performance and cost efficiency?

hard📝 Best Practice Q15 of 15
AWS - DynamoDB
You have a DynamoDB table with 1 million items. You need to retrieve all items where the attribute 'Status' equals 'Active'. The table's primary key is 'UserId'. Which approach gives the best performance and cost efficiency?
AUse Scan with FilterExpression 'Status = Active' to get all matching items
BCreate a Global Secondary Index (GSI) on 'Status' and use Query on the GSI
CUse Query on the primary key 'UserId' with FilterExpression 'Status = Active'
DUse Scan without any filter and filter results in your application code
Step-by-Step Solution
Solution:
  1. Step 1: Understand Scan with filter

    Scan reads all 1 million items, filtering after reading, which is slow and costly.
  2. Step 2: Use GSI for efficient querying

    Creating a GSI on 'Status' allows Query to directly find 'Active' items efficiently.
  3. Step 3: Evaluate other options

    Query on primary key can't filter by 'Status' efficiently; scanning without filter wastes resources.
  4. Final Answer:

    Create a Global Secondary Index (GSI) on 'Status' and use Query on the GSI -> Option B
  5. Quick Check:

    GSI + Query = best performance for non-key attribute [OK]
Quick Trick: Use GSI and Query for non-key attribute filtering [OK]
Common Mistakes:
  • Using Scan with filter on large tables
  • Querying primary key with filter instead of GSI
  • Filtering in application after full Scan

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes