I am creating a script for Task Assignment to multiple users. A task is assigned to a user, if it is not accepted in the next 30 minutes, I need to re-assign to another user.
Actually, I used DynamoDB for this, where every task assignment is attached to TTL after 30 minutes. When TTL expired I handled through Stream and check if it is accepted. If not, I was re-assigning and creating a new entry in the table with 30 minutes TTL.
I missed one concept of TTL that it is not expiring items in real-time and could take up to 48 hours.
Is there any other smart way to handle such use cases, currently I implemented this as -
- add an index with TTL as sort key and event_type = Task as a partition key
- query all the records every minute where TTL less than the current epoch, and batch deleting those records.
There are two challenges here -
- First, as event_type is constant across the table, all data is hitting one partition of the index, which is not good for big volumes
- it's a poll mechanism where I actually need to scan through all records, this is also not a scalable solution
I am exploring if we can do it smartly by a push mechanism. Any pointers or help to solve this use case?