How to create effective indexes in DynamoDB table? Do we need to use Global Or Local index?
What are the reasons to select one over the other?
How to create effective indexes in DynamoDB table? Do we need to use Global Or Local index?
What are the reasons to select one over the other?
The global and local secondary index features (GSI and LSI, respectively), give you a different data model, and which one you need depends on your query needs.
The "local" index (LSI) means that data is reorganized inside one partition key ("locally") under a different sort key. If such re-sorting is all that you need, using an LSI is more efficient in that DynamoDB can read both base-table and index at the same place. This allows you to read the entire item being searched and not just specific columns as in GSI.
Meanwhile, GSI allows you to choose a different column as the partition key of the index, basically allowing you to index any column and not just re-sort the existing partition. This is more powerful but it means that base-table and index data is stored in different nodes, so you can read from the index only specific columns which you decide in advance you want to include in the index. Reading from the GSI also can't be "strongly consistent" and must be "eventually consistent" - whereas with LSI you could read with strong consistency.