Messaging Patterns LabPython · ZeroMQ

Chapter 5

What completed when send returned?

Identify what the sender and receiver know at each step of a request.

Prerequisite: Send work down a pipeline. Course map →

The situation

A process logs “sent” and exits. Another team reads that log as proof that a customer’s order was stored. The log says what happened at the sender. The team still needs evidence from the storage system.

Name five different events

Admission means the local send call accepted the message under that socket’s rules. Reception means the peer received the message. Execution means the handler ran. A commit records the operation at the point where the system promises it will survive a specified failure. An acknowledgement is a reply that reports an outcome to the caller. A failure or delay can separate any of these events.

Document what each acknowledgement (ACK) promises. An ACK sent before a database commits can arrive while the change is still pending. An ACK sent after commit can be lost. The caller then needs another way to find out whether the operation committed.

Compare two crash points

Commit before replying permits a completed operation with a missing receipt. Reply before commitment permits a visible receipt for work later lost. A crash can also occur between applying the change and saving the position from which the reader will resume. Independent systems need an agreement or a recovery procedure that covers both actions.

List each crash point and record which effects and replies survive it. In the retry lab, the handler adds a charge to a list in memory and deliberately drops the reply. The run shows that the client can miss the reply after the handler acts. The list disappears when the process stops.

Send, commit and reply

Illustrative case.

Compare “Handler commits; ACK lost” and “ACK before commit”. What can the caller see and what must storage confirm?

BoundaryUseful evidenceRemaining question
send returnsLocal admissionRemote outcome remains separate
Handler commits; ACK lostEffect may existStable identity and reconciliation
ACK before commitClient saw a replyPotential loss after a crash
All guests closeNo local recovery stateA durable authority is required

Decide what will survive a restart

If work must survive every connected process stopping, choose a system that keeps a record of pending work and its outcomes. That might be a database, a log or a queue. An external service may provide a receipt you can look up or accept a stable request ID so a retry has the same effect as the first call. Decide how long recovery records are available and who can read them.

A proxy forwards messages. Larger socket queues and longer shutdown waits change how long messages stay in memory. For a retry, setting the same value under the same key may be safe, while incrementing a balance or sending a notification twice may have a second effect. Once the record of processed IDs expires, decide how to handle a repeat.

Make evidence reviewable

Give each requested operation a stable ID. Record send attempts, replies, unknown outcomes and repeated effects separately. A final row count can hide repeated deliveries. For a recovery claim, record where reading resumes after a restart and where each effect was saved.

Each run uses a temporary Linux guest. An exported result describes the run. To test durable recovery, restart the system that stores the effects and check for work that was lost or applied twice.

Check your understanding

A service replies with ACK after a write to a local file. The service has no procedure to recover that file after losing power. What can the client conclude?

Show hints
  1. Hint 1

    What does the receipt itself report?

  2. Hint 2

    What evidence would tell you whether the write survives power loss?

Show explanation

The client knows the handler sent the reply. To establish that the change survives power loss, test the storage system and its recovery procedure after that failure.

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.