Aravind0307
Aravind0307

Reputation: 63

Is safe to set a randomly generated alpha numeric string as primary partition key and sort key in DynamoDB

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"
}

Upvotes: 0

Views: 153

Answers (1)

notionquest
notionquest

Reputation: 39186

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).

Upvotes: 1

Related Questions