0
0
DynamoDBquery~3 mins

Why Local Secondary Index (LSI) concept in DynamoDB? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could instantly find and sort data without flipping through every page?

The Scenario

Imagine you have a big notebook where you write down all your friends' names and their phone numbers. Now, you want to find all friends who live in the same city and sort them by their birthdays. Doing this by flipping through every page manually is tiring and slow.

The Problem

Manually searching through pages every time you want to find friends by city and birthday is slow and easy to make mistakes. You might miss some entries or spend too much time flipping pages, especially as your notebook grows.

The Solution

Local Secondary Index (LSI) lets you create a special, organized list inside your notebook that groups friends by city and sorts them by birthday. This way, you can quickly find and sort friends without flipping through every page.

Before vs After
Before
Scan entire table and filter by city, then sort results in code
After
Query table using LSI on city and birthday to get sorted results directly
What It Enables

LSI enables fast, efficient queries on different sort keys within the same partition, making data retrieval quick and organized.

Real Life Example

A music app stores songs by artist (partition key). Using LSI on song release date lets users quickly find all songs by an artist sorted by release date without scanning all songs.

Key Takeaways

Manual searching through all data is slow and error-prone.

LSI creates a sorted view on the same partition key with a different sort key.

This makes queries faster and more efficient for specific access patterns.