Workbench / The TiffinBox Build
S11 · V1·11
Release 0.1
Volume 1, chapter 11. The ten stages become one release. Orders are priced by the rules language when placed, and the price is stored in the log so it never changes; the kitchen moves orders through the lifecycle over HTTP, one change per order at a time; a replay tool prices every logged order under two rule files to show what a change would cost; and a daily report is rebuilt from the log. A single release-check script builds everything, runs 75 checks and tests, refuses a rules file with a dead rule, simulates a busy hour, kills the server with SIGKILL, restarts it, verifies every acknowledged order is back, replays, reports, and passes. Then the release is tagged.
Stage 11: release 0.1
The brief
What you'll build. The last pieces, and the evidence that they work together:
- pricing at placement:
POST /ordersevaluates the rules (stage 10) on the order's facts, including whether this is the customer's first order, and stores the customer and the price in the log (two new extension tags), so a placed order's price never changes when rules do; - kitchen events:
POST /orders/{id}/eventswithaccept 15,ready,handover,cancel <reason>orrefund-paid, applying stage 5's transition function, answering 409 when the lifecycle refuses, with one change per order at a time; GET /version, and anIdempotencyKeycheck without regex (stage 10's lesson);- a
tiffinboxcommand in the server jar:serve,simulate,replay(two rule files over the same logged orders) andreport(stage 7's columns rebuilt from the log); release-check.sh: one script from clean checkout to verified release;- release notes, and a
v0.1.0tag.
Why a real company needs this. A system is more than its parts working separately: the release is where pricing meets durability meets concurrency meets the rules that marketing edits. Companies that can say "this exact script ran, here is its output" before every release break production far less often than those relying on each component's tests. And "what will this rules change cost us?" is a question a business asks every week; answering it from real orders, before shipping, is the kind of capability that makes an engineering team trusted.
Why now. Chapter 11 is about finishing complete systems and proving them. Every earlier stage left something for here: stage 9's "kitchens updating orders" and "discounts on orders", stage 10's replay, stage 8's "reports rebuilt from the log".
What you'll have at the end.
- 4 new server tests (10 in total), core at 44, tbx at 21 checks;
- a passing
release-check.shtranscript; - the replay and report outputs on 2,001 simulated orders;
- ADR-0013 (prices are fixed at placement) and release notes for 0.1.0.
Theory to own
- Prices over time. A customer placed an order under November's rules; December's rules are now live. What should
GET /orders/o1show, and why must the answer not depend on which rules are loaded? (Stage 10's pure interpreter; chapter 05: functions.) - Read-decide-write. Two kitchen tablets send
readyfor the same order at the same moment. What must happen, and what goes wrong without a lock? (Chapter 08: race conditions; Companion to chapter 08, Gaps 1.) - "First order". Two orders from a brand-new customer arrive at the same moment. How many get the welcome discount, and how do you make it exactly one? (Chapter 08: critical sections.)
- What a replay can and can't tell you. A replay of the last day's orders says December's rules cost 2.1% of revenue. What does that number assume? (Chapter 05: sampling and independence.)
- Release evidence. What should a release check prove that the unit tests don't? (Chapter 11: "Tracking your progress"; Companion, Explain it differently 6.)
Build it
Step 1: price orders when they're placed, and remember the price
Add two extension tags to stage 6's format: TAG_CUSTOMER = 3 (the customer id, UTF-8) and TAG_PRICING = 4 (discountPaise;freeDelivery;rules), and an OrderLog.append overload that takes extra extensions. Recovery collects each order's first record's extensions. In the server:
- keep the rules in an
AtomicReference<List<Rule>>, as stage 9 does for the menu; - when placing an order, compute
first(no earlier order from this customer), buildFactsin IST, price withInterpreter.price, append the order with the key, customer and pricing, then publish; - on start-up, rebuild the set of customers with orders and every order's pricing from the recovered extensions;
- add
discountPaise,payablePaise,freeDeliveryandpricedByto the order JSON; - serialise placements per customer with striped
ReentrantLocks (64 stripes).
Checkpoint. With the rules "Welcome" (15% off a first order), "Big order" (₹100 off from ₹500) and free delivery from ₹300: a first order of ₹540 gets ₹100 off and free delivery; the same customer's next order of ₹89.50 gets nothing; another new customer's ₹89.50 gets ₹13.42 off.
Step 2: kitchen events, one order at a time
Add POST /orders/{id}/events. Parse the body into a stage 5 event at the current time (milliseconds), then, holding the order's stripe lock: read the order, apply Transition.apply, and either answer 409 with the reason, or append the new snapshot to the log, publish it, update the kitchen queue, and answer 200.
Checkpoint. ready before accept is 409 with "kitchen hasn't accepted the order"; the full path accept → ready → cancel → refund-paid ends in Cancelled; 20 concurrent ready requests on an accepted order produce exactly one 200 and nineteen 409s.
Step 3: tools for operators
Add Main with four commands, and make it the jar's main class:
serve DIR PORT RULES: parse the rules, run the analyzer, refuse to start if any rule is dead, open the log, start the server, close both on SIGTERM;simulate URL ORDERS SEED: place random orders through HTTP from 400 customers at 12 kitchens, retrying one in ten with the same key, and check every retry gets the original answer;replay DIR RULES_A RULES_B: scan the log read-only (OrderLog.scan), price each order once as it was placed, with "first order" reconstructed from the sequence, under both rule files, and summarise;report DIR: rebuild stage 7'sDayColumnsfrom the latest snapshots in the log, and print the top kitchens by revenue and the leader's top dishes.
Checkpoint. serve with a rules file containing stage 10's dead "Lunch combo" exits with status 65 and the analyzer's findings.
Step 4: the release check
Write release-check.sh at the repository root, with set -euo pipefail, that:
- builds and tests core, tbx and the server;
- shows the dead-rule refusal;
- starts the server on a fresh data directory with November's rules;
- places an order, retries it, sends
readytoo early, thenaccept, and reads the kitchen's next ticket; - simulates 2,000 orders, then kills the server with SIGKILL;
- restarts it, reads order o1, and retries o1's request after the crash;
- stops the server with SIGTERM;
- replays November against December's proposed rules;
- prints the report.
Checkpoint. The script ends with "release check passed" and exit status 0.
Step 5: what would December's rules cost?
Run replay on the release check's data with November's rules against December's proposal (free delivery from ₹400, a 12.5% breakfast deal on d2 or d4 everywhere, "Big order" unchanged, Welcome reduced to 10%).
Checkpoint. You can state the cost difference, which rules decided it, and one thing the replay can't tell you.
Step 6: the report, from the log
Run report on the same data.
Checkpoint. The report lists the top three kitchens by revenue and the leader's top dishes, built in milliseconds from the log alone.
Step 7: release notes and a tag
Write RELEASE-0.1.0.md (what it does, the contract, known limits), make the repository a Git repository if it isn't one, commit, and tag v0.1.0.
Checkpoint. git tag lists v0.1.0, and the notes' "known limits" match the "what breaks first" table below.
Senior and architect lens
1. A release is a claim, and the release check is its evidence. "Durable", "idempotent", "priced by rules" are claims; the script turns each into an observed fact on real processes, with a real crash. Keep the script in the repository, run it in CI on every merge, and paste its output into the release. A release without evidence is a hope.
2. ADR-0013: prices are fixed at placement. Write it with these points:
- Decision: an order's price (discount, free delivery and the deciding rules) is computed once, when it's placed, and stored in the log with the order; it never changes when rules change.
- Why: customers agree to a price; payments, refunds and accounting must reproduce it; replays and audits need it.
- Consequences: rules changes affect new orders only; refunds use the stored price; reports must read the stored price, not recompute it.
- Revisit when: price adjustments after placement are needed (a partial refund, a goodwill credit): model them as new events with their own amounts, never as a recomputation.
3. Concurrency boundaries follow business entities. Locks per order (kitchen events) and per customer (first-order discounts) map exactly onto the invariants they protect. A global lock would be simpler and slower; no lock would be fast and wrong. Naming the entity whose invariant needs protecting is how you choose the lock, and later the database transaction or the partition key (Volumes 3 and 5).
4. Configuration is code. The rules file changes what customers pay, so it's parsed, analysed, refused when wrong, replayed against history, and versioned. The same treatment applies to feature flags, pricing tables and routing rules in any company: anything that can change production behaviour deserves review, validation and a dry run.
5. Look back at the whole volume. Every stage left a decision record and a "what breaks first" table. Reading them in order is the best summary of what Volume 1 taught: start from a precise contract (stage 1), make illegal states unrepresentable (2), measure against naive alternatives (3, 4, 7), prove what can be proved (5), design formats to evolve (6), define durability exactly (8), treat every input as hostile (6, 9, 10), and release with evidence (11).
What breaks first, and when it's addressed:
| Pressure | What breaks | Where it's addressed |
|---|---|---|
| customers using a browser or phone | no frontend; no CORS, TLS or login | Volume 2 (the web frontend), Volume 3 (security) |
| a second server, a second city | one process owns the log and every map | Volume 3 (Spring Boot and a database), Volume 5 (distribution) |
| reports on payable amounts, months of history | columns read subtotals from in-memory snapshots | Volume 3 (SQL reports), Volume 4 (data warehouse) |
| idempotency keys and logs growing forever | no expiry, no compaction | Volume 3 (expiring keys, database storage) |
| rule files edited without a developer | rules are files in the repository | Volume 3 (rules stored, versioned and approved in the database) |
Evidence
- The build prints
tests: 44 passed(core),checks: 21 passed(tbx) andtests: 10 passed(server). release-check.shpasses from a clean checkout; its full output is attached to the release.- The README records the recovered-record count after SIGKILL, and explains why every acknowledged order is present.
- The replay output is in the README, with the note that breakfast rules weren't exercised and how you'd fix the sample.
- ADR-0013 and
RELEASE-0.1.0.mdare committed, andv0.1.0is tagged. - A one-page "Volume 1 retrospective" lists ADR-0001 to ADR-0013 with one sentence each on whether you'd decide the same way again.
Carry forward
- TiffinBox 0.1.0's HTTP contract (ADR-0011 plus the 0.1.0 additions) is what Volume 2's web frontend is built against, starting with menu search on every keystroke and order placement with an idempotency key.
- The release check grows with the system: Volume 2 adds browser tests, Volume 3 adds the Spring service and the database, and it stays the single command that says "this release is real".
- Fixed prices, per-entity locks and validated configuration are design rules that carry into Volume 3's transactional service.
- The reference repository is tagged
v0.1.0. Volume 2 starts from it.