Soru

Zorluk: OrtaData Store Operations with Amazon DynamoDB

A developer is designing a backend service for a smart fitness application. The application tracks user workout histories in an Amazon DynamoDB table. The table uses `UserID` as the partition key and `WorkoutTimestamp` as the sort key. The developer needs to implement two features:

1. Retrieve only the single most recent workout session for a given user.
2. Log a new workout session and update the user's weekly streak counter simultaneously, ensuring that both operations must either succeed together or fail together.

Which combination of DynamoDB operations and configurations should the developer implement to meet these requirements? (Select TWO.)

  1. Perform a `Query` operation on the table with `ScanIndexForward` set to `false` and `Limit` set to 11.Cevap
  2. Perform a `TransactWriteItems` operation containing a `Put` action for the workout and an `Update` action for the streak counter.Cevap
  3. C
    Perform a `Scan` operation with a `FilterExpression` matching the `UserID` to retrieve the workouts, then identify the most recent session in application memory.
  4. D
    Scale up the table's provisioned Write Capacity Units (WCUs) as the primary method to resolve write throttling caused by multiple writes targeting a single hot `UserID` partition key.
  5. E
    Initialize the AWS SDK DynamoDB client inside the application code by hardcoding temporary IAM user credentials to speed up client authentication.

Cevap

To meet the requirements, the developer must perform a Query operation with ScanIndexForward set to false and Limit set to 1 to retrieve the latest workout, and use TransactWriteItems to write the workout and update the streak counter atomically.
The correct options are performing a Query with ScanIndexForward set to false and Limit set to 1, and using TransactWriteItems. Querying with ScanIndexForward set to false scans the sort key in descending order, so a Limit of 1 retrieves only the latest workout. TransactWriteItems ensures that both the workout creation and the streak update succeed or fail together, maintaining data integrity.

Adım Adım Çözüm

1
Query the table for the user's workouts with descending sort order.
By specifying the UserID partition key and setting ScanIndexForward to false, DynamoDB traverses the WorkoutTimestamp sort key in descending order.
This puts the most recent workout at the beginning of the result set.
2
Apply a Limit parameter of 1 to the Query operation.
Only the single most recent workout item is retrieved from the table.
This minimizes the consumed Read Capacity Units (RCUs) by avoiding reading historical workouts.
3
Group the new workout creation and streak update into a TransactWriteItems call.
Both the Put and Update operations are executed in an all-or-nothing transaction.
This guarantees that the user's weekly streak counter is never out of sync with their logged workouts.

Anahtar Kavram

Using DynamoDB Query with sorting and limit features for retrieval, and TransactWriteItems for atomic updates across multiple items.
Tahmini Süre:2m 0s
Bu soruyu puanla