Interactive demo · synthetic dataEvery record on this page is fabricated.

What Counts As A Sale

One order-and-refund ledger, four documented mistakes, and the one written definition that reconciles with the storefront.

The production system behind this demo was engineered by Prada Dipa — LinkedIn profile, opens in a new tab and Luthfi Aditya — LinkedIn profile, opens in a new tab. I managed and directed it — requirements, technical review, QA and rollout.

Read about the system

THE WRITTEN DEFINITION

Four clauses. Each one has a documented alternative that is wrong in a specific way — switch any of them and watch the reconciliation below.

LINES COUNTED
REFUNDS BOOK ON
BUCKETED IN
CHANNEL FILTER

0 CLAUSES ALTERED

RECONCILIATION AGAINST THE STOREFRONT

The storefront publishes its own net sales figure. So does this computation. Where the two disagree, somebody is about to make a decision on a number that is not true.

Net sales per month under the current definition, beside the storefront’s own published figure.
MonthThis definitionStorefrontDelta
2026-01$6,810$6,8100
2026-02$7,190$7,1900
2026-03$5,660$5,6600
QUARTER$19,660$19,6600

Every month reconciles exactly. That agreement is the deliverable — the dashboard, the report runner and the storefront now answer the same question the same way.

FOUR ANSWERS FROM ONE LEDGER

Each of these is one clause changed and nothing else. All five read the same 24 orders and the same 11 refunds.

THE REFUND LEDGER

The returns desk clears its queue in a batch at 06:10 local time, which is 23:10 the previous day in UTC. Bucket in UTC and every one of these eleven refunds is dated a day early. Bucketed in UTC+07:00, none of them is.

Every refund, the order it belongs to, and the month the current definition books it into.
RefundOrderProcessedBooks intoon processed dateAmount
REF-2001merchandiseORD-10022026-02-05local2026-02$860
REF-2002merchandiseORD-10032026-01-21local2026-01$640
REF-2003merchandiseORD-10042026-02-01local2026-02$430
REF-2004merchandiseORD-10062026-02-11local2026-02$1,780
REF-2005shippingORD-10062026-02-11localnot counted$60
REF-2006merchandiseORD-1005wholesale2026-02-17local2026-02$6,400
REF-2007merchandiseORD-10102026-03-02local2026-03$1,220
REF-2008merchandiseORD-10132026-03-06local2026-03$1,120
REF-2009merchandiseORD-10142026-03-19local2026-03$780
REF-2010merchandiseORD-10172026-03-24local2026-03$1,390
REF-2011merchandiseORD-10182026-03-30local2026-03$560

WHAT THE LINE FILTER ADMITS

Every line billed on the quarter’s online orders. A storefront hands you all of them; only the first is a product sale.

  • Merchandise$28,440
  • Shipping$900
  • Tax$2,844
  • Duty$205
  • Tips$120
  • Gift cards$350

WHERE A CHANGE GOES

Every source is split the same three ways, with hard boundaries. The payoff is that no one has to decide where a change belongs.

The API changed
connector — raw I/O, pagination and auth, no business logic
A business rule changed
transform — pure; selects columns and coerces types, no I/O
Write semantics changed
loader — one transaction: upsert parents, delete and reinsert children

WHO CAN SEE THE NUMBER

A figure this contested is also a figure not everyone should have. Two rules, both server-side.

  • Every API route re-fetches the user row on each request rather than trusting the session cookie's claims — so a deactivation bites on the next call, not at the next login.
  • The external-partner role is scoped to traffic, marketing and reviews, and is refused sales figures outright.

STATIC ARCHITECTURE — NOT SIMULATED HERE

What is real, and what is simulated

Runs in your browser

  • The net-sales computation: merchandise lines only, orders on their creation timestamp, refunds on the timestamp they were processed, both bucketed into the storefront's trading timezone with the identical channel filter on each side
  • The four documented failure modes, each computed live over the same rows
  • The month-by-month reconciliation against the storefront's published figure

Rebuilt from the platform's written net-sales definition, not ported from the SQL. The storefront's three monthly figures are hand-written constants rather than a second call to the same function — a computation checked against itself proves nothing. 26 tests assert that the definition reproduces all three exactly and that each of the four mistakes fails to.

Simulated

  • All six external APIs — the storefront, the analytics property, the review platform and three ad platforms — plus Salesforce, the nightly staggered cron and the report runner's background jobs
  • PostgreSQL and the view itself. This is the definition rebuilt in TypeScript, because a database view cannot execute in a browser
  • The ledger — 24 orders and 11 refunds, all invented, for the fictional label MERIDIAN
  • The connector / transform / load decision table and the access model. Both are static architecture, stated rather than simulated, and labelled as such on the page