Manage Deletion of Stale Items in DynamoDB | Best Practices for AWS Developers

Manage Deletion of Stale Items in DynamoDB

Prev Question Next Question

Question

An application hosted in AWS has been configured to use a DynamoDB table.

Several items are written to the DynamoDB table.

These items are only accessed in a particular time frame, after which they can be deleted.

Which of the following is an ideal way to manage the deletion of the stale items?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - D.

The AWS Documentation mentions the following.

Time To Live (TTL) for DynamoDB allows you to define when items in a table expire so that they can be automatically deleted from the database.

TTL is provided at no extra cost as a way to reduce storage usage and reduce the cost of storing irrelevant data without using provisioned throughput.

With TTL enabled on a table, you can set a timestamp for deletion on a per-item basis, allowing you to limit storage usage to only those records that are relevant.

Options A and B are incorrect since these would not be cost-effective and have a performance issue on the underlying DynamoDB table.

Option C is incorrect since versioning is not possible in DynamoDB.For more information on Time to Live for items in DynamoDB, please refer to the below Link-

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

The ideal way to manage the deletion of stale items in a DynamoDB table is to enable Time To Live (TTL) for the items. Therefore, option D is the correct answer.

Enabling TTL allows DynamoDB to automatically delete items that have exceeded their expiration time. To use TTL, a column must be designated as the TTL attribute in the table. This attribute should contain the timestamp indicating when the item should expire. Once TTL is enabled, DynamoDB automatically deletes the expired items.

Option A is not ideal because scanning the entire table can be expensive and inefficient, especially if the table has a large number of items. Scanning for stale items is also prone to false positives and may result in deleting valid data.

Option B involves creating an additional column to store the date and then querying for stale items based on this column. While this method can work, it requires additional development effort and may not be as efficient as using TTL.

Option C involves enabling versioning for the items in the table. This method allows you to retain previous versions of an item, but it does not automatically delete stale items. You would still need to query for stale items and delete them manually, which is not ideal.