I have a software application where we have 2 services, say A
and B
.
A
delegates some long running work(tracked by an id
) to B
which is done asynchronously.
They both talk via HTTP.
Post submitting the job, A
periodically does getStatus
calls passing the id
.
Given that any of A
or B
can die, I need to handle failure scenarios.
I was thinking of using above getStatus
calls as 2 way heartbeats
which would behave as following for unhappy cases(and their handling after ->
):
1. A unable to reach B -> heartbeat would timeout/connection refused, leading A to think work has failed
2. A is able to reach B but B has crashed and restarted -> heartbeat is treated as unknown, leading A to think work has failed
3. A dies/becomes unresponsive -> B misses few heartbeats and cancels its work(via timer), another A would reschedule this
Does above heartbeat
handling looks like a good approach for A
as well as B
to know about each other's liveness?
B
would get the message to start the work regardless as long asA
successfully sent the message. This avoids the need to have heartbeats to track liveness. IfA
wants to know status of a long running job, then it can queryB
using the job ID.liveness
tracking.