0
votes

I have a DynamoDB table with a partition key (UUID) with a few attributes (like name, email, created date etc). Created date is one of the attribute in the item and its format is YYYY-MM-DD. But now there is a requirement change - I have to sort it based on created date and bring the entire data (that is, I cannot just bring the data on a particular partition, but the whole data from all the partitions in a sorted fashion. I know this might take time as DynamoDB to fetch data from all the partitions and sort it after. My question is:

  1. Is the querying possible with the current design? I can see that partition key is required in the query, this is why I am confused because I cannot give a partition key here.
  2. Is there a better way to redesign the table for such a use case?

Thanks in advance.

1

1 Answers

3
votes

As your table exists you couldn't change the structure now, and even if you wanted to you would be reliant on UUID as your partition key.

There is functionality however to create a global secondary index for your DynamoDB table.

By using a GSI you can rearrange your data representation to include the creation date as the partition key of your table instead.

The reason why partition keys are important is that data in DynamoDB data is distributed across multiple nodes, with each partition sharing the same node. By performing a query it is more efficient to only communicate with one partition, as there is no need to wait on the other partitions returning results.