DynamoDB Secondary Indexes: Best Practices

Optimum Secondary Index Design Recommendations

Prev Question Next Question

Question

Your team is working on an application that is going to work with a DynamoDB table.

At the design stage, you are trying to find out the optimum way to define partition keys and secondary indexes.

Which of the following are recommendations for defining secondary indexes? Choose 2 answers from the options given below.

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - A and C.

The AWS Documentation mentions the following.

Keep the number of indexes to a minimum.

Don't create secondary indexes on attributes that you don't query often.

Indexes that are seldom used contribute to increased storage and I/O costs without improving application performance.

Avoid indexing tables that experience heavy write activity.

For example, in a data capture application, the cost of I/O operations required to maintain an index on a table with a very high write load can be significant.

If you need to index data in such a table, it may be more effective to copy the data to another table with the necessary indexes and queries there.

Since the documentation mentions this clearly, all other options are invalid.

For more information on working with indexes, please refer to the below URL-

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-indexes-general.html

When working with DynamoDB tables, it's important to carefully define partition keys and secondary indexes to optimize performance. Secondary indexes are used to enable more efficient querying of data in DynamoDB.

Regarding the recommendations for defining secondary indexes, option A and C are the correct answers:

A. Keep the number of indexes to a minimum: This is a best practice recommendation because the more indexes you have, the more storage and throughput capacity is consumed. Each index consumes storage and adds write capacity units (WCUs) and read capacity units (RCUs) to your DynamoDB table. So, it's recommended to create only the necessary indexes that are required to support the application's query patterns.

C. Avoid indexing tables that experience heavy write activity: This is also a best practice recommendation because secondary indexes incur additional write costs. Whenever a write operation is performed on a DynamoDB table, the same operation needs to be performed on all secondary indexes associated with the table. Therefore, adding too many secondary indexes to a table with high write activity can cause performance degradation and consume more resources than necessary.

Option B and D are incorrect:

B. Define as many indexes as possible to maximize performance: This is not a best practice recommendation because adding too many secondary indexes to a DynamoDB table can negatively impact performance and consume more resources than necessary. It's important to create only the necessary indexes that are required to support the application's query patterns.

D. Add indexes to tables that experience heavy write activity: This is not a best practice recommendation because adding too many secondary indexes to a table with high write activity can cause performance degradation and consume more resources than necessary. It's recommended to avoid indexing tables that experience heavy write activity unless it's absolutely necessary to support the application's query patterns.