Noel Llevares
Noel Llevares

Reputation: 16037

What is the use-case for a DynamoDB LSI over GSI?

Is there still a reason for using Local Secondary Indexes over Global Secondary Indexes?

GSIs are better in all aspects AFAIK. * You can create GSIs after table creation. * You're not limited to using the hash key as part of the index unlike an LSI. * You can provision throughput for it separately.

When is an LSI better than a GSI?

Upvotes: 3

Views: 1307

Answers (1)

Tom
Tom

Reputation: 1730

LSIs allow you to have multiple sorting options for the same primary hash key.

For example, if you want to show a table of product orders for a user, you may want the username to be the hash key, and different attributes of the orders to be the sort keys. That way, you can show the orders to the user and allow them to server-side sort by product name, product type, purchase date, etc. It wouldn't really make sense to have separate provisioned throughput for each sort type since your access pattern is the same, so you also save some money by only paying for the primary key's provisioned throughput.

Upvotes: 2

Related Questions