Chapter 30
Diagnose the missing receipt
Trace the outcome of a request whose first reply never arrives.
Use the run evidence to identify a repeated charge and decide what to test before trusting a repair.
Prerequisite: Review a complete messaging design. Course map →
The situation
The shop sees a correct final reply and two request attempts. Finance asks whether the underlying effect occurred once.
This example combines two earlier lessons. One retries a charge after the handler records it and withholds the first reply. The other matches three out-of-order replies by request ID. The charge history and the record of seen IDs exist only in this run’s Python memory.
- RetryTwo attempts use charge-aThe first handler applies 12 and withholds its reply. The rule for repeated IDs decides whether the next attempt applies another 12.
- Response matchingReplies for c, b and aThe client uses the request IDs to match them to C, B and A.
Conceptual diagram. The charge list and processed IDs are kept in memory. A lasting payment record requires a separate storage or service agreement.
Before you run
If you can see a final ACK, what evidence would show how many times the charge was recorded?
Run the experiment
One request for a charge of 12 is tried twice. A separate exchange sends replies c/C, b/B and a/A in reverse request order.
For the original example, click Restore code if it is shown, then click Run. Compare your output with the worked result.
Python prepares in the background while you read. First use can download about 71 MiB. Your code runs only when you select Run; each run starts with clean experiment state.
Your edits are saved in this browser when storage is available.
Full error details
Run output
Troubleshooting
If Python stops responding, restart the environment and try again. Your code and last completed result are kept.
Downloads
Worked result
effect_total is 12 after two request_attempts. The handler skipped the repeated ID. matched_replies assigns the three replies to their requests.
Full output from the original example
{
"effect_total": 12,
"request_attempts": 2,
"logical_requests": 1,
"matched_replies": {
"a": "A",
"b": "B",
"c": "C"
},
"diagnosis": "The first ACK is deliberately lost after applying work. Stable identity and an authored duplicate policy affect the visible effect; transport success alone does not."
}The build ran the original editor code to produce this output.
Try one change
Run the starter. To save its result, open Downloads and click Export run. Replace the last line with result = capstone(deduplicate=False), run again and export that result. Compare request_attempts and effect_total. Use the retry lesson to identify the attempt where the extra effect first appears.
Inspect the socket implementation
The editor calls this read-only helper. Read all socket helpers or read the separate-process code. The code download includes both files.
def capstone(deduplicate=True):
retry=retries(deduplicate)
matched=correlation()
return {'effect_total':retry['total_effect'],'request_attempts':len(retry['attempts']),'logical_requests':1,'matched_replies':matched['matched'],'diagnosis':'The first ACK is deliberately lost after applying work. Stable identity and an authored duplicate policy affect the visible effect; transport success alone does not.'}
Costs, waiting and recovery
| Aspect | What to account for |
|---|---|
| Work | Count the orders separately from the number of attempts and replies. |
| Stored information | Track the IDs being handled now and the IDs kept so a retry can be recognized. |
| Message path | The socket delivers messages, and the application records the charges. Inspect both kinds of evidence. |
| Waiting | Set a time limit for waiting. Decide what to do with late replies and with requests of unknown outcome. |
| Recovery | Test a crash at the point where the charge is applied and again after the charge but before the reply. |
Check your understanding
Design a production repair if the duplicate record and actual effect live in different systems. What are your next three failure tests?
Show hints
Hint 1
Where is each request recorded, and where is the charge applied?
Hint 2
What could happen if the charge succeeds but the receipt is lost?
Hint 3
What changes if the process restarts or the record of seen IDs expires?
Show explanation
Use a service that recognizes repeated requests by ID, or save the ID and the effect in one transaction when both are local. Test losing the reply after completing the work, restarting and retrying the same ID, and retrying after the ID record expires. Check for missing and repeated effects in each test.
ReferencesFunction documentation and helper source
References open in a new tab; course helpers are documented separately from library APIs. PyZMQ API links use version 27.3.0.
Reconcile reply matching and retries
The capstone composes the course correlation and retry helpers. Read the socket contracts while accounting for attempts and effects separately.
Course helper implementation
These are functions written for this course, not additional library APIs. Inspect their parameters, operator calls and authored policies. The source shown is generated from the same Python files packaged with Run and Download Python.
Experiment scope
The lab combines real socket exchanges and a Python list that represents charges. The list and seen-ID set disappear when the lab stops.
ZeroMQ reference · Runtime and model boundaries