Messaging Patterns LabPython · ZeroMQ

Chapter 22

When does a worker own a job?

Separate transient routes, readiness, assignment identity and effect ownership.

Prerequisite: Dispatch with worker credit. Course map →

The situation

A worker reconnects under a new route while the dispatcher still associates a job with its old connection. Another worker has already received a retry.

Keep identities separate

A ROUTER uses a route label to direct a message to a connected peer. A worker ID names the application participant even if it reconnects under a new route. A job ID names the work across retries. An assignment ID names one attempt to give that work to a worker.

Decide which identities survive restart and who can issue them. Client-selected route labels are not authenticated users. Define collisions, reconnect behavior, stale routes and what to do with a result from an older assignment.

Readiness is application state

In the credit investigation, READY gives the dispatcher permission to assign one job to a worker. A later DONE can return that credit under the dispatcher’s rules. A connected route alone gives the dispatcher no evidence that the worker has an available slot. Credit returned after an acknowledgement has a different meaning from credit returned after durable commitment.

The local credit lab explicitly sorts initial readiness and drives workers serially. Its alternating assignments follow the explicitly written dispatcher policy. Testing concurrent workers or PUSH scheduling requires a different experiment.

What the dispatcher knows

Illustrative case.

Which row says a route exists? Which row tells the dispatcher that a worker can take a job?

BoundaryUseful evidenceRemaining question
Route existsCurrent transport addressingWorker capacity unknown
READY creditDeclared application admissionCompletion meaning must be defined
Assignment retriedA new attempt existsOld effect may be unknown
Proxy restartsConnectivity can returnJob ledger still separate

Recovery must settle unknown ownership

A dead or suspected worker may have completed an effect without delivering its response. Keep the job ID when retrying. Either make repeating the operation safe or have the service applying the effect reject an assignment that is no longer current. Retaining an assignment ledger is useful only if its persistence and relationship to the actual effect are defined.

A proxy can restore transport connectivity without reconstructing job outcomes. Test failure before receipt, during work, after effect and before acknowledgement. Include an old worker returning after a new assignment has started.

Operate the dispatch policy

Track which workers are ready, busy or unresponsive. Count attempts per job, rejected work and unknown results. Limit how many jobs can be outstanding and document what to do when a worker stops responding, loses its route or repeatedly fails on the same job.

Validate the real topology under load and failure. A deterministic socket exercise teaches envelope and policy wiring, but a multi-host scheduler needs actual deployment evidence for latency, fairness, leader failover and durable recovery.

Check your understanding

A worker sends DONE for attempt 7 after attempt 8 has started elsewhere. What must the dispatcher find out before accepting the late result?

Show hints
  1. Hint 1

    Use the attempt number to identify the assignment.

  2. Hint 2

    Find out whether either attempt has already applied the change.

Show explanation

Check which assignment is current and which worker actually applied the change. Ensure the system that applies changes checks the current assignment number. Decide how the dispatcher records the old reply and resolves any result that remains unknown.

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.