How to create Global Secondary Index in DynamoDB
Watch my YouTube video for explanation :
Please look into the class notes here for your references:
Global Secondary Index
Employee Table
EMPID, JOINING_DATE, LOCATION
1 , 20-02-2009, Bangalore
2, 12-03-2009, Mysore
3, 31-01-2018, Delhi
4, 27-02-2014, Gurugram
5, 19-04-2008, Pune
6, 18-07-2004, Bangalore
Partition Key = EMPID
Sort Key = JOINING_DATE
other attribute = LOCATION
Query Find out all EMPIDs whose location is Bangalore?
Approach 1 SCAN operation Filter Expression (LOCATION=='Bangalore')
Approach 2 Create a GSI , and with index name - lookup the data where LOCATION =='Bangalore'
Meaning of Creating GSI -
a. Create a new GSI Index meaning define a new partition key
b. when we create a GSI then we create a new table with New Partition Key but keeping these 2 tables in sync
LOCATION , JOINING_DATE, EMPID
Bangalore, 20-02-2009, 1
Mysore, 12-03-2009, 2
Delhi, 31-01-2018, 3
Gurugram, 27-02-2014, 4
Pune, 19-04-2008, 5
Bangalore, 18-07-2004, 6
Partition Key = LOCATION
Sort Key = JOINING_DATE
other attribute = EMPID
How the GSI works internally-
GSI partition key requires uniform data distribution, meaning it works best when data is uniformed
Define RCU and WCU separately on the Index
Throttling
Overhead -
Cost will go higher as the no of GSI index increases , may go up to 20 GSIs
No guarantees of data consistency
Need to Keep WCU of GSI table>= WCU of Main Table
Separate metrices on your GSI for monitoring and action
Fore more Abinitio, AWS and data engineering videos please subscribe , view , like and share my YouTube channel
Click DataPundit
Comments
Post a Comment