amazon-dynamodbttl

DynamoDB TTL Interaction When Dealing with A Single Partition Key


I currently have a table structure with the following columns:

pk (partition key)
sk (sort key)
attr_1
attr_2
ttl

Here pk and sk are both string values. pk is a domain string (think pokemon name) and sk is a timestamp representation of when the entry was created. Some sample data below:

[pikachu, 2024-01-03 18:00:00, v5, v6, 5th jan 2024 (in its epoch format)]
[pikachu, 2024-01-02 18:00:00, v3, v4, 4th jan 2024 (in its epoch format)]
[pikachu, 2024-01-01 18:00:00, v1, v2, 3rd jan 2024 (in its epoch format)]

So the question here is -- given that I have multiple ttls across a single pk would the oldest entry (row 3 above) expire in its due time (of course I understand the deletion is not instantaneous but you get the gist).

My confusion stems from the fact that all ttl documentation for DynamoDB talks about expiration of an item but in my case the pk is shared across multiple items. Any clarification on this would be appreciated, cheers.


Solution

  • If it were instantaneous, row 3 would be removed first as it has the oldest TTL value.

    However, you'd typically see all items deleted at the same time if their time range is close enough (secs, mins, hours).

    If you're looking for the specific order in which they'll be deleted, it's not guaranteed. However, as DynamoDB stores data in ascending order of sort key, I would assume that the youngest item would delete first, followed by the other two immediately.