Workbench / Volume 3 Companion: The Backend
V3·55
Backend Projects
Companion to Volume 3, chapter 55: how the working method, the eight projects, the ways they're proved and the evidence they leave connect. New angles: a building inspector who checks only the front door, a lift that waits for strangers, a photograph that keeps a stain, and a budget that rounds up. What the chapter simplifies, measured on TiffinBox's release in stage 56: a server that passed 8 of 13 definition-of-done checks, with every API access rule holding while the web pages let anyone read any receipt; a correct lock that halved throughput on a slow disk; a golden master that preserved a wrong 404 for twenty stages; a 0.1 KB budget failure; and nine forward references to the wrong volume. Also: the theory behind them, how Spring MVC decides between 404 and 405 (from its source), four debugging drills, interview questions with how to approach each.
Understanding it better
Concept map
Chapter 55 covers the working method (definitions of done first, the thinnest end-to-end slice, reproducing a failure before fixing it, measuring, a README per project) and eight projects that grow one backend: a plain-Java order API, Spring Boot with PostgreSQL, sign-in and access control, notifications through a broker, payments that survive failure, a fast menu, the test and build pipeline, and production readiness. It also covers how each project is proved (counts, matrices, kill tests, budgets) and how it becomes evidence (READMEs with measurements, mastery levels).
The links worth remembering:
- A definition of done is only as good as the doors it checks. "Customers see only their own orders" has to hold at every way to reach an order, not just the endpoint the checklist names.
- Correctness checks can hide performance coupling, and the reverse. 1,000 concurrent orders producing 1,000 unique ids says nothing about who waited for whom.
- Evidence is numbers you could be wrong about. A README's claims are convincing when they could have come out differently, and the repository shows how they were measured.
Explain it differently
1. A building inspector who checks only the front door. The lock is excellent and the report says "secure". The side entrance the caterers use has no lock at all. A security definition of done lists every entrance first, then checks each one (Gaps 1).
2. A lift that waits for strangers. Each car carries one family at a time, which is the rule. But if the building hands out cars by surname initial, the Iyers wait for the Ivanovs. Same rule, wrong grouping. Give each family its own car, and nobody waits for strangers (Gaps 2).
3. A photograph that keeps a stain. A golden master is a photograph of the system's answers, and it keeps everything, including the stain on the wall. When you clean the wall, the photograph no longer matches. That's the point: someone has to look and say "yes, that's the stain gone" (Gaps 3).
4. A budget that rounds up. Nobody notices one extra coffee. A monthly budget does. Small steps add up to drift, and only a check that fails on a small step stops it (Gaps 4 and 5).
Gaps and misconceptions
What the chapter oversimplifies
All outputs are real, from OpenJDK 21.0.12 and the build's stage 55 and 56 code (exp/56), unless stated.
1. A definition of done checks the doors you list. Stage 56 turned chapter 55's definitions of done into a scorecard (launch.py) and ran it against stage 55's server, access enforced. Stages 51 and 55 had tested the API's access rules thoroughly: a matrix of 37 rows, a mutation run that killed all 38 mutants. The API checks passed:
PASS P3 unusable tokens: no token 401, expired 401, wrong audience 401, alg none 401, tampered claims 401
PASS P3 who may read an order (API): its customer 200, another customer 404, its kitchen 200, another kitchen 404
FAIL P3 who may read a receipt (page): anonymous 200, another customer 200, its customer 200
FAIL P3 placing an order as someone else from the web form: anonymous checkout as c1 -> 303 /receipt/o1001
FAIL P3 whether a customer has ordered, from the review page: c500 (has ordered): 200, Welcome offered: False; a new number: 200, Welcome offered: True
The same orders could be reached through the HTML pages, and they asked nobody anything. Receipts were public with sequential ids. The checkout placed orders as any typed customer number. The review page showed whether a number had ever ordered, because only new customers were offered the Welcome discount. Stage 55's RoutesTest didn't catch it, because those routes were declared "public" and the test checks routes against their declarations. A rule over a set is only as good as the set's declarations, and a declaration needs checking against what the route actually does. In total, stage 55's server passed 8 of 13 checks. Stage 56's passes 15 of 15, including the two checks below.
2. A correct lock can be the wrong lock. "1,000 concurrent order creations produce exactly 1,000 orders with unique ids" passed on stage 55's server. But orders held one of 64 striped locks across the log's fsync, chosen by hashing the customer or order id, so unrelated customers sharing a stripe waited for each other's disk writes. Measured with 64 customers placing orders for 10 s, every fsync made 20 ms slower:
stripes fsync +20ms: 6875 orders in 10 s, p50 85.7 ms, p90 169.1 ms, p99 233.8 ms, max 556.6 ms
per key fsync +20ms: 13848 orders in 10 s, p50 44.5 ms, p90 52.9 ms, p99 83.2 ms, max 183.0 ms
The same rule (one write at a time per customer, and per order), with locks per key instead of per stripe, doubles throughput. On a fast disk the difference is inside the noise (33–36 thousand orders in 10 s before, 38–41 thousand after), which is why no test noticed. Correctness checks pass on contended code. Performance checks pass on fast hardware. Only a check that combines contention with a slow resource shows the coupling.
3. A golden master preserves bugs. Stage 35 recorded 47 HTTP exchanges as TiffinBox's golden master, including DELETE /orders, answered 404 not found. A known path with an unsupported method should be 405 with an Allow header, so a client can tell "wrong method" from "no such thing". When stage 56's router learned 405, the master failed (exp/56/golden-diff.out):
== DELETE /orders {}
-404
...
-not found
+405
+ allow: POST
...
+use POST
For twenty stages the master had protected the wrong answer, as it should: a golden master asserts that nothing changed, not that anything is right. The fix is to read each difference, decide it's intended, and re-record in the same commit. The 405 router then produced a new mistake. HEAD /menu.json was answered 405 Allow: GET, which tells clients the menu can't be HEADed (exp/56/methods-after.out now shows 200 with Content-Length: 500 and no body; stage 55 answered 404 with a 10-byte body). RFC 9110 requires GET and HEAD of every general-purpose server.
4. Budgets catch what review can't. The kitchen page now names its menu's version (/menu/v/8b29fbf2a16cf2a8.json, cached for a year as immutable). The first version read that URL in a shared helper with a doc comment, and the release check failed on the plain view's JavaScript budget:
E AssertionError: over budget (median, budget, runs): {"js_kb": [12.2, 12, [12.2, 12.2, 12.2]]}
The budget is 12 KB gzipped, and the view sat at 12.0. Nobody reviewing a five-line helper would object to 246 bytes, and that's the point: budgets exist for changes too small to argue about. The fix read the attribute inline and kept the shared module unchanged (12.0 again). Raising the budget would have been the drift the budget is there to stop.
5. Plans drift too. Each TiffinBox stage ends with "what breaks first, and when it's addressed", a list of promises. Stage 56's ledger (promises.py) read every one. Thirteen rows pointed at stage 56, and nine pointed at the wrong volume, written from an early outline and never checked:
stage 51: Volume 7 (cloud) but the subject is Volume 10 (security): Volume 7 (security: asymmetric keys, an identity provider, JWKS)
stage 54: Volume 6 (infrastructure) but the subject is Volume 5 (distributed systems): Volume 6 (distributed systems: versions that mean the same everywhere)
All nine are fixed. Of the stage 56 promises, eight were kept and four were re-pointed with reasons (stage 56's ledger table). "Re-pointed" isn't the same as "dropped". Kitchens as data belong in Volume 4's database, where a properties file written now would be replaced within weeks. A lease can't be tested with one instance, so it waits for Volume 5's second one.
Common misconceptions
| Misconception | What's actually true | Where it's shown |
|---|---|---|
| "The API's security tests pass, so access is enforced." | At the API. Every other door needs the same rule and its own check. | Gaps 1 |
| "It's correct under concurrency, so the locking is right." | Correct and fast are separate questions; a lock can be right in rule and wrong in grouping. | Gaps 2 |
| "The golden master passes, so behaviour is correct." | It's unchanged, which includes unchanged bugs. | Gaps 3 |
| "0.1 KB doesn't matter." | It doesn't, once. Budgets exist because it happens every week. | Gaps 4 |
| "Unfinished promises mean the project failed." | Re-pointing with a reason is scope; silence is drift. | Gaps 5 |
| "A project's README should list the technologies." | It should give measurements and reproduced failures. | The chapter, "Portfolio checklist" |
Theoretical gaps: the ideas behind the chapter
1. Definitions of done over interfaces. A requirement like "customers see only their own orders" is a property of the system, so it has to hold at every interface that reaches orders: API, pages, streams, exports, admin tools, background jobs that send emails. Checking it means first enumerating the interfaces (in TiffinBox, the route table, the stream and the pages), then checking the property at each. A requirement checked at one interface is a claim about that interface only.
2. Lock scope and lock grouping. A lock enforces an order between operations that must be ordered. Holding it across I/O is right when that order is the rule (here, a customer's orders, and an order's events, in storage order). It is expensive only when unrelated operations share it. Striping (a fixed array of locks chosen by hash) bounds memory but makes collisions certain: with 64 keys in 64 stripes, about 23 stripes are empty on average, so many keys share. Per-key locks need cleanup (a reference count, removed when it reaches zero) but group exactly. The general rule is the one chapter 38 applies to shared state: lock what must be ordered, nothing more.
3. Characterisation tests. A golden master, snapshot or approval test records current behaviour and fails on any change. It's ideal for refactoring and for code nobody fully understands (Michael Feathers' term is "characterisation test"). It's useless for deciding correctness, so every difference needs a human verdict. Make differences readable: normalised output (stage 35 strips dates and ids), one exchange per block, and a re-record step in the same commit as the change.
4. Ratchets. Budgets, ledgers and scorecards are ratchets: they let a system improve freely and make it get worse only on purpose. A ratchet works when it's automatic (in the release check), precise (12.0 KB, not "small"), and when the response to a failure is a change in the work, not in the limit, unless someone writes down why.
Applying it
Code walkthrough
Gaps 3's router fix, and how Spring MVC decides it. From spring-projects/spring-framework, main at commit 7ce40c8 (18 November 2026).
404 or 405: partial matches
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java. When no mapping matches the request fully, Spring looks again at the mappings whose URL matched:
@Override
protected @Nullable HandlerMethod handleNoMatch(
Set<RequestMappingInfo> infos, String lookupPath, HttpServletRequest request) throws ServletException {
if (CollectionUtils.isEmpty(infos)) {
return null;
}
PartialMatchHelper helper = new PartialMatchHelper(infos, request);
if (helper.isEmpty()) {
return null;
}
if (helper.hasMethodsMismatch()) {
Set<String> methods = helper.getAllowedMethods();
if (HttpMethod.OPTIONS.matches(request.getMethod())) {
Set<MediaType> patchMediaTypes = helper.getConsumablePatchMediaTypes();
Set<MediaType> queryMediaTypes = helper.getConsumableQueryMediaTypes();
HttpOptionsHandler handler = new HttpOptionsHandler(methods, patchMediaTypes, queryMediaTypes);
return new HandlerMethod(handler, HTTP_OPTIONS_HANDLE_METHOD);
}
...
throw new HttpRequestMethodNotSupportedException(request.getMethod(), methods);
}
if (helper.hasConsumesMismatch()) {
...
PartialMatchHelper keeps the mappings whose path pattern matched (getActivePatternsCondition().getMatchingCondition(request) != null). null (no partial match) becomes 404. A partial match that failed only on method becomes HttpRequestMethodNotSupportedException with the union of declared methods:
public Set<String> getAllowedMethods() {
Set<String> result = new LinkedHashSet<>();
for (PartialMatch match : this.partialMatches) {
for (RequestMethod method : match.getInfo().getMethodsCondition().getMethods()) {
result.add(method.name());
}
}
return result;
}
And the exception carries its own header, in spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java:
@Override
public HttpHeaders getHeaders() {
if (ObjectUtils.isEmpty(this.supportedMethods)) {
return HttpHeaders.EMPTY;
}
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.ALLOW, StringUtils.arrayToDelimitedString(this.supportedMethods, ", "));
return headers;
}
Note the order of the checks: method first, then Content-Type (415), then Accept (406), then parameters (400). Each check considers only the mappings that passed the previous one, so the status names the first condition that failed. TiffinBox's router now does the first step the same way: collect the methods of routes whose pattern matched, 405 with Allow if any, otherwise 404. OPTIONS is the case Spring answers itself (200 with Allow) and TiffinBox doesn't.
Debugging drills
D1. The penetration test that read receipts
An external test reports that customer receipts can be read by anyone. Your team's access tests all pass, and they cover every API endpoint.
D2. Slow only on the busy store's disk
Order latency doubled at one site after its storage was moved to network disks. Load is normal and there are no errors. CPU is idle.
D3. A bug fix that fails the build
A developer fixes an endpoint that returned 404 for a wrong method. The golden-master test fails, and a reviewer asks them to revert "because it breaks compatibility".
D4. Twelve point one
A small feature fails the release check on a JavaScript budget by 0.1 KB. The developer proposes raising the budget to 12.5 KB.
Career-oriented
Interview prep
Mid-level 1: 404 or 405
Question. "A client sends DELETE /orders and your API only supports POST there. What should it return, and why does it matter?"
How to get there. What can the client do with each answer?
Mid-level 2: a definition of done
Question. "You're asked to add 'customers can download a PDF of their receipt'. What's your definition of done?"
How to get there. What could go wrong that a demo wouldn't show?
Senior 1: the same rule at every door
Question. "How do you make sure every way into your system enforces the same authorisation?"
How to get there. Inventory, then enforcement, then a check that the inventory stays complete.
Senior 2: a lock across I/O
Question. "A reviewer says 'never hold a lock across I/O'. Is that right?"
How to get there. What is the lock protecting?
Staff 1: what to cut from a launch
Question. "Two weeks before launch, the plan has fourteen items left. How do you decide what ships?"
How to get there. Separate what makes the launch safe from what makes it better.
Staff 2: promises that rot
Question. "Design docs across your organisation say 'we'll handle this in phase 2'. How do you keep those promises from rotting?"
How to get there. Make promises data.