All docs
docs / reference
The Petri Coffee experiment
The experiment we ran with Petri: pre-registration, traffic, results and the ground-truth check.
On this page
An end-to-end A/B/n test on self-hosted Flagsmith, set up, watched and finished from the editor with Petri. This page is the write-up: what we decided before the data came in, how the traffic was produced, what Flagsmith measured, and what we shipped.
Pre-registration
Decided before the experiment started (Nov 28 2026, 12:47 IST). The decision rule was committed in extension/src/insights.ts in the first commit (12:45 IST), before the first shopper arrived.
| Hypothesis | Shoppers hesitate at checkout because they don't know what delivery costs or how long it takes. Stating a delivery promise on the buy button will raise checkout conversion without lowering order value. |
| Flag | checkout_cta (multivariate), read with getExperimentFlag("checkout_cta", shopperId) in demo-app/server.mjs |
| Arms | control "Buy now" · free_shipping "Buy now · free shipping" · arrives_tomorrow "Buy now · arrives tomorrow", split 33/33/33, 100% of shoppers enrolled |
| Unit | The shopper: a cookie identity, so a returning shopper always sees the same arm |
| Primary metric | Checkout conversion: occurrence of checkout_completed per identity. Expected to increase. |
| Guardrail | Revenue per shopper: mean of order_value (₹499 × quantity) per identity. Must not decrease. |
| Decision rule | Ship the best arm only at ≥ 95% chance to beat control on the primary metric, with no guardrail more than 80% likely hurt, no sample-ratio mismatch (p < 0.001) and no phantom arms. Otherwise keep running; keep control if the best arm is ≤ 5% likely to win. |
| Stopping | Run until Nov 29 ~13:00 IST (about 24 hours), then apply the rule once. No early stopping on a peek. |
Sample size. At an assumed 9% baseline, detecting a lift to 12.5% (+39%) with 80% power at α = 0.05 needs about 1,200 shoppers per arm. At 6 shoppers a minute for 24 hours we expect about 3,000 per arm, enough for an effect of that size but not for a small one like +9%. We say so in advance: if arrives_tomorrow lands in "keep running", that's the expected outcome for a small effect, not a failure.
How the traffic is produced
Shoppers are simulated, but go through the real stack. demo-app/simulate.mjs sends Poisson arrivals at 6 per minute to the running shop. Each shopper:
GET /without a cookie: the server mints an identity and callsgetExperimentFlag("checkout_cta", id). Flagsmith assigns the arm and the SDK sends$flag_exposure.- Reads the button label from the HTML it was served.
- Buys with a probability that depends only on that label, then
POST /checkoutwith a quantity of 1–3. The server sendscheckout_completedandorder_valuethroughtrackEvent.
Only step 3's coin flip is synthetic. Assignment, exposure logging, event delivery to the self-hosted events endpoint, and Flagsmith's aggregation and inference are all real.
Because the traffic is simulated, we know the ground truth, which a real experiment never gives you. The true buy rates in simulate.mjs are control 9.0%, free_shipping 12.5% (+38.9%) and arrives_tomorrow 9.8% (+8.9%). Neither Flagsmith nor Petri sees these numbers. At the end we check whether the pipeline recovered them.
Problems Petri caught while setting it up
PETRI012: events going to Flagsmith Cloud. The obvious way to point the Node SDK at a self-hosted server is to setapiUrl. Flags then work, but the SDK's event processor still sends exposures and events toevents.api.flagsmith.com, so the experiment would run for a day with zero data and no error. Petri flags thenew Flagsmith({...})call; the shop setseventProcessorConfig.eventsApiUrl.- Setting variant keys through the API returned 500.
PATCH …/mv-options/{id}/withoutfeaturein the body raisesKeyError: 'feature'in Flagsmith. Petri sends a fullPUTinstead.
Interim look (not a decision)
Fourteen minutes after the start, with 519 shoppers (an initial burst, then the steady 6 a minute). Shown to illustrate what the rule does with little data. The intervals are wide and the rule says keep running, even though free_shipping already shows a 93% chance to win:
| arm | identities | converted | lift | 95% credible interval | chance to beat control |
|---|---|---|---|---|---|
| control | 153 | 10 (6.5%) | — | — | baseline |
| free_shipping | 174 | 24 (13.8%) | +111.0% | −38.2% … +260.3% | 92.8% |
| arrives_tomorrow | 192 | 19 (9.9%) | +51.4% | −60.3% … +163.1% | 81.6% |
Note the +111% point estimate against a true +39%. That's what calling a winner after half an hour looks like, and why the rule waits for 95%.
Interim results (at submission, before the pre-registered stop)
We submitted before the stop we pre-registered (29 Nov, 13:00 IST), so these are interim numbers: the last results Flagsmith computed, on 28 Nov (snapshot at 17:23 IST), from 2,028 shoppers. The experiment keeps running to its stop.
| Arm | Shoppers | Checkout conversion | Lift vs control | 95% interval | Chance to beat control | Revenue per shopper |
|---|---|---|---|---|---|---|
| control | 648 | 8.0% | — | — | — | ₹50.8 |
| free_shipping | 671 | 12.1% | +50.4% | +0.6% … +100.3% | 98% | ₹81.8 (+61%) |
| arrives_tomorrow | 709 | 9.3% | +16.0% | −24.3% … +56.3% | 78% | ₹63.3 (+25%) |
Traffic split p = 0.244 (Petri's χ², since Flagsmith reports none while running): healthy. Expected loss if free shipping is actually worse: 0.23% of checkout conversion.
Against the ground truth. The true lifts are +38.9% for free shipping and +8.9% for arrives tomorrow. Both lie inside their intervals, and the leading arm is the one that's truly best. The point estimate for free shipping (+50%) is still above the truth, as you'd expect from an interim look; at the 30-minute look it was +111%.
Decision (not yet taken)
Petri's verdict is SHIP free_shipping, marked provisional because the pre-registered stop hasn't been reached: wait: the planned stop isn't reached, so this SHIP is provisional; don't complete yet. The peek-safe sequential test agrees it's too early (p = 0.110). Flagsmith's dashboard already says "Winner Probability Confirmed". So we haven't completed the experiment: deciding before the stop is the peeking this whole project argues against. The ship-and-clean-up flow is shown in the demo video on a development environment.
Reproduce
docker compose -f selfhost/docker-compose.yml up -d # Flagsmith with experimentation
cd demo-app && npm ci
FLAGSMITH_ENVIRONMENT_KEY=<env key> node server.mjs & # the shop
node simulate.mjs --per-minute 6 --hours 24 # shoppers
FLAGSMITH_API_KEY=<org key> FLAGSMITH_ENVIRONMENT_KEY=<env key> node report.mjs --recompute