0

In DynamoDB I have a table like below example data

pk        sk                         name         price 
=======================================================
product   cat#phone#name#iPhone11    iPhone 11    500
product   cat#phone#name#Nokia1100   Nokia 1100   100
product   cat#phone#name#iPhone11    iPhone 11    500

In a case I have to search by name. So, first I have created a global index for name where in index pk = pk, sk=name . Then I made a search which working fine.

Now I have changed my decision and created a local index for name, where name is sk. It's also working fine. My question is if I use local index here, has there any benefit ? and when I should not use local index ? If global index not required here but I have used , has there any performance issues ?

Niloy Rony
  • 602
  • 1
  • 8
  • 23
  • 1
    It may be more beneficial to reference this thread. https://stackoverflow.com/questions/21381744/difference-between-local-and-global-indexes-in-dynamodb – Cody Tapp Feb 03 '21 at 10:17

1 Answers1

1

@niloy-rony,

This AWS doc very well explains LSI and GSI in detail.

Now to answer your questions
- LSI comes at no extra cost. You don't need to pay for GSI's RCUs, WCUs however need to pay for storage as depicted here in another AWS doc.
- One should not use LSI if you are very certain that single partition (ie - pk) of your main table (pk remains the same in LSI) can be over 10GB. This is also discussed in link shared above.
- There is no performance issue with LSI and GSI in terms of query latencies. However, reads in GSI are eventual consistent whereas LSI supports strong consistent reads.


Edit, putting excerpt from the AWS doc to understand strong and eventual consistent reads.

Strongly Consistent Reads - When you request a strongly consistent read, DynamoDB returns a response with the most up-to-date data, reflecting the updates from all prior write operations that were successful.

Eventually Consistent Reads - When you read data from a DynamoDB table, the response might not reflect the results of a recently completed write operation. The response might include some stale data. If you repeat your read request after a short time, the response should return the latest data.

Refer this AWS doc for tips to minimise propagation delay of data from main table to GSIs

  • 1
    Would you please explain more about "reads in GSI are eventual consistent whereas LSI supports strong consistent reads." ? – Niloy Rony Feb 03 '21 at 10:36
  • 1
    LSI acts like a new table for you, whereas GSI is an index over your main table and data might not be consistent between main table and GSI. Have updated answer for more details. – Anshul Saraswat Kaul Feb 03 '21 at 10:44