Authentication vs Authorization in AWS Amplify
Authentication vs Authorization in AWS Amplify
Why Permissions Feel Confusing in Amplify
Difference between GSI and LSI in DynamoDB

When you start learning DynamoDB, one thing becomes clear very quickly: how you design your keys decides how well your table works. But when people compare GSI and LSI, they often focus only on feature-level differences like consistency, throughput, or creation time. The real difference becomes much easier to understand when you look at **how DynamoDB maintains them **behind the scenes.
When creating tables in DynamoDB, the Primary Key needs to be defined. A primary key can have:
Partitions are logical groups where DynamoDB stores data. If a table or index has a sort key, the data inside that partition is stored in sorted order.
Note: A DynamoDB table must have a partition key, but the sort key is optional. If you don’t define a sort key, your table uses a simple primary key (PK only). If you do, it becomes a composite primary key (PK + SK).
DynamoDB is fast when you query using this key structure because it does not need to scan the whole table. It can go directly to the relevant partition and fetch the matching items.
What happens if you want to ***query or sort data, not using ***that primary key? This is where the SECONDARY INDEXES come in.
DynamoDB has two types of indexes:
These indexes help support additional query patterns while maintaining efficiency. At a high level, both GSI and LSI solve the same problem: they let DynamoDB support more query patterns without scanning the whole table. But they do not do it in the same way.
A GSI creates a separate indexed view of the same data using a different partition key and optionally a different sort key, but keeps two in sync. It queries span all primary(basic) partitions across the entire table.
An LSI is an index that uses the same partition key as the base table, but a different sort key. It does not create a completely new access path across the whole table. Instead, it gives another way to organize and query items within the same partition key. Queries are scoped to a single partition.
Base table: Orders
Primary key:
PK: userIdSK: orderId
Sample items:
userId=U1, orderId=O1001, createdAt=2026-03-01, status=SHIPPEDuserId=U1, orderId=O1002, createdAt=2026-03-03, status=PENDINGuserId=U2, orderId=O2001, createdAt=2026-03-02, status=SHIPPED
Scenario 01: Using the base table key
U1 (query by userId)userId + orderIdScenario 02: Using an LSI (same PK, different sorting)
userId (same as base table)createdAtNow DynamoDB can still look inside the same user’s partition, but sort the results by creation date instead of orderId.
Scenario 03: Use GSI (new access pattern across the table)
statuscreatedAt (If you want shipped orders sorted by date)This is a completely new access pattern across the whole table.
In all three scenarios, querying is based on the partitions(logical separations), so only that partition will be accessed to get relevant data. And the sort key is needed to get the other range for that queried data.
Therefore queriying using indexes will be more efficient than using only one partition key and sort key, which is defined for the primary table.
The real reason is that DynamoDB maintains them differently.
An LSI is closely linked to the base table. It uses the same partition key as the main table. Only the sort key is different. Because of this, LSI queries stay within the same partition key group. DynamoDB does not need to look across the whole table.
Since LSI is closely tied to the base table, it can support strongly consistent reads. But because of that close connection, you must create an LSI when you create the table.
A GSI maintains a separate indexed view of projected data from the base table. using a different partition and sort key. Because of that, a GSI creates a new way to query data. It is not limited to the base table’s main key.
But DynamoDB updates the base table first and then updates the GSI. That is why GSI reads are usually eventually consistent. GSI behaves differently because it works like a separate access path for the same data.
Secondary indexes exist because one primary key design cannot support every query pattern.
An LSI helps when you want another way to query data within the same partition key. A GSI helps when you need a new access pattern across the table.
So the core difference is not just consistency or throughput.
The core difference is this:
To really understand LSI and GSI, it helps to look at what is happening underneath and why they behave differently in practice.
Once you see why they work differently, the choice between LSI and GSI becomes much clearer.
A version of this article was first published on March 9, 2026 on Medium.
Why Permissions Feel Confusing in Amplify
AWS DynamoDB Eventual Consistency VS Strong Consistency Amazon DynamoDB reads data from tables, local secondary indexes (LSIs), global secondary indexes (GSIs), and streams. Both tables and LSIs …
What Is Amazon EC2? A Beginner’s Guide to Virtual Servers in AWS Amazon EC2 (Elastic Compute Cloud) is a service that provides virtual servers, called instances, in the cloud. You can choose the …