Adding strongly consistent queries on a non-partition key attribute in DynamoDB

Performing strongly consistent queries on a non-partition key attribute in DynamoDB

Question

An application stores its data in a DynamoDB table.

The application team finds that they have a new access pattern where the application has to perform strongly consistent queries on an attribute that's not the partition key.

How can the team solve this problem?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer: A.

Option A is CORRECT because the requirement is to perform strongly consistent queries on a new partition key.

In this scenario, a new DynamoDB table must be created as GSI only supports eventual consistency.

Option B is incorrect because Global Secondary Indexes do not support strongly consistent reads (but only eventual consistency reads).

Option C is incorrect because Local Secondary Indexes use the same partition key as the base table.

Option D is incorrect because DynamoDB Accelerator is a caching solution for DynamoDB and is not suitable for use in this case.

As a caching solution, it only allows queries on the same partition key as the base table.

Reference:

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SecondaryIndexes.html

In DynamoDB, strongly consistent reads can only be performed on items that belong to the same partition. A partition key is a primary key used to partition data across multiple nodes in the DynamoDB cluster.

In this scenario, the application team wants to perform strongly consistent queries on an attribute that's not the partition key. To solve this problem, the team has the following options:

A. Create a new DynamoDB table: Creating a new table can be a viable solution if the access pattern is significantly different from the existing table's access patterns. However, creating a new table means that data has to be migrated from the existing table, which can be a costly and time-consuming process.

B. Create a new GSI: Global Secondary Indexes (GSIs) allow you to query on attributes that are not the partition key. GSIs can be created during table creation or added later. When you create a GSI, you define a partition key and sort key for the index, which allows you to query the index in the same way as the base table. By creating a GSI, the application team can perform strongly consistent queries on the new attribute without creating a new table.

C. Create a new LSI: A Local Secondary Index (LSI) is an index that has the same partition key as the base table but a different sort key. LSIs are useful when you want to query data using a different sort key than the table's primary key. However, LSIs can only be created during table creation and cannot be added later. Therefore, creating a new LSI is not a viable solution in this scenario.

D. Create a DynamoDB Accelerator (DAX) cluster: DynamoDB Accelerator (DAX) is an in-memory cache for DynamoDB that can significantly improve read performance. However, DAX does not provide support for strongly consistent reads on attributes that are not the partition key. Therefore, creating a DAX cluster is not a viable solution in this scenario.

Therefore, option B (Create a new GSI) is the best solution for the application team to perform strongly consistent queries on the new attribute without creating a new table or performing any data migration.