BCA
APIs and interoperability
Study map: Original subject-specific business–computing teaching chapter
An API connects systems through agreed requests, outcomes and failure behaviour. This chapter uses a local durable-request fixture to show why a lost response, retry or partial failure needs an explicit contract and recovery path.
Foundation: an interface is a shared contract
An application programming interface defines how one component requests or supplies behaviour from another. In business integration, the interface may connect order entry, fulfilment and reporting. A useful contract describes inputs, outcomes, errors and responsibilities. A machine-readable format alone does not establish agreement about what an order status or monetary amount means.
Distinguish an operation request from evidence that it completed. A client may send an approval and lose the response after the server commits the change. A timeout is therefore ambiguous: it may mean nothing happened, or that the result was not observed. Retrying without an agreed policy can create duplicate work. The client and server need consistent identifiers, outcome queries or another appropriate recovery mechanism.
The runnable exercise models the handling logic locally. It does not run an HTTP server, send network requests or authenticate users. This limitation is deliberate: first understand the contract and state transition, then add transport with its own failure modes. A simulated operation is useful teaching but must not be represented as a deployed API service.
Undergraduate: specify payloads and retry behaviour
Our request has an identifier, order identifier and positive integer amount in paise. R1, O1 and 10,000 represent one synthetic approval. A second identical R1 returns replayed and leaves the total unchanged. A changed payload with the same request identifier returns conflict. A different request identifier naming an already recorded order returns order-exists. These outcomes separate a retry from a new attempt and from a disputed meaning.
The implementation stores the request and order in one SQLite transaction. If a synthetic failure occurs after writing the order but before recording the request, the entire transaction rolls back. A later retry can therefore approve the order once without inheriting a half-completed operation. Closing and reopening a connection does not discard the file-backed state. The demo's temporary directory is removed at exit; persistent-state experiments use a learner-selected practice path or the supplied tests.
HTTP methods have defined semantics. Idempotence concerns the intended server effect of repeating an identical request, not a guarantee that every response is identical or every network operation succeeds. Do not infer that a creation request is automatically safe to retry merely because the payload is JSON. Read the protocol and the application's contract together. The lab's replay policy is an application rule, not a claim of universal HTTP behaviour.
Postgraduate: design boundaries and recovery
A contract review should cover schema, identity, permitted transitions, error categories, retry policy, version compatibility and monitoring. Decide which errors are correctable by the client and which require human review. Blind retries of a malformed amount waste work; automatic acceptance of a conflicting identifier hides a business disagreement. State which department owns each exception and how it is reconciled with source records.
The transaction protects changes within one database. It does not atomically send an email or approve an external payment. To extend the design, separate local persistence from external effects, record work that still needs delivery and define how delivery failures are retried and reconciled. Do not claim exactly-once delivery across independent systems merely because a request table has a primary key.
Security and usability need explicit boundaries. Parameterised SQL separates values from query structure, while a trusted identity mechanism must establish who may invoke the operation. The fixture role argument does not provide that trust. Operational design also needs request limits, monitoring, compatible changes and a recovery plan. These are requirements to study, not features secretly supplied by the teaching script.
Research: test reliability and organisational outcomes
A study might ask whether durable request tracking reduces duplicated approvals during network interruptions. Define the interruption scenarios and distinguish computational properties from business outcomes. Tests can show that the implementation preserves an invariant under specified failures. They cannot establish effectiveness under every crash, deployment environment or organisational procedure.
Measure duplication, unresolved ambiguity, recovery delay and manual correction effort. Track whether a stricter conflict rule blocks legitimate work and whether staff find the escalation route workable. A comparison should include the same kinds of requests and failures; reporting only successful demonstrations omits the difficult cases. State the limits of the SQLite fixture and what evidence would be needed for a distributed implementation.
Submit the request contract, predicted outputs, failure tests and an exception memo. Connect the nine enquiry words to a concrete event: who may request, whom it affects, whose amount is authoritative, what changes, where state persists, when a retry occurs, why it is permitted, which conflict needs review and how the approved total is reconciled.
Study questions and answers
What does a timeout establish about whether an approval committed?
It establishes that a response was not received within the allowed period, not that the operation failed. The change might already have committed, so retry requires an agreed identity and recovery policy. Indicative marking: Core distinction or result 3; mechanism/reasoning 3; case application 2; explicit limitation 2.
Predict identical replay, changed payload and failure before recording the request in the SQLite exercise.
Identical key and payload returns replayed without another order; changed payload returns conflict. A failure after the order insert rolls back both transactional effects, and a subsequent valid retry can approve once. Indicative marking: Core distinction or result 3; mechanism/reasoning 3; case application 2; explicit limitation 2.
Does atomic storage of order and request guarantee exactly-once email or payment effects?
No. The transaction boundary is one database. External effects need separate delivery, retry and reconciliation design; a local primary key does not prove a distributed exactly-once guarantee. Indicative marking: Core distinction or result 3; mechanism/reasoning 3; case application 2; explicit limitation 2.
What evidence is needed to evaluate durable retry handling?
Test specified failures and verify counts and totals after restart, then evaluate unresolved ambiguity, recovery delay and correction burden under comparable request conditions. Disclose untested crash, transport and deployment scenarios. Indicative marking: Core distinction or result 3; mechanism/reasoning 3; case application 2; explicit limitation 2.
Extended practice questions
What does a timeout establish about whether an approval committed?
It establishes that a response was not received within the allowed period, not that the operation failed. The change might already have committed, so retry requires an agreed identity and recovery policy.
Marking guide: Core distinction or result 3; mechanism/reasoning 3; case application 2; explicit limitation 2.
Marks: 10
Predict identical replay, changed payload and failure before recording the request in the SQLite exercise.
Identical key and payload returns replayed without another order; changed payload returns conflict. A failure after the order insert rolls back both transactional effects, and a subsequent valid retry can approve once.
Marking guide: Core distinction or result 3; mechanism/reasoning 3; case application 2; explicit limitation 2.
Marks: 10
Does atomic storage of order and request guarantee exactly-once email or payment effects?
No. The transaction boundary is one database. External effects need separate delivery, retry and reconciliation design; a local primary key does not prove a distributed exactly-once guarantee.
Marking guide: Core distinction or result 3; mechanism/reasoning 3; case application 2; explicit limitation 2.
Marks: 10
What evidence is needed to evaluate durable retry handling?
Test specified failures and verify counts and totals after restart, then evaluate unresolved ambiguity, recovery delay and correction burden under comparable request conditions. Disclose untested crash, transport and deployment scenarios.
Marking guide: Core distinction or result 3; mechanism/reasoning 3; case application 2; explicit limitation 2.
Marks: 10
An order API times out and the client immediately submits the same purchase as a new request. What risk and safer recovery should be considered?
The server may already have processed the original request even though the response did not reach the client. A new purchase identity can therefore create a duplicate commitment. Use a documented request identity and a supported means of discovering the existing outcome, or route uncertain cases to controlled reconciliation. Do not assume every API supports the same idempotency mechanism. Test committed-response-loss and uncommitted-failure scenarios separately with synthetic records. The business owns order and payment policies; developers implement the agreed recovery boundary. A timeout is evidence of uncertainty about the response, not proof that the purchase never occurred.
Marking guide: Commit before lost response; duplicate risk; supported identity/reconciliation; distinct tests; no universal mechanism. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.
Marks: 10
Compare schema validation with business-rule validation at an API boundary.
Schema validation checks the expected structure and types, such as whether quantity is an integer and an order identity is present. Business-rule validation checks whether the requested action is acceptable in context, such as sufficient stock or authority for a discount. Both are needed, and a structurally valid request can still violate policy. Record errors so the caller can respond appropriately without exposing sensitive internals. Technical teams implement the checks, while business owners define the rules. Passing schema validation does not establish authorisation, correctness of every field meaning or successful execution of the business transaction.
Marking guide: Structure/types versus contextual acceptability; example; roles; useful errors; schema limits. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.
Marks: 10
An API receives 100 calls, including twenty retries of earlier request identities. Eighty unique requests include seventy committed outcomes. Calculate the unique-request completion rate and explain the call-count trap.
Unique-request completion is 70/80 = 87.5%. Dividing by all 100 calls gives 70%, which answers a different question and treats retry traffic as additional unique demand. Preserve the mapping between request identities and attempts. The exercise does not specify whether unresolved requests failed, remain pending or have an unknown outcome, so do not label all ten as permanent failures. Monitor attempts for technical load and unique outcomes for business completion. A client and server need compatible identity handling; counting calls alone cannot establish how many distinct customers or purchases were served.
Marking guide: 87.5%; 70% different denominator; attempts versus outcomes; unresolved status; identities. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.
Marks: 10
Specify a reproducible API integration test plan without using live customer records.
Create synthetic requests for valid input, malformed structure, policy rejection, missing authority, repeated identity and response loss after processing. Define the expected status and record state for each case. Verify that errors are understandable and that no secrets appear in logs. Test a changed payload with an existing identity according to the API's documented contract. Preserve fixtures and execution instructions so another learner can reproduce the checks. These tests validate stated behaviours in the bounded environment, not every security or production condition. Business and technical reviewers must agree which guarantees the integration actually provides.
Marking guide: Synthetic varied fixtures; expected states; safe errors/logs; contract-specific identity; reproducibility and scope. Indicative allocation: reasoning 4; application or workings 3; assumptions and limits 3.
Marks: 10
Revision cards
What is an API contract expected to specify?
It defines inputs, outputs, meanings, errors and relevant behavioural expectations between systems. Include identifiers and version assumptions. Matching a JSON shape is insufficient if the systems interpret quantities, time or business status differently.
An order API times out and the client immediately submits the same purchase as a new request. What risk and safer recovery should be considered?
A timeout does not prove failure to commit. Reuse a supported request identity or reconcile the known request before creating another purchase.
Compare schema validation with business-rule validation at an API boundary.
Schema checks structure and types; business validation checks contextual acceptability. A well-formed request may still lack stock, authority or policy validity.
An API receives 100 calls, including twenty retries of earlier request identities. Eighty unique requests include seventy committed outcomes. Calculate the unique-request completion rate and explain the call-count trap.
Unique completion is 70/80 = 87.5%. Seventy outcomes over 100 calls is 70%, but retries make call count a different denominator.
Specify a reproducible API integration test plan without using live customer records.
Test valid, malformed, rejected, unauthorised, duplicate and response-loss cases with synthetic fixtures. State expected records and contract limits; passing tests are bounded evidence.
Why can retrying an API call duplicate business work?
A request may succeed while its response is lost. A retry can repeat the action unless the application implements an appropriate duplicate-handling mechanism. A client timeout does not prove server failure or establish that repeating the request is safe.
How should an integration handle partial completion?
Identify which operations succeeded, preserve their identifiers and choose an authorised recovery or compensation path. Do not label the whole workflow complete without evidence. Undoing one step may not reverse external commitments or restore the original state.
Why distinguish a transport success from business acceptance?
A successful HTTP exchange indicates a protocol outcome, while the payload and application contract determine the business result. A received response may describe rejection or pending work. Check the defined status rather than treating connectivity as completed fulfilment.
What helps an API evolve without breaking consumers silently?
Version expectations, compatibility tests, documented changes and a transition plan help consumers adapt. The server and clients may upgrade at different times. Keeping the same endpoint address does not guarantee that its behaviour remains compatible.
Practice task
Complete transformation-workshop.html: predict outputs, run the durable-request fixture, test failure and restart, and submit a contract, role table and balanced benefit case.
Sources and further reading
- Transformation and dependable requests workshop
Type: Original teaching and local practice
Use: A connected case with predicted outputs and explicit limits - HTTP Semantics: RFC 9110
Type: Free primary standard
Use: Study method and retry semantics; not a tutorial for organisational governance - Python sqlite3 documentation
Type: Free official documentation
Use: Connection, transaction and parameterised-query behaviour