DVA-C02 · Question #375
A developer is writing an application, which stores data in an Amazon DynamoDB table. The developer wants to query the DynamoDB table by using the partition key and a different sort key value. The dev
The correct answer is B. Add a local secondary index (LSI) during table creation. Query the LSI by using strongly. A Local Secondary Index (LSI) supports alternate sort keys on the same partition key and, unlike a GSI, supports strongly consistent reads required to guarantee the latest write operations are returned.
Question
A developer is writing an application, which stores data in an Amazon DynamoDB table. The developer wants to query the DynamoDB table by using the partition key and a different sort key value. The developer needs the latest data with all recent write operations. How should the developer write the DynamoDB query?
Options
- AAdd a local secondary index (LSI) during table creation. Query the LSI by using eventually
- BAdd a local secondary index (LSI) during table creation. Query the LSI by using strongly
- CAdd a global secondary index (GSI) during table creation. Query the GSI by using eventually
- DAdd a global secondary index (GSI) during table creation. Query the GSI by using strongly
How the community answered
(47 responses)- A11% (5)
- B81% (38)
- C4% (2)
- D4% (2)
Why each option
A Local Secondary Index (LSI) supports alternate sort keys on the same partition key and, unlike a GSI, supports strongly consistent reads required to guarantee the latest write operations are returned.
An LSI with eventually consistent reads may return stale data that does not reflect the latest write operations, failing the requirement for the newest data.
An LSI shares the base table's partition key but allows a different sort key, enabling queries with the desired alternate sort key. Because LSIs are stored within the same partition as the base table, they support strongly consistent reads, which ensures all recent write operations are visible and the developer retrieves the most up-to-date data.
A GSI uses a separate distributed storage model and does not support strongly consistent reads; queries against a GSI are always eventually consistent.
A GSI does not support strongly consistent reads, so querying it cannot guarantee that the latest write operations are reflected in the results.
Concept tested: LSI strongly consistent reads vs GSI eventual consistency
Source: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LSI.html
Community Discussion
No community discussion yet for this question.