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.)
- Perform a `Query` operation on the table with `ScanIndexForward` set to `false` and `Limit` set to .Answer
- Perform a `TransactWriteItems` operation containing a `Put` action for the workout and an `Update` action for the streak counter.Answer
- CPerform a `Scan` operation with a `FilterExpression` matching the `UserID` to retrieve the workouts, then identify the most recent session in application memory.
- DScale 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.
- EInitialize the AWS SDK DynamoDB client inside the application code by hardcoding temporary IAM user credentials to speed up client authentication.
Answer
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.
Step-by-Step Solution
Key Concept
Using DynamoDB Query with sorting and limit features for retrieval, and TransactWriteItems for atomic updates across multiple items.
Estimated Time:2m 0s