DEV Community

Marcos Henrique for AWS Community Builders

Posted on

DynamoDB GSI vs LSI Unleashed! Explained like you're five!

Imagine having a big box filled with a wide variety of toys.

Cars, dolls, and balls are all examples of toys. Now imagine that you want to locate every red car in the box.

GSI

A global secondary index (GSI) functions similarly to a separate list or index that reveals the precise locations of all the red cars inside the box.
So, instead of having to go through the entire box when someone asks for the red vehicles, you can easily look at this list and find them.

LSI

In contrast, a local secondary index (LSI) is similar to having smaller boxes inside a bigger one, each of which is for a certain kind of toy.
There are boxes specifically designated for cars, dolls, and balls, for instance. You may discover the toys within each smaller box using a list or index that is specific to that box.
Therefore, if you want to locate every red car, you may head to the car box, check its index, and only locate red cars in that particular box.

TL;DR

In conclusion, a global secondary index aids in finding items throughout the whole box, whereas a local secondary index aids in finding items inside a specific area of the box.

Top comments (0)