I'm trying to realize a service that executes operations at a certain time, those operations are specified by another service by messaging, here's the scenario:
- The service A receives a request to create an object, the service stores the object in its own database
- For every object, an operation must be executed at a given time specified in the object
- Trying to estabilish some business boundaries, the service B will be responsible for the execution of the above mentioned operations; this is because the role of the operation is to create a session accessible to clients (think it like a chat room that starts at X time and ends at Y time)
- I'm attempting to follow a coreographic architecture, so I would like for the service B to know what operations to execute and when to execute them
- According to this, service A will just send messages to the service B about what operations to execute and when they need to be executed
The problem is what is the best strategy for service B to achieve this once it receives messages; I thought of 2 solutions:
- Once the service B receives a message, it stores the informations on a dedicated database; the service can then check every X time the operations to be executed on the DB, but this can affect performance, since it requires continuous access and query to the database
- Once the service B receives a message, it starts a timer that will execute the operations at the given time; this will reduce operations to the minimum required, but if the service falls for any reason, all timers would be gone. This would imply writing logic to restore timers gone and already started ones.
I don't know if these are the best solutions; is there another strategy that I can use? Thanks