Modeling a DynamoDB Table with pk and sk



Data:

My data mainly contains environment, product name, data type name and modification timestamp epoch.

{ env: beta, product: analytics, dataType: voice,  modifiedAt: 1676460738394 }

There is more than one data with the same data type name

{ env: beta, product: analytics, dataType: voice,  modifiedAt: 1576460738394 }

There is more data with other date type names

{ env: beta, product: analytics, dataType: nonvoice,  modifiedAt: 1476460738394 }

There is more data with other product names

{ env: beta, product: ingest, dataType: nonvoice,  modifiedAt: 1376460738394 }

There is more data with other environment names

{ env: qa, product: ingest, dataType: nonvoice,  modifiedAt: 1276460738394 }


Requirement:

Data should be stored in a way that supports two query options:

  1. I need a list of data sorted by ModifiedAt
  2. Latest data required - recently modified data


Solution:

Perform the following two opeartiongs when storing a data

  • Create history record - store the data with PrimaryKey - environment:productName:dateTypeName and SortKey - modifledAt and add attribute type: history
  • Create latest record - store the data with PrimaryKey - envinronment:productName and SortKey - dataTypeName and add attribute type: latest

Query methods:

To retrieve list of data:

 PK - envinronment:productName:dataTypeName

To get latest data:

PK - envinronment:productName and SK - dataTypeName

Post a Comment

0 Comments