DEV Community

Cover image for Alternative to Amazon DynamoDB Time to Live (TTL)
Prabusah
Prabusah

Posted on • Edited on

4 3

Alternative to Amazon DynamoDB Time to Live (TTL)

Scenario:

  • Certain data lose relevance after a specified time.
  • So create records in datastore that should exists only for a specified time from the creation time.
  • Time can be anything from 1 second to hours.

Example Case: Make the record expire within 10 seconds of its creation time.

Option 1: Application based timer (Not Recommended)
Whenever Application creates a record it has to trigger a timer as shown below JavaScript example timer:

/*
setTimeout's not the right way to keep track of timer... Let's assume it works for explaining this option.
*/
setTimeout(function() {
    purgeRecord(recordId);
}, 10000);
Enter fullscreen mode Exit fullscreen mode

Problem: An Application receiving thousands of request per second has to create those number of timers. This option is not scalable.

Option 2: Amazon DynamoDB - (Not Recommended)
DynamoDB per-partition scanner background process automatically and continuously evaluates the expiry status of items in the table.

Problem:
Amazon DynamoDB TTL typically deletes expired items within 48 hours of expiration. Scan & Filter by timestamp not a scalable option.
This option works best if your TTL is minimum 48 hours.
Not matching with our scenario of expiring items in 10 seconds.

Option 3: Amazon Elasticache (Recommended)
Redis compatible Amazon Elasticache honours TTL by seconds.
Code example:

redis_client.set('key', 'value', {
  EX: 10
});
Enter fullscreen mode Exit fullscreen mode

Matches with our 10 seconds expiring scenario.

Please let me know your thoughts or other options in comments.

Image by Sadia from Pixabay

Imagine monitoring actually built for developers

Billboard image

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay