Navigation

Retail / commerce

StockPoint

Orders, stock, promotions and returns across stores and a distribution centre, with no overselling when hundreds of checkouts chase the same units.

In the demo you replay Black Friday for a fictional NZ homewares retailer: 600 checkouts compete for 40 units, a stock count releases exactly the promises it broke, and you compare a recovery plan before applying it. Underneath: an append-only stock ledger behind one conditional UPDATE, allocation that stores the reason for every choice, and versioned pricing.

My role
Sole engineer: spec to deployment
Walkthrough
90-second guided scenario
Focus
Correctness under concurrent demand

Launch guided demo (opens in a new tab)Engineering evidence

Stack: React · TypeScript · PHP/Symfony · PostgreSQL · Playwright + axe

Independently built portfolio showcase · simulated data

StockPoint order H-1007: a cotton cushion and a linen throw both allocated to ship from the Riccarton store with a Mon 30 Nov promise, and the "Why this allocation" panel listing the locations not chosen with the reason for each.

The business problem

A retailer with eight stores, a distribution centre, a website and an app runs Black Friday. Hundreds of checkouts chase a few discounted units, a store count finds stock missing, a supplier delivers early and short, and a promotion stacks by mistake — all landing on orders customers were already promised.

Try the workflow

  1. Step 1

    StockPoint trading floor at 09:00 on Black Friday: the flash-sale guide strip, 25 of 40 eligible throws reserved, availability per location for the linen weighted throw, and a feed of allocated orders H-0998 to H-1007.
    Flash sale: checkouts compete for 40 eligible units; reservations stop exactly at what exists.
  2. Step 2

    StockPoint at 10:30 with a "Reality check" alert: a Ponsonby count of the stoneware table lamp found 5 against a system figure of 12 (−7), waiting for approval above the stock-by-location table.
    Reality check: a store count finds 5 where the system expected 12. Approving it releases exactly the broken promises.
  3. Step 3

    StockPoint recovery comparison for 6 orders released by the count shortage: three options (Keep promise dates, Fewest shipments, Lowest cost) with their customer, shipment and cost impact, the per-order changes and an "Apply 4 delivery changes" button.
    Recovery: three plans compared before anything changes; applying one commits a reviewed decision, or gets a conflict if the data moved.

Engineering invariants

Rules the system enforces whatever the user does, and where each one is proven.

InvariantWhy it mattersEvidence
A channel can reserve stock only if enough is free after reservations, picks and store protection. One conditional UPDATE on the balance row checks this; a CHECK constraint is the last guard.Never commits more stock than exists, even when hundreds of requests hit the same SKU.Contention test: 600 requests, exactly 40 commit, 20 runs (opens in a new tab)Integration/StockPointContentionTest.php :: testExactlyTheEligibleUnitsCommitUnderContention
Stock movements are INSERT-only. The balance row and its movements change in one transaction, and a ledger check proves balance = sum of movements for every key.History is never rewritten, and drift is detected rather than assumed away.ADR 0008 decision + 'Ledger check' (opens in a new tab)ADR 0008 — Stock reservations under contention: append-only ledger + transactional balance gate
A recovery preview records the version of everything it read. Applying it re-checks exactly those; if anything changed, it returns 409 and writes nothing.A reviewed decision is never applied to a state the reviewer did not see.Stale preview → 409, no partial write (opens in a new tab)Integration/StockPointRecoveryTest.php :: testAChangeOnAnAffectedKeyMakesThePreviewStaleWithNoPartialWrite

System architecture

StockPoint system architectureBrowser, then a React and TypeScript single-page app, then a Symfony modular monolith with the Retail module, then PostgreSQL: row-level security isolates every demo session. The backend calls an AI adapter: AI structures supplier price lists into draft products (every value quoted from the document) and drafts customer messages from calculated facts with a number guard; it never decides allocations, prices or stock.BrowserAnonymous demo session · guided scenarioReact + TypeScriptSingle-page app · Playwright end-to-end + axeJSON · RFC 9457 problem detailsSymfony modular monolithRetail modulestock ledger · allocation · pricing versionstransactions · constraintsPostgreSQLRow-level security isolates every demo sessionAI adapterJSON schema + semanticvalidation · fixture modeby default · no AI numbersDocker + Caddy on a shared 4-vCPU host · synthetic data only
AI structures supplier price lists into draft products (every value quoted from the document) and drafts customer messages from calculated facts with a number guard; it never decides allocations, prices or stock.

Key decisions

  • One conditional UPDATE on a balance row under READ COMMITTED, plus an INSERT-only movement ledger.

    Why: Each reservation costs the same however long the history, and contention on a hot item queues on one row instead of causing retry storms.

    Rejected: SERIALIZABLE with retries (retry storms), and a key lock with a ledger SUM on every reservation.

    ADR 0008

  • Store protection is a reservation policy, and inbound supply is not stock: back-orders are promised only against confirmed deliveries.

    Why: Store stock stays available for walk-in shoppers, and unknown supply never produces a promise date.

    Rejected: Counting inbound supply as stock (my first design, corrected after review).

    docs/specifications/013-stockpoint.md review history, §4, §13

Engineering evidence

  • Benchmark

    Contention test

    600 single-unit requests from 32 worker processes against 40 eligible units: exactly 40 committed and 560 refused in each of 20 runs, and the ledger matched every time. p95 latency 130 ms, because requests queue on one hot row by design.

    Conditions: Local Docker, 8 CPUs, PostgreSQL 19, measured 2026-11-23 (ADR 0008)

  • Benchmark

    Peak hour on production

    20,000 orders over 5,000 SKUs at 9 locations in 24.9 s: 804 orders/s, p50 4.0 ms, p95 12.0 ms, no deadlocks or lock timeouts, ledger consistent.

    Conditions: Production host: shared 4 vCPU, PostgreSQL 19, 4 worker processes

  • End-to-end

    Playwright Black Friday smoke with axe

    The whole Black Friday story with axe checks on four screens. 1/1 passing on production on 26 Nov 2026.

    Conditions: Desktop only (the trading floor is a desktop surface)

  • Engineering page

    “How it's engineered” in the live demo (opens in a new tab)

    The full detail: rules, data model, tests and measurements, next to the running product.

I use AI-assisted development for implementation, exploration and review. I remain responsible for architecture, business rules, code quality and deployment. Critical behaviour is verified with deterministic tests, static analysis and reproducible benchmarks.

Trade-offs and limits

  • Fictional retailer (Harbour & Home) and synthetic data
  • No storefront, checkout or payments; refunds are calculated, not paid
  • No real POS, ERP or warehouse integration
  • No carriers, forecasting or loyalty

My contribution

I built StockPoint as an independent engineering showcase: product specification, architecture, frontend, backend, data model, automated tests and deployment.

Want to discuss the engineering behind this?

Launch demo (opens in a new tab)Get in touch

Source-code walkthroughs available on request.