How do you properly name DynamoDB index names?

I sometimes see DynamoDB index names like GSI1, GSI2, etc. But I don’t really understand how that’s supposed to help identify them later.

Would it be better to use a more descriptive pattern like {table_name}_{pk}_gsi?

For example, a table named todo_users when having an gsi by email, would be named like todo_users_email_gsi. Is that a good pattern?

What is considered a good practice?


Related discussions:

Two schools of thought on this.

  1. If you have an attribute named `email` already in your base table, and you want to make a GSI where `email

Suffix the field name with “-index”

If you are using single table design then the GSI names being generic is very useful. If you are not using single table design it (sometimes) makes more sense to give them more specific names.

You give the indices general names, if you have a single table design. That is if you save different data models into the same table. Then you can reuse the indices for each data model differently. At which point it would make no sense in given the index a name of a concrete attribute.

Generic GSI names are good for reusability, if you can fit it within your schema (the library ElectroDB allows you to do this easily); the same way it’s sometimes/many times suggested to name your partition and sort keys, “PK” and “SK” respectively.

But there’s nothing that says you need to name GSIs and partition/sort keys as generically as possible. If it works for you to have your GSI named “users_by_email” or something to that effect, there’s nothing wrong with it.

It just means your queries might be a bit less optimal or your costs will be slightly less optimized. And if monetary difference between “very optimized” and “slightly less very optimized” isn’t significant, it probably doesn’t matter until you scale much more.

Can you give me the rest of the thoughts?

Thanks. This is helpful.

I use on demand tables. I don’t think there would be any cost difference whether I use single table or multi table. I hope I’m not missing anything here.

I use on demand tables. So don’t use single table design.

I use on demand tables. So don’t use single table design.

Are you referring to base table fields?

On demand tables don’t really have a tremendous amount to do with single-table designs. There are some cost considerations and even less performance considerations and corner cases where a single table might help.

But the big thing that you can get from a single table design is when you are able to get multiple data types or related data from executing a single QUERY operation. If your data is laid out right, like having a GSI on a `order_id` field, you might be able to get the data for the customer, the order item rows, shipping info and other data types that are all related to that order.

This is an extension of the concept of designing your DynamDB data schema to make sure that you are handling as many of the read use-cases with as get GETs and QUERYs as possible. A single table can let you read multiple data types that might be required for certain processes, from a single QUERY.

But not all applications and use-cases fit into this format, so having multiple tables isn’t a 100% fit for everything. But it is good to think about if you have do have use cases where you might want to get records for multiple data types at the same time.

Wat

Yeah, I use multi table design.

Not a dynamodb expert. But I’m guessing I need to design my table to use single table design to be efficient?

With regards to cost, Single table design would make sense for provisioned capacity. But not for on demand.

Multi table design usually means you’re thinking about tables in a relational database way which is an antipattern in dynamo db.

It everything exists in one table you can get all your data in one query. Instead of multiple queries.

For instance, if you have a customer records, order records table and product records you could use a single table design in dynamo that can return data to populate an invoice with customer records product records and order records all in one query.

If you have your product records in a product table, you order records in an order table and your customers in a customer table that’s going to be 3 queries.

In dynamodb you want to model your data for your access patterns, not to fit neatly into separate entities that may exist in your code

Watch this:

https://youtu.be/KYy8X8t4MB8?si=xuqkiqTwoCKAnY_B

Thanks for the explanation. This helps. And yes, you are right. I’m still thinking in relational database way.

I’ll watch the video.

If you name things badly enough AWS will apparently try to hire you, so tread carefully.

OP, Based on your responses to some of the commenters here, I want to recommend that you pickup

https://www.dynamodbbook.com

Or search “Alex DeBrie AWS reinvent” on YouTube and start watching

You are right. I need that. Thanks for the recommendations.