Soru

Zorluk: KolayData Store Operations with Amazon DynamoDB

A developer is designing a mobile fitness application that stores daily step counts in an Amazon DynamoDB table. The table has UserId\text{UserId} as the partition key and ActivityDate\text{ActivityDate} as the sort key. The developer needs to retrieve all step counts for a specific user over the past month.

Which DynamoDB operation should the developer use to retrieve this data in the most efficient manner?

  1. A
    Use the Scan operation with a filter expression specifying the UserId\text{UserId}.
  2. B
    Use the Scan operation and filter the retrieved items on the client side.
  3. Use the Query operation with a key condition expression specifying the UserId\text{UserId}.Cevap
  4. D
    Use a parallel Scan operation with multiple segments to find the user's records.

Cevap

Use the Query operation with a key condition expression specifying the UserId.
The Query operation is the most efficient way to retrieve items because it targets only the partition associated with the specified partition key value. In this scenario, specifying the UserId in a key condition expression allows DynamoDB to read only the items for that user, minimizing Read Capacity Unit (RCU) consumption.

Adım Adım Çözüm

1
Identify the primary key structure of the DynamoDB table.
The table uses a composite primary key consisting of a partition key (UserId) and a sort key (ActivityDate).
Understanding the key structure is necessary to determine which API operations can perform targeted lookups.
2
Evaluate the query requirement against the key structure.
The application needs to retrieve all records associated with a specific partition key value (UserId) over a range of sort key values (ActivityDate).
This access pattern matches the design of the Query API, which allows fetching all items belonging to a single partition.
3
Compare the efficiency of Query vs Scan operations.
The Query operation accesses only the partition holding the specific UserId, whereas Scan reads the entire table. Therefore, Query is chosen to minimize Read Capacity Unit (RCU) consumption.
Using Query instead of Scan is the standard best practice for retrieving sorted items under a known partition key.

Anahtar Kavram

Using the Query operation instead of the Scan operation to retrieve items with a known partition key in Amazon DynamoDB.
Bu soruyu puanla