Risk and resilience × Programming
Business lens: Risk and resilience · Technology lens: Programming
Reading scope: Original synthetic teaching; selected primary background and same-author checks are not independent validation.
Failure is a business state
A program can fail before it changes a record, after it changes a record, or while the caller is waiting for confirmation. Those positions have different consequences. In a fictional order importer, a timeout after saving an order must not automatically cause a second order. Begin by describing the intended business event and its stable identifier. Distinguish input validation, attempted execution, recorded completion and acknowledged completion. A learner should draw these states before writing exception handlers. Otherwise a technically successful retry can create a business error that becomes visible only when finance or fulfilment reconciles the records.
Specify an invariant
An invariant is a condition that should hold across permitted operations. For this importer, each accepted external order identifier should correspond to one intended local order. State what happens if a second payload uses the same identifier but changes the amount. Treating every repeated identifier as harmless would conceal a conflict; accepting every payload would create duplicates. Define a comparison and an escalation rule. The developer implements the bounded check, operations explains legitimate amendments, and finance specifies evidence needed for monetary changes. The program should return an intelligible unresolved state when those business rules cannot establish an answer.
Worked retry reconciliation
The exercise contains forty distinct order intentions and fifty-two execution attempts. Twelve attempts are retries. The retry share among attempts is 12/52, approximately 23.08%, while retries per intention are 12/40 = 30%. These denominators answer different questions. Thirty-eight intentions have confirmed completion and two remain uncertain, giving confirmed coverage of 95%. Nothing in those counts establishes that fifty-two distinct orders were sold. If someone reports revenue using execution attempts as order count, repeated technical work becomes invented business growth. Reconcile identifiers before calculating sales and retain the two uncertain cases until evidence supports a disposition.
Handle errors deliberately
Separate malformed input, unavailable dependencies and conflicting business evidence. Rejecting a malformed amount is different from abandoning a valid order because a service is temporarily unavailable. Record enough diagnostic context to investigate the state without logging unnecessary personal information. Avoid catching every exception and returning success. Avoid infinite retries that increase pressure on the failed dependency. In the exercise, define a finite retry allowance and a consultation route after it is exhausted. A retry allowance is a local teaching assumption, not a universal production recommendation. The order's uncertainty survives until the owner resolves it.
Connect code and departments
Use the existing Python cleaning lesson to practise stable identifiers and explicit invalid rows in synthetic data. Add a table with intention identifier, attempt identifier, outcome and reconciliation status. Ask operations to explain how a corrected order is distinguished from a duplicate. Ask customer service what can truthfully be said while confirmation is missing. Assign a developer to the fault, a business owner to the amendment rule and an analyst to the denominator. Their handoff should include the smallest reproducible example, affected identifiers and the missing evidence. A vague message saying that the script is broken delays every department.
Test both outcomes and boundaries
The official Python unittest documentation supplies free background on assertions and isolated tests. For this case, test a repeated identical intention, a conflicting repeated intention and an unavailable dependency separately. A test passing on fictional inputs does not establish correct operation with every future payload. Preserve the exact version and expected result. Include a changed case with forty intentions, forty-eight attempts and thirty-nine confirmed intentions: retries per intention become 20% and confirmation coverage becomes 97.5%. Explain why improved aggregate coverage still leaves one uncertain business event requiring a named owner rather than automatic deletion.
Enquiry and levels
Who resolves a conflicting amendment? Whom does a retry delay? Whose identifier is authoritative? What state follows a timeout? Where is uncertainty recorded? When may another attempt occur? Why separate intentions and attempts? Which error needs consultation? How is confirmation reconciled? Foundation study explains a program and a repeated attempt. Undergraduate study computes both retry denominators and builds a small state table. Postgraduate study critiques error policies, logging costs and departmental authority. Research study proposes a bounded fault-injection experiment with declared states, synthetic inputs and predefined acceptance rules. The portfolio must clearly distinguish tests actually run from proposed production protections.
Study questions and answers
Compute retry share and retries per intention.
12/52 ≈ 23.08% of attempts; 12/40 = 30% per intention. Neither is a count of new sales.
Marking guide: Credit 12/52=23.08% attempt share and 12/40=30% retries per intention; neither counts new sales.
What is confirmed coverage?
38/40 = 95%; two intentions remain uncertain.
Marking guide: Credit 38/40=95% confirmed coverage and two uncertain intentions.
Why is a conflicting repeated identifier different from an identical retry?
Changed business content requires amendment evidence; silently treating it as a duplicate may conceal an unauthorised change.
Marking guide: Distinguish changed-content repeated identifiers from identical retries; require amendment evidence rather than silently discard the change.
Practice task
Build the intention/attempt state table and test identical, conflicting and unavailable cases on synthetic inputs. Preserve unresolved cases.
Practice bridge
- Build the intention/attempt state table and test identical, conflicting and unavailable cases on synthetic inputs. Preserve unresolved cases.
- Reproduce the stated arithmetic, change one valid assumption and distinguish actual lesson observations from the invented case.
Boundary: Original synthetic teaching connected to an existing bounded or guided lesson. No new executable fixture, catalogue lab or external platform execution claimed.
Sources and further reading
- Python unittest documentation
Scope: Selected assertions, fixtures and isolated testing background.
Access: Free selected official documentation/background page; no enrolment or certificate claim.