Databases & System Design•Part 3: NoSQL & Document Databases (MongoDB, DynamoDB) (26 - 40)
DynamoDB GSI vs LSI:
In Simple Words:
- LSI: Shares table's Partition Key with a different Sort Key; max 10GB per partition; must be created at table creation.
- GSI: Can define completely new Partition and Sort keys; scales throughput independently; can be created anytime.
json
// Global Secondary Index (GSI) schema definition:
{
"IndexName": "StatusIndex",
"KeySchema": [
{ "AttributeName": "status", "KeyType": "HASH" },
{ "AttributeName": "created_at", "KeyType": "RANGE" }
],
"Projection": { "ProjectionType": "ALL" }
}