The Data Foundry

← All practice

Free · Guided project · SQLite · Intermediate

Replay the order feed without changing revenue

Build three linked SQL stages, test replay and late cancellations, and practise protecting the last good report in a browser simulation.

Original fictional data, eight valid and four rejected public examples. Runs on this device; no sign-in, paid service, real warehouse, scheduler or cloud progress. Supplied-case matches are guided feedback, not independent mastery.

Task and business rules

Prerequisites: SELECT, CTE, GROUP BY, event versus order grain, and ROW_NUMBER or an anti-join. Amounts are integer cents in one fictional currency.

  1. delivery_id is a physical receipt; event_id is an immutable business event; order_id is an order. Replays can change receipt ID/time, never business payload.
  2. Each positive source_version is the full replacement order state, not a delta. Greatest version wins even if old data arrives last; gaps are allowed. Do not choose by receipt or event timestamp.
  3. One event per order/version. Different payload for the same event, a second event for an order/version, or a changed original order_date rejects the source before SQL.
  4. Latest paid state contributes its amount and one eligible order. Cancelled contributes zero cents and zero eligible orders on the original order date. Retain a 0/0 row for an all-cancelled date.
  5. Return the exact stage headers in order. Nonempty output requires text/safe integer types and exact row multiplicity; row order is irrelevant. No rounding or text-to-number coercion. Empty checks establish zero rows only.
  6. No tax, FX, partial refund, line item or delete semantics. Reconcile eligible latest-order cents and counts, never raw receipt amounts across replays or versions.

Complete input and expected outputs

Two paid orders on Jan 1. Selecting a snapshot retains all three queries and the last published report; rerun previews on the new input.

delivery_id TEXT, event_id TEXT, order_id TEXT, source_version INTEGER, order_date TEXT, event_time TEXT, received_at TEXT, status TEXT, amount_cents INTEGER. IDs are nonblank; dates must be real YYYY-MM-DD, timestamps real UTC YYYY-MM-DDTHH:MM:SSZ, status paid/cancelled, version positive and cents nonnegative safe integers.

Raw input — 2 physical deliveries

delivery_idevent_idorder_idsource_versionorder_dateevent_timereceived_atstatusamount_cents
D01E01O112026-01-012026-01-01T09:00:00Z2026-01-01T09:00:05Zpaid10000
D02E02O212026-01-012026-01-01T10:00:00Z2026-01-01T10:00:05Zpaid20000

Expected accepted_events — disclosed expected rows, not a worked query

event_idorder_idsource_versionorder_dateevent_timestatusamount_cents
E01O112026-01-012026-01-01T09:00:00Zpaid10000
E02O212026-01-012026-01-01T10:00:00Zpaid20000

Expected current_orders — disclosed expected rows, not a worked query

order_idsource_versionorder_datestatusamount_cents
O112026-01-01paid10000
O212026-01-01paid20000

Expected daily_revenue — disclosed expected rows, not a worked query

order_daterevenue_centseligible_order_count
2026-01-01300002

Stage 1 — accepted events

Read raw_deliveries. Keep each immutable business event once, despite new delivery IDs and receipt times.

Stage 2 — current orders

Read your materialized accepted_events output. Keep the greatest source_version for every order; each version is a full replacement state.

Blocked: match the previous stage on this input first. A wrong or missing upstream output cannot advance.

Stage 3 — daily revenue

Read your materialized current_orders output. Sum paid current states by original order_date, keeping 0/0 dates where all orders are cancelled.

Blocked: match the previous stage on this input first. A wrong or missing upstream output cannot advance.

15-second engine-load / 3-second query budget · 20,000 SQL characters · 500 output rows / 32 columns / 64,000 output bytes · SQLite allocations limited to16MiB. Cancel terminates the worker. These small local limits are not a cloud capacity guarantee.

Run Stage 1, then use its actual output in Stage 2 and Stage 3. Previews are unpublished.

Publish a simulated report

Previews never publish automatically. Match all three stages on the same current input and query revisions, then deliberately publish. Changing input or a query invalidates affected previews and publication eligibility; it keeps the last good report.

The named failure happens before publication: retry Stage 3, then publish explicitly. Wrong SQL, rejected input, engine error, timeout, Cancel or stale replies also cannot replace the last good report/run ID.

Last successfully published report

No report published yet. Running a preview does not create one.

This report is in memory until you explicitly save on this device. Saved history is not independently verified, account-synced or a production transaction.

Help and production consequences

Hints and per-stage worked queries are optional; complete input and expected rows are available before Run.

    At-least-once receipts plus a deterministic SELECT do not prove exactly-once writes. Immutable events support replay/audit at storage cost; latest-state tables speed reads but lose event history. Full recomputation suits small teaching data, while large real pipelines require bounded keyed updates, transactional publication, monitoring and rollback. Unknown source-version authority is escalation, not a guessed timestamp winner.

    Device-only drafts and recovery

    Three separate queries, source selection, assistance state and last published snapshot. No cloud/account persistence.

    Loading this device's saved copy…