I am evaluating approaches to see how i can order expiry based on TTL. If TTL reaches, need to cancel the order.
One way to do same is keep on polling and checking which orders are expired say every minute. But this approach is extensive and say in cases don't want to wait a full minute to know about the expiry.
What could be some ways to handle it automatically in say push manner. Something like say using REDIS key expiry(not sure if its there), like some tool/code which keeps track of expiry and notifies. The orders could be in hundred's.
Redis has keyspace notifications that can help you with this. They use the Redis Pub/Sub mechanism. You can configure the Redis server to publish events for different types of operation and also selectively for parts of the keyspace.
You would then use a Redis Pub/Sub subscriber to be notified when a key has expired, and could take appropriate action in your application logic.
Note there may be a delay in the notification happening, but in most cases this is reliable enough to use - quoting https://redis.io/docs/manual/keyspace-notifications/:
The expired events are generated when a key is accessed and is found to be expired by one of the above systems, as a result there are no guarantees that the Redis server will be able to generate the expired event at the time the key time to live reaches the value of zero.
If no command targets the key constantly, and there are many keys with a TTL associated, there can be a significant delay between the time the key time to live drops to zero, and the time the expired event is generated.
Basically expired events are generated when the Redis server deletes the key and not when the time to live theoretically reaches the value of zero.
Keyspace notifications: https://redis.io/docs/manual/keyspace-notifications/
Pub/Sub: https://redis.io/docs/manual/pubsub/
Example application that uses these concepts: https://github.com/redis-developer/keyspace-notifications-node-redis -- this uses Node.js but any Redis Client that supports pub/sub will work.