0
votes

Here is the sample JSON which we are planning to insert into DynamoDB table. As of now we are having organizationID as primary partition key and __id__ as sort key. Since we will query based on organizationID we kept it as primary partition key. Is it a good approach to keep __id__ as sort key.

{
  "__class__": "package",
  "__updated__": "2015-10-19T14:30:13Z",
  "__created__": "2015-10-19T12:32:28Z",
  "transactions": [
    {
      transaction1
    },
    {
      transaction2
    }
  ],
  "carrier": "USPS",
  "organizationID": "6406fa6fd32393908125d4d81ec358",
  "barcode": "9400110891302408",
  "queryString": [
    "xxxxxxx",
    "YYYY",
    "delivered",    
  ],
  "deliveredTo": null,
  "__id__": "3232d1a045476786fg22dfg32b82209155b32"
}
1
As per your data model, can you have multiple items for the same organizationID? I am just trying to understand the requirement of sort key in the above data model.notionquest
Yes we will be having multiple items for the same organizationIDAravind0307

1 Answers

1
votes

As per the best practice, you can have timestamp as sort key for the above data model. One advantage of having timestamp as sort key is that you can sort the data for the particular partition key and identity the latest updated item. This is the very common use case for having sort key.

It doesn't make much sense to keep both partition and sort key as randomly generated value because you can't use sort key efficiently (unless I miss something here).