Chapter 16
What does silence tell you?
Decide what to do when a reply or a worker’s check-in is late.
Prerequisite: Where is the unfinished work?. Course map →
The situation
A worker is busy and misses a heartbeat, a periodic message that says it is still running. The dispatcher reassigns its job, then both workers produce an effect.
A timeout is an observation
No reply arrived before a local deadline. The remote handler may be slow, disconnected, paused, completed with a lost response or failed. Network and scheduler behavior can make those cases indistinguishable to the observer.
Measure elapsed time with a monotonic clock, which keeps moving forward when the system’s wall clock is corrected. Say which event starts and ends the wait. A connection/handshake timeout is different from a queue wait, handler deadline or end-to-end business completion objective.
Heartbeats need a protocol
Say which process sends each heartbeat, how it identifies itself after a restart and when a missed heartbeat triggers action. A thread whose job is sending heartbeats can continue while the thread doing the work is stuck.
Suspicion can justify a bounded operational action, but it does not settle an unknown effect. If an older worker may resume, give each new assignment a higher number. Have the system that writes the result reject requests with an obsolete number. This check is called fencing.
Clues after a missed reply
Illustrative case.
Compare a deadline with a heartbeat. After a missed reply and a received heartbeat, what do you still need to check about the first attempt?
| Boundary | Useful evidence | Remaining question |
|---|---|---|
| No reply by deadline | Local bounded absence | Remote outcome unknown |
| Heartbeat arrives | One liveness observation | Handler progress still separate |
| Job reassigned | New owner selected | Old owner may still act |
| Retry budget exhausted | No more automatic attempts | Reconciliation or durable escalation |
Retries consume capacity
Decide which failures are worth retrying. Keep the same request ID and cap the number of attempts and time spent. If clients could retry together, give them increasing waits with a small random delay. Avoid multiplying retries independently at every layer.
The retry investigation sends exactly two requests after deliberately withholding the first ACK. Production policy also needs cancellation, unknown-outcome reconciliation, late replies, duplicate retention and a durable place for unresolved work.
Test pauses and ambiguous outcomes
Inject slow service, lost replies after effects, disconnected pipes, stale heartbeats, process restart and a worker returning after reassignment. Observe logical jobs, attempts, pending age, duplicate effects and missing effects.
A detector’s threshold trades reaction time against false suspicion for the workload/failure model. Do not derive a universal safe deadline from one successful run on an emulated guest. Record the assumptions and test the real deployed timing environment.
Check your understanding
A worker still sends heartbeats for assignment 4. The dispatcher has already given assignment 5 for the same job to another worker. Where must the system check the assignment number to prevent the older worker from applying the change?
Show hints
Hint 1
Which version does the dispatcher currently recognize?
Hint 2
Which system can accept or reject the change?
Show explanation
The system that applies the change must check the current assignment number. When 5 is current, it must reject work from assignment 4.
ReferencesPrimary sources for this chapter’s design case
Use these guides to check the framework or protocol contract discussed in this chapter. Moving “stable” or “current” guides can describe a different release; check the version used by your deployment. These readings do not execute the distributed frameworks they compare.
ZeroMQ heartbeat options
ZeroMQ Guide: reliability