A developer is implementing a hotel reservation tracking system that stores reservation details in an Amazon DynamoDB table. The base table uses as the partition key and (formatted as YYYY-MM-DD) as the sort key. The application frequently needs to retrieve all reservations for a specific hotel location (stored in the attribute) within a given date range. Which strategy should the developer implement to meet these requirements with the lowest latency and the most efficient Read Capacity Unit (RCU) consumption?
- APerform a Scan operation on the base table using a filter expression on and a comparison on .
- Create a Global Secondary Index (GSI) with as the partition key and as the sort key, and perform a Query operation on the GSI.Answer
- CIncrease the provisioned Read Capacity Units (RCUs) on the base table to handle throttling, and continue retrieving the data using a Scan operation with a filter expression.
- DInitialize the Amazon DynamoDB SDK client with hardcoded AWS access keys inside the application code to minimize authentication latency when performing a Scan operation.
Answer
Create a Global Secondary Index (GSI) with HotelLocation as the partition key and CheckInDate as the sort key, and perform a Query operation on the GSI.
Creating a Global Secondary Index (GSI) with the hotel location as the partition key and check-in date as the sort key allows the application to perform highly efficient Query operations. The Query operation only reads the items that match the key condition expression, minimizing latency and RCU consumption.
Step-by-Step Solution
Key Concept
Optimizing data retrieval in DynamoDB using Global Secondary Indexes (GSIs) and Query operations instead of Scan operations.
Estimated Time:1m 30s