A developer is designing a real-time notification service for a collaborative task management application. The application stores notifications in an Amazon DynamoDB table with the following schema:
- Partition key: `RecipientUserID` (String)
- Sort key: `NotificationTimestamp` (String)
- Attributes: `IsRead` (Boolean), `Message` (String)
The service needs to retrieve only the unread notifications for a specific user, sorted from newest to oldest. The developer implements a `Query` operation on the base table using a `KeyConditionExpression` of and a `FilterExpression` of .
As the number of read notifications per user grows over time, the application experiences latency spikes and frequently receives `ProvisionedThroughputExceededException` errors, even though the volume of unread notifications remains low. Which approach is the most cost-effective and performant way to optimize this read operation?
- Modify the application to write a new attribute `UnreadTimestamp` only for unread notifications, removing it when marked as read. Create a Global Secondary Index (GSI) with `RecipientUserID` as the partition key and `UnreadTimestamp` as the sort key to query unread notifications directly.Answer
- BChange the operation to a `Scan` on the base table with a `FilterExpression` of and to bypass partition-key sorting constraints, and scale up the table's provisioned Read Capacity Units (RCUs).
- CKeep the current base table query configuration and increase the provisioned Read Capacity Units (RCUs) on the table to handle the capacity consumed by the `FilterExpression`, as the error indicates overall table throughput limits have been reached.
- DInitialize the AWS SDK client inside the application code by hardcoding high-privilege IAM credentials with a dedicated policy that bypasses read capacity throttling for the target DynamoDB table.