Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Would DyanomoDB delete item immediately based on TTL, how can I achieve deleting an item from table after 5 minutes?

I have a login session valid for 5 minutes from the last activity. If there is any activity I update the time-to-live attribute in the item by adding 5 minutes, otherwise it should get deleted at time set in ‘expireAt’. But why does the item in dynamoDB not get deleted as per the time-to-live set in item ‘expireAt’ ?

In Java Spring-Boot, I have set EPOCH time in seconds as mentioned in the documentation login.setExpireAt((System.currentTimeMillis() / 1000) + 300);. It does not delete item in table after 5 minutes. What alternate approach can I adopt to work around this ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

But why does the item in dynamoDB not get deleted as per the time-to-live set in item ‘expireAt’

DynamoDB TTL works on a best effort basis as it provides free deletes for your table. If you item has surpassed its expiry time then it is eligible for deletion eventually, but that could be mins/hours/days in the future. If you need more strict deletions you have some choices:

  1. Create your own TTL eviction with EventBridge Scheduler
  2. Use a filter expression on reads, which filters out items that have surpassed the expiry time and should be evicted
  3. Create your own TTL sweeeper that periodically reads and deletes items from DynamoDB.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading