Workbench / The TiffinBox Build
S56 · V3·55
Release 0.3.0, Checked at Every Door
Volume 3, chapter 55, the end of the volume. The chapter's eight projects each end with a definition of done; this stage turns the ones that apply to TiffinBox into a launch scorecard and runs it against the real server. Stage 55's server passed 8 of its 13 checks. Every access rule held at the API, but the web pages, the other door into the same orders, let anyone read any receipt, place orders as any customer and find out which customer numbers had ordered. Wrong methods were answered 404. With those fixed, the stage keeps the promises earlier stages made it: per-key locks (under a slow disk, p50 86 → 45 ms and twice the orders), versioned menu URLs caches keep forever, `tbx log repair`, faster mutation runs, waits on signals instead of sleeps, and the slow-disk drill in the release check. It re-points four promises to the volumes they belong in, and ships release 0.3.0.
Stage 56: release 0.3.0, checked at every door
The brief
What you'll build.
exp/56/launch.py: chapter 55's definitions of done that apply to TiffinBox, run against the jar with access enforced:- 1,000 concurrent placements;
- a retried key;
- an illegal transition;
- an oversized body;
- wrong methods;
- unusable tokens (none, expired, wrong audience,
alg: none, tampered); - who may read an order, through the API and through the receipt page;
- placing an order as someone else from the web form;
- the menu's caching;
SIGTERMduring a request.
Each check prints what it measured.
- The fixes it calls for:
- the router answers a known path with an unknown method with 405 and Allow, and HEAD like GET without the body;
- the review, checkout and receipt pages apply the API's access rules (Pages.denied), and their routes say so;
- a signed-in customer orders on the web as themselves.
- Per-key locks (Orders.KeyedLocks) in place of 64 shared stripes, measured by exp/56/stripes.py.
- Versioned menu URLs: GET /menu/v/{hash}.json, immutable. The kitchen page names the version and preloads it, and all three kitchen clients fetch it.
- tbx log repair FILE [--apply] and OrderLog.repair: what a repair would drop, and, when asked, the repair itself, keeping the original.
- exp/56/mutate.py: stage 55's mutation run, first against the tests that mention the mutated class (RunTests takes class names).
- Signals instead of sleeps in three tests.
- exp/56/drill.py: stage 53's slow-disk drill, now in the release check along with the scorecard.
- exp/56/promises.py: the promise ledger over every stage doc.
- Release 0.3.0: RELEASE-0.3.0.md, contract/released/0.3.0.json, release-0.3.out, the tag v0.3.0.
Why a real company needs this. A launch fails at the door nobody listed. Teams check what the design doc mentions, usually the API. Customers, and attackers, use every way in: the web form, the old endpoint, the admin page, the export. A definition of done written as checks and run against the real build is how "we tested it" becomes a list of what was tested. The doors missing from that list are the next thing to add.
Why now. Chapter 55 is Volume 3's projects. TiffinBox has built the parts of them that a plain-Java service can (see The eight projects, mapped). Stages 49 to 55 sent thirteen promises here.
What you'll have at the end.
- a launch scorecard in the release check, passing 15 of 15;
- one access rule at every door into an order;
- the stage promises kept or re-pointed, each with a reason;
- release 0.3.0;
- ADR-0058: what "done" means for a TiffinBox release.
Theory to own
- Definitions of done over doors. Why can every API check pass while the product is unsafe? (The chapter, "The working method"; Companion, Gaps 1 and Theory 1.)
- Lock scope. When must a lock be held across I/O, and what does sharing a lock between unrelated keys cost? (Companion, Gaps 2 and Theory 2.)
- Characterisation tests. What does a golden master assert, and when should it change? (Companion, Gaps 3 and Theory 3.)
- Budgets and ledgers. How do you stop a system, and a plan, from drifting by small steps? (Companion, Gaps 4 and 5, Theory 4.)
Build it
Step 1: the scorecard, on stage 55's server
Write exp/56/launch.py and run it against stage 55's jar.
Checkpoint. exp/56/launch-before.out: 8 of 13 checks pass.
Step 2: one rule, every door
Add Pages.denied. The review and checkout pages check sign-in before reading the form, then Access.placeOrder for the customer the form names. The receipt page applies Access.readOrder. A signed-out HTML GET is sent to /login, a signed-out form post gets a "sign in" page, and an order you may not see gets the same "not found" page as one that doesn't exist. Split the page routes by method, with access descriptions that say who may call them, and add the router's 405 and Allow. Add RoutesTest.everyRouteAnswersAWrongMethodWith405AndAllow.
Checkpoint. The server suite passes. The scorecard's five failures pass. exp/56/golden-diff.out shows three changed exchanges: DELETE /orders (404 → 405) and two pages. Re-record the golden master after reading each.
Step 3: locks per key
Write exp/56/stripes.py: 64 customers placing orders for 10 s, with --fault-fsync-delay at 0 and 20 ms. Run it against stage 55's locks, then replace the 64 stripes with KeyedLocks (a ReentrantLock per key, created when first needed and removed when its last user leaves) and run it again. Add OrdersTest.aKeysLockBlocksOnlyThatKeyAndIsForgottenWhenFree.
Checkpoint. exp/56/stripes-before.out, stripes-after.out, stripes-repeat.out.
Step 4: the menu by version, and HEAD
Add MenuVersion (the first 16 hex digits of the menu JSON's SHA-256), GET /menu/v/{hash}.json with Cache-Control: public, max-age=31536000, immutable (the last 8 versions kept), and data-menu on the kitchen page's ticket list. All three kitchen clients fetch that URL. Then write exp/56/methods.sh and run it.
Checkpoint. The performance budgets pass, and exp/56/methods-after.out shows HEAD answering 200 with no body.
Step 5: repair, selection, signals, the drill
- Repair. Write
OrderLog.repairandtbx log repair. It refuses--applywhile a server holds the directory's lock. Runexp/56/repair.sh. - Selection. Write
exp/56/mutate.pyand run it onAccess.javaandTokens.java. - Signals. Replace the sleeps in
ConcurrencyTest(the stream's first line follows the subscription),OrdersTest(wait for a write in progress) andServerTest(wait for both access lines). - The drill. Write
exp/56/drill.pyand add it and the scorecard torelease-check.sh.
Checkpoint. exp/56/repair.out, mutate.out, drill.out; core 58, server 91 and tbx 24 tests.
Step 6: the ledger and the release
Write exp/56/promises.py and run it over every stage doc. Fix what it finds, decide each promise to stage 56, then write RELEASE-0.3.0.md, copy the contract to contract/released/0.3.0.json, set VERSION to 0.3.0, run the release check into release-0.3.out, and tag.
The release check's time budgets failed on the way. The container had moved to a slower host, and stage 55's own code failed the plain view's all_cards_ms budget there too (medians 949 and 961 ms against 900). Preloading the menu helped a little. Medians of five runs instead of three made the other views stable. The plain view's budget is re-baselined to 1,000 ms in ADR-0059, with the previous release measured on the new host as the evidence (exp/56/perf-host.out).
The first release check of 0.3.0 failed too, on the golden master. Every page's footer and /version had changed from 0.3.0-dev to 0.3.0 (exp/56/release-0.3-first.out). That was the one intended difference, so it was re-recorded in its own commit.
Checkpoint. exp/56/promises-before.out, promises.out, perf-host.out; the release check passes (release-0.3.out); v0.3.0.
The eight projects, mapped
TiffinBox is plain Java on purpose, so it implements the parts of chapter 55's projects that don't need Spring, PostgreSQL, a broker or an identity provider. Each chapter's companion reads the Spring source for the rest.
| Project | In TiffinBox | Not here, and where it comes |
|---|---|---|
| 1 Order API in plain Java | the server (stages 9, 34–45, 49), the scorecard's P1 checks | |
| 2 Spring Boot and PostgreSQL | configuration, readiness and JSON bodies the Boot way (47–49); a log, not a database (50) | PostgreSQL: Volume 4 |
| 3 Sign-in and access control | tokens, sessions, the access matrix (51, 55); every door (56) | an identity provider and JWKS: Volume 10 |
| 4 Notifications through a broker | the outbox and the event stream (29, 52) | a broker, consumers, a DLQ: Volume 5 |
| 5 Payments that survive failure | idempotency keys (5, 11), deadlines and shedding (53) | a payment provider: not planned; the patterns are stage 53's |
| 6 A fast menu | ETags and shared caching (19, 46), versioned caches (54, 56), JFR (42) | Redis: Volume 4 (NoSQL stores) |
| 7 The test and build pipeline | reproducible jars (43), contracts (16, 46), mutation (55, 56), property tests (55) | CI: Volume 8 |
| 8 Production readiness | probes and drains (48), the drill (53, 56), access logs (45) | dashboards, alerts, traces: Volume 9 |
Senior and architect lens
1. List the doors before checking the locks. Every way to read or change an order (API, pages, stream, exports, admin tools) is a door. A security review starts with that list. TiffinBox's list is the route table, and RoutesTest makes a new route declare its rule. The declarations themselves are reviewed by the scorecard, which checks behaviour.
2. ADR-0058: what "done" means for a TiffinBox release. Write it with these points:
- The scorecard (
launch.py) and the drill run in the release check. A check that's no longer true is fixed, or removed with a reason, never skipped. - Every door: a new route declares its access, and the scorecard gains a check for any new way to reach orders.
- Characterisation: golden-master differences are read and re-recorded in the same commit as the change that caused them, with the reason in the message.
- Budgets don't move to make a change pass; the change makes room.
- Promises: the ledger runs before each release; every promise due is kept or re-pointed with a reason.
Also write ADR-0059, the time budgets after a host change: budgets are wall-clock times on an emulated slow CPU, so they move with the host. A re-baseline needs the previous release measured on the new host, and changes only the budgets that release fails.
3. Re-pointing is a decision, not a failure. Four promises moved to the volumes where they're cheapest to keep well. Writing down why, where a reader will look, is the difference between scope and drift.
What breaks first, and when it's addressed:
| Pressure | What breaks | Where it's addressed |
|---|---|---|
| the order history grows for months | memory and recovery time | Volume 4 (databases: the order history in PostgreSQL) |
| kitchens open and close | a code change for each one | Volume 4 (databases: kitchens as a table, with their menus) |
| two server instances | jobs run twice, streams see one instance's changes | Volume 5 (distributed systems: leases, a shared log with consumer offsets) |
| a customer signs in by pasting a token | no real sign-in for people | Volume 10 (security: an identity provider, passkeys) |
| the scorecard runs only before a release | a regression lives until then | Volume 8 (delivery: the scorecard in CI on every push) |
Evidence
exp/56/launch-before.out(8 of 13),launch-after.out(15 of 15),golden-diff.out,methods-stage55.out,methods-after.out.exp/56/stripes-before.out,stripes-after.out,stripes-repeat.out,repair.out,mutate.out,drill.out,promises-before.out,promises.out,perf-host.out.- Core 58, server 91 and tbx 24 tests;
golden master: 47 exchanges, identical; the release check passes, scorecard and drill included. RELEASE-0.3.0.md,release-0.3.out,contract/released/0.3.0.json; ADR-0058 and ADR-0059; the tagv0.3.0.
Carry forward
- Every door, one rule. New ways to reach an order join the route table and the scorecard.
- Locks per key, held only across what must be ordered.
- The ledger runs before every release, and so do the scorecard and the drill.
- Volume 4 starts from here: the order history, kitchens and menus move into PostgreSQL, and the log becomes what it was always closest to, a write-ahead log.