I am looking for small design implementation suggestion
At some point in my existing REST endpoint
- SERVICE_1 calls another service SERVICE_2 for a task(say TASK_1), that call takes about 5 minutes MAX to complete
- Once SERVICE_2 finishes, it calls an endpoint(say /returnRes) on SERVICE_1 to inform about the status of that job. Other option can be that it may error out and can never respond.
- Once the SERVICE_2 starts TASK_1, SERVICE_1 put a message({id, time}) into some QUEUE/KAFKA
- When SERVICE_1 receive response from SERVICE_2 with status on endpoint(/returnRes), it polls the QUEUE/ and remove that message and process further(successfully responsed case processing)
- Or If within 5 minutes No_Response from SERVIVE_2 on endpoint(/returnRes), SERVICE_1 will look for messages where timer is exceeded 5 minutes, remove them and process further(NoResponse/Error case processing)
SERVICE_1 will have many instance running(horizontally scaled)
Questions:
-
I can use Queue(Kafka) to put messages, use springboot 3 features to poll every few seconds to see if any message with timer expiry. Make a note of the time when the next message will expire and fire my polling after that interval. I want to understand better way to work on this?
-
Even better if there are some solution already available around this kind of situation
Note: Ideally SERVICE_2 calling back to SERVICE_1 to respond is not a good design but that part exists today on my proj and can change that. I only plan to work/fix/implement on SERVICE_1
Please advice
Thanks