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

4 Comments

  1. Students preparing for competitive exams can also benefit from the structured lessons and quizzes available on E Shikshakosh.

    ReplyDelete
  2. Those exploring technology and innovation will appreciate EraTechInfo for its detailed coverage of global news and business trends. Each article is engaging, trustworthy, and provides context for complex topics in an accessible way.

    ReplyDelete
  3. In today’s fast-moving news environment, MaltaMagazine stands out by delivering comprehensive reporting on business, tech, and cultural developments. The platform ensures readers receive clear and reliable insights from both local and global perspectives.

    ReplyDelete
  4. Quality journalism shines through in RomaniaMagazine’s coverage of social, economic, and political topics. The articles offer clarity, context, and thoughtful insights into events shaping Romania and the wider world.

    ReplyDelete