1
votes

I've read the developer guide for expiring items using DynamoDB TTL, and was wondering if it's possible to use TTL as an alternative to deletes, instead of in addition to.

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html

Since Amazon deletes the item for you (when convenient for them) without consuming any write units, would it be possible to have all of my deletes done like this? The idea would be to create items without a TTL, and then instead of deleting them just setting the TTL to the current time. I understand that I would have to add some logic to account for expired-but-not-deleted items, but this seems trivial compared to the savings.

Is this possible?

2

2 Answers

1
votes

The idea would be to create items without a TTL, and then instead of deleting them just setting the TTL to the current time.

That doesn't make sense, you'd need to use a WCU to update the item, might as well just delete it.

Using TTL to delete the item for free makes sense when you can set the TTL when the item is created.

I suppose setting the TTL with an update might be useful if you have multiple GSIs. You'd only pay for the update to the table, the delete's would be free. Whereas if you delete the record in the table, you'd pay for the table and the GSIs.

2
votes

You are correct in that the items themselves will be deleted without any cost to you which does make this process free for deleting items.

The deletion process can take upto 48 hours from the TTL time (the items are queued as a background action) so you would need to ensure your application performs the logic to filter these items out.

Depending on the size and activity level of a table, the actual delete operation of an expired item can vary. Because TTL is meant to be a background process, the nature of the capacity used to expire and delete items via TTL is variable (but free of charge). TTL typically deletes expired items within 48 hours of expiration.

Unless you have large volumes of data that you're deleting/updating you will simply be using any of the available WCU your DynamoDB table has remaining.