04 Apply and measure
Approve a price and compare observed sales, stock, and contribution with unchanged pricing.
Outcome
Approve your own price change. Watch subsequent synthetic sales and compare their observed revenue, units, remaining stock, and contribution with unchanged pricing.
Starting point
Complete Module 03. Keep the sales writer running.
How an approved price becomes sales
The forecast and the generated sales have different roles. ClickHouse SQL uses the prepared model's fitted coefficients to forecast price options. The sales generator uses a known synthetic response rule to produce transaction rows. It reuses the baseline demand captured at approval, but does not use the fitted coefficients to turn the recommended forecast into matching sales.
- Approve and commit. The workbench saves the chosen price and an approval receipt in Managed Postgres. For that store/SKU, the writer replaces its ordinary sales feed with paired applied-price and unchanged-price generation, avoiding duplicate primary sales.
- Calculate synthetic demand. The writer spreads the captured baseline demand across the remaining business time before expiry. For each batch, it applies the fixed response
(new price / old price)^−2. Reducing SGD 8 to SGD 6 gives approximately 1.78× expected demand, before stock limits. This is an assumption of the synthetic environment, not a learned fact about real shoppers. - Generate integer transactions. The writer samples a random nonnegative integer sales count around each expected mean (a Poisson distribution). Both paths use the same random input, then cap their counts by separate available stock. One possible batch could sell two units at SGD 6 and one at SGD 8; actual counts vary. Each sold unit becomes a transaction row carrying its price, branch, and receipt ID. Only applied sales reduce operational inventory.
- Ingest and aggregate. The writer inserts those rows into
pricing.retail_sales. The incremental materialized views update the minute aggregates, preservingsourceandbranch. ClickPipes delivers the operational batch and receipt evidence. - Query observed results. Chain queries use applied sales. The receipt-scoped
retail_outcome_seriesview reads the transaction rows and CDC evidence to calculate cumulative units, receipts, stock, waste, and contribution for both paths. The chart displays these recorded synthetic outcomes; they can differ from the earlier forecast.
This exercise demonstrates a controlled pricing feedback loop. Because the generator shares captured baseline inputs and uses a predefined response, its results are not an independent validation of production model accuracy. The model reference explains both components and their limits.
Actions
1. Approve the price yourself
- Return to the workbench and refresh your selected product's comparison.
- Select Review SGD … for your chosen price.
- Read the store, SKU, expected profit change, and current stock.
- Select Approve and apply price.
- Wait for the Price applied: SGD … confirmation beside your selection. It includes the Receipt ID and a View observed results button. Select that button to follow subsequent sales.
The server checks current inventory, price, policy, and model before it commits. If the evidence changed, refresh the comparison and review again.

In this example, Price applied: SGD 6.00 confirms the committed change. The table retains the comparison captured when the price was SGD 8.00. Its SGD 42.33 profit change is a projection until expiry; the next step measures subsequent sales.
2. Watch observed transactions
- Stop the continuing sales writer in its terminal with Ctrl+C and wait for its container to exit.
- Advance the next two hours of synthetic selling time:
.venv/bin/python -m app.loadgen.retail_writer --transactions-per-minute 10000 --minutes 120 --speed 20- Keep Observed results open. Watch the business-time boundary advance as completed batches reach ClickHouse. Compare the applied-price and unchanged-price curves.
- Open View observed sales data to inspect the underlying rows.
Read the early observation

Read the chart:
| Part | How to interpret it |
|---|---|
| Horizontal axis | Simulated business time in UTC, here 03:20–03:30. Each point represents a business minute. |
| Vertical axis | Cumulative sales receipts in SGD since approval. Read the price itself from the cards below. |
| Solid green: Applied price | Recorded synthetic sales using the approved SGD 6.50 price. This branch updates operational stock. |
| Dashed purple: Unchanged price | A simulated comparison that keeps the previous SGD 9.00 price, with its own stock balance. Exclude it from the workshop's chain-sales totals. |
A rising segment means additional receipts between those business minutes. A flat segment means no additional receipts in that interval. ClickHouse groups the receipt-linked transactions by minute and branch, then uses running sums to produce these cumulative curves.
Interpret this example: Each branch has sold one unit, so receipts are SGD 6.50 versus SGD 9.00, with 56 units remaining in each branch. At this early point, unchanged pricing has collected more revenue. The lower price needs enough additional sales to compensate for earning less per unit. Watch both units and contribution as more sales arrive; revenue alone does not determine profit. Your observation window and totals will differ.
The contribution cards deduct the purchase cost of all starting stock, plus selling costs and disposal costs when applicable. They can start negative because early sales have recovered only part of that purchase cost. Before expiry, the 56 unsold units are remaining stock; they become waste only at expiry.
Follow the same comparison later
The next screenshot follows the same receipt, Store 61 / SKU 102, later in business time. Additional sales at the applied price move the green revenue curve above the unchanged-price curve.

| Measure at this point | Applied SGD 6.50 | Unchanged SGD 9.00 |
|---|---|---|
| Units sold | 5 | 1 |
| Cumulative receipts | SGD 32.50 | SGD 9.00 |
| Remaining stock | 52 | 56 |
| Contribution | −SGD 225.00 | −SGD 247.70 |
Connect the two observations: Initially, one sale at SGD 9.00 earned more than one sale at SGD 6.50. Later, the lower-price branch has sold four additional units, collected SGD 23.50 more revenue, and improved contribution by SGD 22.70. The contribution improvement is smaller than the revenue increase because the additional sales also incur selling costs.
The comparison is still running. Both contribution values remain negative, and the remaining stock has not expired. Continue observing sales and compare waste and contribution again at expiry; these screenshots show an interim synthetic outcome.
Advance two business hours faster
A single product may sell only a few units per hour. --minutes 120 --speed 20 requests two hours of simulated sales in about six minutes of elapsed time: 120 ÷ 20 = 6. Each batch still has to complete, so delivery can take longer. The writer stops earlier if the trading day ends.
Follow Live business time (UTC) as new batches arrive. The diagram's times are an example: the writer resumes your current business clock and stock, without repeating Module 02's high-rate burst. The speed setting changes the simulation's pacing; measure ClickHouse query performance separately.
Two prices under the same simulated conditions
Think of two copies of the same product in the same store. Both start with the same stock and receive the same simulated demand conditions, including the same random draw for each batch. One copy uses the approved price; the other keeps the previous price. Those prices can produce different numbers of sales.
Only the applied-price branch changes operational inventory in Managed Postgres. The unchanged-price branch keeps a separate simulated stock balance. ClickHouse stores their generated transactions and compares the running totals. The five-versus-one counts illustrate the screenshot above; your counts change as sales arrive.
This controlled simulation illustrates price response. Production effects require their own evidence, and the observed integer sales can differ from the earlier weighted forecasts.
Record both branches' units, revenue, and contribution.
3. Query the observed series directly
Run this query in the SQL console without edits. It finds the current run and its latest approved price, then returns the recorded sales for both price branches.
WITH
(SELECT run_id FROM pricing.retail_analysis_context LIMIT 1) AS current_run,
(SELECT receipt_id FROM pricing.retail_receipts_cdc FINAL
WHERE run_id = current_run AND _peerdb_is_deleted = 0
ORDER BY acknowledged_at DESC, receipt_id DESC LIMIT 1) AS latest_receipt
SELECT current_run AS run_id, latest_receipt AS receipt_id,
minute, branch, price_minor / 100 AS price_sgd, units,
receipts_minor / 100 AS receipts_sgd, remaining_stock, waste_units,
contribution_minor / 100 AS contribution_sgd
FROM pricing.retail_outcome_series(
run=current_run, receipt=latest_receipt)
ORDER BY minute, branch LIMIT 1000;Check that receipt_id matches the receipt shown in Observed results, then compare the newest values with the chart. If you approved more than one price, open the latest approval in the workbench. If no rows appear, finish Approve and apply price and allow CDC to deliver the receipt before running the query again.
Use branch='applied' for chain KPIs; including the comparison branch would count simulated alternatives as extra business sales.
Verify
Explain the difference between a projected scenario and an observed event series. Why must the comparison branch be excluded from total chain revenue? How does the receipt ID connect an approved price to the observed sales in ClickHouse?