0
0
DynamoDBquery~3 mins

Why Global Secondary Index (GSI) concept in DynamoDB? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could find any data instantly, no matter how you want to search it?

The Scenario

Imagine you have a huge phone book stored as a simple list. You want to find all friends living in a certain city, but the list is only sorted by last name. You have to scan every entry one by one to find them.

The Problem

Searching manually through the entire list is slow and tiring. It wastes time and can easily lead to mistakes, especially when the list grows very large. You might miss some friends or take forever to find them.

The Solution

A Global Secondary Index (GSI) acts like a special extra phone book sorted by city instead of last name. It lets you quickly find all friends in that city without scanning the whole list, making searches fast and easy.

Before vs After
Before
Scan entire table and filter by city
After
Query GSI on city attribute to get matching items
What It Enables

GSIs let you quickly find data using different keys, unlocking flexible and fast searches beyond the main table's sorting.

Real Life Example

A shopping app stores orders by order ID but wants to quickly find all orders by customer email. Using a GSI on the email lets the app instantly show a customer's order history.

Key Takeaways

Manual scanning is slow and error-prone for alternate queries.

GSIs provide fast lookup using different keys than the main table.

They enable flexible, efficient queries for better app performance.