AAmit’s LibraryLEARN · PRACTISE · REFLECT

Execution and iteration × Databases

Business lens: Execution and iteration · Technology lens: Databases

Reading scope: Original synthetic business and computing application. Source links support technical background, not the invented organisations or arithmetic.

Execution requires a consistent record

An online stationery seller updates stock in one screen and records orders in another. During a busy afternoon two staff members both see three notebooks available and each accepts an order for two. Execution breaks when a decision uses a state that has changed. Iteration must address that failure mechanism, not merely add a warning banner. Define the business invariant: accepted reservations must not exceed available stock under the chosen inventory policy. Separate physical stock, reserved quantity and fulfilled quantity so departments can explain the balance. A database can coordinate certain related updates, but it cannot make a missing delivery arrive or decide whether a customer should accept a substitute. Preserve that boundary when proposing an automated fix.

A transaction is an operational unit

For a local SQLite teaching example, create an order identity and attempt a guarded stock update inside an explicit transaction. The update should succeed only when sufficient unreserved stock exists; inspect the affected-row result before accepting the reservation. If the guard fails, roll back and tell the caller the order was not accepted. SQLite has one simultaneous writer, so the example is not a claim about every distributed database architecture. Busy conditions and retries need explicit handling. Use a stable request identity to avoid accepting the same customer request twice. A transaction covers the related local records; it does not automatically coordinate an external payment or a courier's system.

Trace the inventory rather than a success message

Start with three unreserved notebooks. Request A asks for two and succeeds, leaving one. Request B asks for two and fails the guard, leaving one rather than minus one. If A is retried with the same request identity, return the existing reservation without subtracting two again. If a later authorised cancellation releases A, unreserved stock returns to three. These four steps form a small state trace. Check order status and quantity after each step, not just the final balance. A cancellation that increments stock but leaves the order marked reserved creates another inconsistency. Use the trace to define expected outcomes before writing the programme and retain it as a regression check after the next improvement.

Handoffs and managerial involvement

Sales may communicate accepted orders only after the reservation outcome is known. Warehouse staff confirm physical availability and report damaged stock. Finance reconciles authorised payment outcomes with order states. IT manages transaction logic and retry handling. Customer support explains rejected reservations and offers alternatives within the business policy. A manager reviews cancellations, rejected requests and physical discrepancies, rather than celebrating transaction success alone. When a stock adjustment occurs, record its reason and responsible role without giving every employee unlimited edit rights. Departments need a shared definition of reserved, paid, picked and dispatched. The database eases coordination by retaining explicit state; humans resolve exceptional commitments and investigate why the recorded stock disagrees with the shelf.

Failure recovery and levels

Suppose a transaction commits but the confirmation message is lost. The customer retries, creating the appearance of a failed operation even though stock is already reserved. The stable request identity lets the application discover the committed result. A separate payment failure may require a later compensating cancellation under the defined policy; it is not solved by pretending an external transaction belongs to the local database. Foundation learners trace the notebook balance. Undergraduate learners implement guarded updates and deliberate rollback. Postgraduate learners compare retries, idempotency and compensation boundaries. Research learners study how state visibility affects interdepartmental dispute resolution, define evidence from synthetic event histories and distinguish correlation from organisational causation. A bounded SQLite demonstration is a foundation for analysis, not production readiness.

Nine questions and controlled iteration

Who authorises a manual stock adjustment? Whom should sales consult when physical stock disagrees? Whose request identity prevents duplicate reservations? What invariant must hold after every accepted order? Where are cancellation reasons recorded? When should a retry return an existing outcome? Why is a lost confirmation different from a rolled-back order? Which changes belong in one local transaction? How will the team reconcile an external payment failure? Submit the four-step trace, a state table and a test plan covering a failed guard, duplicate request and cancellation. Then propose one improvement and rerun the same evidence. Continuous improvement means changing a known failure mechanism while checking the existing guarantees, not adding features without an operational baseline.

Study questions and answers

Trace A, B, duplicate A and cancellation A.

Starting at three, A reserves two and leaves one. B cannot reserve two, so the failed guard leaves one. Duplicate A returns the recorded outcome and leaves one. An authorised cancellation of A releases two and returns availability to three, with the order state updated consistently.

Marking guide: Credit availability sequence 3→1 after A, remaining 1 after failed B and repeated A, then 3 after authorised cancellation. Require consistent order state and the failed capacity guard.

Why is a lost confirmation unsafe to handle as a new order?

The local transaction may already have committed. A retry with the same request identity should discover that existing reservation instead of subtracting stock again. Check the committed state; a network message failure does not prove that the database operation failed.

Marking guide: Credit possible committed reservation despite a lost confirmation. Require the same request identity and authoritative state before retry; message failure is not transaction failure.

Does the local transaction automatically roll back an external payment?

No. The database transaction covers the specified local records. External payment outcomes require reconciliation and a defined compensation or cancellation policy. State the boundary and preserve evidence; do not claim atomicity across services that the exercise has not implemented.

Marking guide: Credit local transaction boundary and separate external-payment reconciliation/compensation. Reject unimplemented cross-service atomicity; preserve outcome evidence.

Practice task

Submit the inventory state trace, guarded-update specification, retry tests and payment-boundary memo.

Sources and further reading

  • SQLite transaction reference
    Scope: Public documentation on transaction behaviour; synthetic business cases below are our own. No course or certification review.

Related chapters

Interactive practice

Open workshop

Open interactive matrix reading