I have the need to store temporarily some change tracking data in DynamoDB.
Initially I thought having the following attributes:
Attributes:
-
recordId (String): Identifier for the entity.
-
lastTimestamp (Number): Timestamp of the last change.
-
changes (String): JSON string containing the change details.
{
changes: [
{ timestamp: ‘2024-04-01 16:14:23’, user: 11111, property: ‘inventory’, original: ‘0’, current: ‘1.5’},
{ timestamp: ‘2024-04-01 16:14:23’, user: 11111, property: ‘assetId’, original: ‘123455’, current: ‘223344’},
{ timestamp: ‘2024-04-01 17:20:01’, user: 2222, property: ‘cost’, original: ‘1.5’, current: ‘1.0’},
]
}
Instead of creating a new object in the table I just get the item by recordId and append to the json attribute “changes” a new item.
The problem with the above is that i think is not that performant if I want to filter by timestamp of each of the changes because that timestamp lives in each changes array item.
So now Im thinking on having these attributes:
Attributes:
- recordId (String): Identifier for the entity.
- timestamp (Number): Timestamp of the change.
- property (String): Name of the property that was changed.
- original (String): Original value of the property.
- current (String): Current value of the property.
In the above i will have to create a new DynamoDB record for each change.
Is important to mention that TTL will be set to they can expire in about 3 months.
What scenario do you think is better? Appreciate any recommendation