Secondary Index Best Practices

Understand the tips and tricks to get the most out of GSIs.

Unless you want strongly-consistent reads and writes, it makes no sense to use LSIs. There are good reasons for avoiding LSI. The primary reason being the limit on the size of the item collection. You can’t have more than 10GB of data with the partition key. LSI also increases your partition size, which is not desirable.

Also, while using GSIs, we should be mindful of the projected attributes. If we project all the attributes, we waste write capacity. If we query for a non-projected attribute from GSI, we will consume extra read capacity. Hence, the rule of thumb is to project all the attributes that we query frequently.

Sparse index

Only the items whose index keys are present are projected to the GSI. This means we do not consume write capacity on the items without an index key. A secondary index to which a few items are projected is called a sparse index. You should use sparse indexes as much as possible. The following figures show a sparse index.

Get hands-on with 1000+ tech skills courses.