A developer is managing a logistics tracking application that stores package delivery status in an Amazon DynamoDB table. The table's partition key is and the sort key is . A background worker periodically retrieves all packages currently marked with a status of to generate a real-time dashboard. Currently, the worker performs a operation on the table and uses a to filter by status. As the table has grown to millions of items, the worker is consistently exceeding the table's provisioned read capacity, resulting in errors. Which two changes should the developer make to resolve the throttling issues and optimize the read performance?
- Create a Global Secondary Index (GSI) with a sparse partition key attribute that is only populated when the package status is In-Transit-Delayed.Cevap
- Update the background worker to use the Query API operation on the new GSI to retrieve the delayed packages.Cevap
- CUse a Scan operation with Segment and TotalSegments parameters to run parallel scans on the main table, applying the FilterExpression on each segment.
- DIncrease the provisioned Read Capacity Units (RCUs) on the base table to handle the scan throughput, and implement an exponential backoff algorithm in the application SDK client.
- EInitialize the AWS SDK DynamoDB client inside the background worker by hardcoding temporary credentials with maximum read privileges.
Cevap
Create a Global Secondary Index (GSI) with a sparse partition key attribute that is only populated when the package status is In-Transit-Delayed, and update the background worker to use the Query API operation on this GSI.
The correct solution involves creating a Global Secondary Index (GSI) with a sparse partition key. Because DynamoDB only populates a GSI when the index key attributes are present in the item, this index will only contain the small subset of packages that are delayed. By querying this GSI instead of scanning the entire base table, the developer restricts data retrieval to only the relevant items, which drastically reduces RCU usage and eliminates throttling.
Adım Adım Çözüm
Anahtar Kavram
Using Sparse Global Secondary Indexes (GSIs) and the Query API instead of Scan operations to optimize DynamoDB read performance and reduce RCU consumption.