System Design Atlas

Multi-stage request approval

07 / 10Worked example

Critical flow

What is the time of the error, and what result can the system still claim afterwards?

The F-17 decision and R-4 submission both expect request A-17 at R-3/v7. Each successful command increments the request version, so exactly one wins. The sequences also show normal business and budget approval, a duplicate decision and a lost purchasing response.

Starting point Step 6 placed outbox processing after the approval commit.

Assumptions for the example case

Illustrative design: an internal procurement request for 6,000 euros undergoes business review followed by budget review. The inclusive budget threshold is 5,000 euros. These figures are assumptions rather than operational measurements. Ordering, payment, contract law and automatic decisions are outside the scope.

Four critical approval scenarios

A-17/R-3 durchläuft Fach- und Budgetprüfung. U-17 entsteht erst nach beiden Freigaben. Die Spur Prüfende benennt die jeweils handelnde Rolle ausdrücklich.

Applicants
Reviewers · Business/budget
Approval API
SQL · Request/outbox
Handover worker
Purchasing application
  1. 01 Applicants → Approval APISubmit R-3

    6,000 euros · requestKey · expected draft state

  2. 02 Approval API → SQL · Request/outboxStore R-3, P-2 and F-17

    submitted → reviewing in a transaction

  3. 03 SQL · Request/outbox → Approval APICommit · R-3/v7 reviewing

    First business review task stored durably

  4. 04 Approval API → Applicants202 · R-3/v7 accepted

    business review pending

  5. 05 Reviewers · Business/budget → Approval APIBusiness reviewer: approve F-17

    requestKey K-F-17 · expected R-3/v7

  6. 06 Approval API → SQL · Request/outboxF-17 approved + G-17 open + v8

    Atomically check revision, version, role, assignment and open; 6,000 euros ≥ 5,000 euros

  7. 07 SQL · Request/outbox → Approval APICommit · Business decision and evidence

    A-17 remains reviewing

  8. 08 Approval API → Reviewers · Business/budgetF-17 confirmed; G-17 on working list

    Only the budget owner may decide G-17

  9. 09 Reviewers · Business/budget → Approval APIBudget owner: approve G-17

    own requestKey · expected R-3/v8

  10. 10 Approval API → SQL · Request/outboxG-17 and A-17 approved + U-17 pending + v9

    Check permissions, version and open; write state, outbox and evidence together

  11. 11 SQL · Request/outbox → Approval APICommit · Business approval
  12. 12 Approval API → Reviewers · Business/budget200 · Approval R-3/v9

    Purchasing acceptance still pending

  13. 13 Handover worker → SQL · Request/outboxRead due pending outbox entries

    only committed entries

  14. 14 SQL · Request/outbox → Handover workerU-17 for approved R-3

    Stable key and immutable content

  15. 15 Handover worker → Purchasing applicationDeliver U-17

    authenticated target contract

  16. 16 Purchasing application · Local processingDurably accept and deduplicate U-17

    Link acceptance and downstream effect transactionally

  17. 17 Purchasing application → Handover workerAcceptance of U-17 confirmed
  18. 18 Handover worker → SQL · Request/outboxStore U-17 acknowledged

    Evidence references the same U-17/R-3

  19. 19 SQL · Request/outbox → Handover workerCommit · Handover confirmed

Dashed arrow: decoupled transfer. The messages are read from top to bottom.

Result: A-17 becomes approved after business and budget approval. U-17 remains pending until separate acceptance evidence arrives; only the worker communicates with purchasing.

The normal flow, revision conflict, duplicate decision and lost purchasing response use the same messages on desktop and mobile. The reviewer lane identifies the business reviewer or budget owner on each request.

Business-effect commit point

Before commit
A decision made is only an attempt. R-4 can still replace R-3.
At commit
Task status, active revision, current role, expected request version and resulting state are checked together. The winner writes v8; the other command against v7 receives 409. After rereading the state, the person can deliberately issue a new command.
After commit
The worker transfers U-17 from the outbox. A lost response leaves it pending instead of creating a second order.

Expected outcomes

ScenarioExpectationValidation
Normal flowA-17 approved, U-17 pending or acknowledged.Check business and budget approval records before the first handover attempt.
R-4 winsF-17 returns 409; no U-17 is created.Concurrent test with R-4 and F-17.
Response lostU-17 remains pending and is retried with deduplication.Target reports existing U-17 without a second order reference.
Duplicate decisionThe same requestKey returns the same record; changed content receives 409.Commit before loss of response; repetition does not produce a second G-17.

Normal flow

Expectation
A-17 approved, U-17 pending or acknowledged.
Validation
Check business and budget approval records before the first handover attempt.

R-4 wins

Expectation
F-17 returns 409; no U-17 is created.
Validation
Concurrent test with R-4 and F-17.

Response lost

Expectation
U-17 remains pending and is retried with deduplication.
Validation
Target reports existing U-17 without a second order reference.

Duplicate decision

Expectation
The same requestKey returns the same record; changed content receives 409.
Validation
Commit before loss of response; repetition does not produce a second G-17.

Terms in this step

Optimistic version check
The writing process compares the expected version with the currently stored version and rejects if there is a deviation.

Try it yourself

Track the case R-4 wins in six messages and name two illicit effects of the old decision.

A hint for your attempt

The outdated decision must not prepare a later worker assignment.

Compare with a possible solution
Six messages
1 Domain reviewer → API: decide on F-17/R-3/v7. 2 Applicant → API: submit R-4 against R-3/v7. 3 API → SQL: atomically write R-4, F-R-4, task cancellations and v8. 4 SQL → API: commit the version change. 5 API → SQL: check the old decision against the current state. 6 SQL → API: version conflict, no write effect. The API then returns 409 to the reviewer.
Unauthorised effects
The stale command must neither set A-17 to approved nor create U-17. A-17 remains reviewing on R-4/v8. Test: the request and new task are readable, old F-17 is cancelled and the handover is absent.

Apply to your project

Which external event in your project can only take place after which local commit?

Step 8 examines which measurements justify revisiting the initial design.