Soru

Zorluk: OrtaData Store Operations with Amazon DynamoDB

A developer is implementing a hotel reservation tracking system that stores reservation details in an Amazon DynamoDB table. The base table uses ReservationIDReservationID as the partition key and CheckInDateCheckInDate (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 HotelLocationHotelLocation 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?

  1. A
    Perform a Scan operation on the base table using a filter expression on HotelLocationHotelLocation and a comparison on CheckInDateCheckInDate.
  2. Create a Global Secondary Index (GSI) with HotelLocationHotelLocation as the partition key and CheckInDateCheckInDate as the sort key, and perform a Query operation on the GSI.Cevap
  3. C
    Increase 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.
  4. D
    Initialize the Amazon DynamoDB SDK client with hardcoded AWS access keys inside the application code to minimize authentication latency when performing a Scan operation.

Cevap

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.

Adım Adım Çözüm

1
Analyze the query requirements against the primary key structure of the base table.
The query needs to filter by HotelLocation, which is not the partition key (ReservationID) of the base table. A Query operation cannot be performed on the base table directly.
DynamoDB Query operations require an equality condition on the partition key.
2
Define an indexing strategy to support the query requirements.
Identify that a Global Secondary Index (GSI) with HotelLocation as the partition key and CheckInDate as the sort key is required.
GSIs allow querying data across the entire table using a partition key and sort key that differ from those of the base table.
3
Choose the optimal data retrieval operation.
Perform a Query operation on the GSI using the key condition expression for HotelLocation and a range condition for CheckInDate.
Query operations only read the items that match the key condition, resulting in predictable, low latency and highly efficient RCU consumption compared to full table scans.

Anahtar Kavram

Optimizing data retrieval in DynamoDB using Global Secondary Indexes (GSIs) and Query operations instead of Scan operations.
Tahmini Süre:1m 30s
Bu soruyu puanla