Skip to content

Demo 14: compensation under fire - #17

Merged
MAOFILHO merged 1 commit into
mainfrom
demo14/compensation
Nov 17, 2026
Merged

MAOFILHO merged 1 commit into
mainfrom
demo14/compensation

Conversation

@MAOFILHO

Copy link
Copy Markdown
Owner

Why

A second reader of the LinkedIn post asked to see duplicate events and timeouts during compensation. Looking for them found a real gap: a release that beat its slow hold left the late hold, and its stock, held for good.

What changed

  • Inventory demo switch: holds or releases take 6 s, longer than the order service's 3 s timeout.
  • A release beats its hold: inventory records a release for a hold it never saw, so the late hold holds nothing. The stock is unchanged.
  • A release times out but goes through: the event copy lands first and the direct call second. The stock comes back once, and the page counts both copies.
  • Replayed events: a button resends a checkout's events with the same IDs.
    • Inventory skips the ones it already acted on and ignores the types that are not its business.
    • The page counts both.
  • One shared demo switch (DemoSwitch) and one "switches are off" answer, used by payment, inventory and order.
  • Page /patterns/compensation, plus README section 14 with a screenshot.

Tests

  • 194 unit tests pass, written test-first.
  • 28 local smoke tests pass, 3 of them new, one per case.
  • The frontend typechecks and builds.

🤖 Generated with Claude Code

…s, replayed events

A second LinkedIn reader asked to see duplicate events and timeouts during compensation.

- Inventory demo switch (slow_reserve / slow_release, 6 s, past order's 3 s timeout).
- A release for a hold inventory never saw is recorded as RELEASED (and logged), so a hold that
  arrives late holds nothing. Before, that late hold kept the stock held for good.
- Release counts every copy it receives (releases_received), so the page shows the timed-out
  direct call and its event copy both arrived and the stock came back once.
- POST /api/order/sagas/<id>/replay resends a checkout's events with the same ids; inventory
  counts what it skipped (duplicates_skipped) and what is not its business (not_handled).
- Demo switches share shop_common.flask_support.DemoSwitch and one switches_off() answer.
- Page /patterns/compensation, README section 14, smoke tests for the 3 live cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MAOFILHO
MAOFILHO merged commit aa1f90f into main Nov 17, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant