Workbench / Volume 3 Exercises: The Backend
V3·55
Backend Projects
Exercises for Volume 3, chapter 55: checkpoints for the eight backend projects that grow one tiffin-centre ordering service (the order API in plain Java, the Spring Boot service with PostgreSQL, sign-in and access control, notifications through a message broker, payments that survive failure, a fast menu with caching and profiling, the test and build pipeline, and production readiness), plus the working method and portfolio. 9 theory questions, 9 programming checkpoints, 3 integration projects, the practices the chapter leaves out, and 5 senior-level exercises.
Start here: how this chapter's exercises work
This chapter is projects, so its exercises work differently, as in Volume 1's and Volume 2's projects chapters. They don't ask you to build the eight projects again. They're checkpoints: each one checks that you understood a project's hard part before you build it (theory) and while you build it (programming).
- Theory (one per project, plus the working method): the decisions and failure modes each project exists to teach, tied back to the chapters that cover them.
- Programming checkpoints: a small, self-contained piece of each project, often its test harness or its trickiest part, with real output. Most outputs are measurements this volume's labs and exercises already made, and each one names its source. Three were run for this chapter on JDK 21 and PostgreSQL 16: project 1's concurrency, body-limit and shutdown checks, project 2's 100,000-row import, and project 7's reproducible build. If your checkpoint passes, the project's foundation is sound.
- Integration projects join several projects into one system. They're the cumulative set for this chapter, and draw on all of Volume 3's chapters 33–54, plus Volumes 1 and 2.
Senior exercises are about reviewing, scoping, presenting and defending the work.
Two of this chapter's own measurements are worth knowing before you start:
- P1. 1,000 concurrent
POST /v1/ordersrequests throughHttpServergave 1,000 distinct ids even with a thread-unsafe repository. Calling the same repository directly from 8 threads lost up to 408 of 80,000 orders. A load test through HTTP can be too slow to expose a race. - P7. Two builds of the same source produced different JAR hashes (
6fe73d48…againsteb78fb0e…) because of file timestamps. Withjar --date=2026-01-01T00:00:00Z, both were75cf0b08….
Coverage map.
| Chapter component | Theory | Checkpoint |
|---|---|---|
| the working method; definitions of done | T1 | P9 |
| Project 1: the order API in plain Java | T2 | P1 |
| Project 2: the Spring Boot service with PostgreSQL | T3 | P2 |
| Project 3: sign-in and access control | T4 | P3 |
| Project 4: notifications through a message broker | T5 | P4 |
| Project 5: payments that survive failure | T6 | P5 |
| Project 6: a fast menu: caching and profiling | T7 | P6 |
| Project 7: the test and build pipeline | T8 | P7 |
| Project 8: production readiness | T9 | P8 |
| portfolio checklist and mastery levels | T1 | P9, S5 |
Theory
T1. The working method and definitions of done
- The chapter's method:
- write the definition of done first;
- build the thinnest end-to-end slice;
- reproduce the failure before fixing it;
- measure with the labs' tools;
- write a README per project.
For each step, name the backend failure it prevents (gold-plated half-finished services, integration surprises late, fixes that don't fix, opinions instead of numbers, invisible work). 2. Rewrite these vague goals as measurable checks with the method of measurement: - "the API is fast"; - "orders are never lost"; - "it's secure"; - "payments are reliable"; - "the tests are good". 3. The chapter maps projects to mastery: projects 1–3 with their checks give L2; stretch goals and explaining every measurement give L3–L4; defending the design decisions in projects 4–8 gives L5. What's the difference between doing a project and being able to defend it, in backend terms?
T2. Project 1: the order API in plain Java
- Why build the first version with only the JDK (
HttpServer, records, virtual threads)? Name four things you'll later get from Spring (routing, binding and validation, problem details, lifecycle, configuration, observability), and what you learn by writing them yourself. - The definition of done includes "1,000 concurrent order creations produce exactly 1,000 orders with unique ids". P1 found that a thread-unsafe repository passed that check through HTTP (1,000 of 1,000) and failed when called directly from 8 threads (79,592 of 80,000 stored in the worst run). Why can an end-to-end load test miss a race, and what should the check be?
- The other checks: illegal state transitions give 409; bodies over 10 KB are refused (P1: 413 with a problem body);
kill -TERMduring a 2 s request still completes it (P1: the in-flight request finished after 2,014 ms, and new connections were refused). Explain what each protects against in production.
T3. Project 2: the Spring Boot service with PostgreSQL
- The rebuild must keep project 1's API contract so its curl script passes unchanged. Why is that the right first check for a framework migration, and what usually breaks (trailing slashes, ch48's P1; error formats; JSON naming; date formats)?
- The definition of done asks for:
- a fixed number of SQL statements per page regardless of size (ch49's lab: N+1 gave 201 queries against 1);
- one transaction for a 5-line order that leaves nothing on failure;
- one success and one 412 for two concurrent edits;
- importing 100,000 historical orders in under 10 s;
-
open-in-viewoff.
For each, name the chapter technique and the failure it prevents.
3. JPA or JdbcClient for the hottest query? What would make you choose each, and how do you justify it in the README?
T4. Project 3: sign-in and access control
- Walk through the flow: Keycloak realm with roles; a public client with the authorisation code flow and PKCE (ch50's P2); the service as a resource server validating issuer, audience, expiry and the signature from the JWKS; deny-by-default filter chains; role rules and ownership rules; a BFF or session cookies for the Volume 2 frontend; CORS restricted to the frontend's origin. Which of these is most often missing in real services, and why?
- The definition of done tests every endpoint with six kinds of token and asserts exact 401, 403 and 200 results. Why are 401 and 403 different, and why should a customer requesting another customer's order get 404 (or 403: decide and document)? What does ch50's P3 add to the token list (an HS256 token signed with the public key, accepted by a naive verifier)?
- Where should each check live (T1 of ch50): the filter chain, method security, the application service, the database? Why must the ownership rule live in the application layer?
T5. Project 4: notifications through a message broker
- The design: an outbox table in the order transaction, a relay to Kafka or RabbitMQ, three idempotent consumers in separate processes, retries with backoff and a dead-letter topic, ordering per order id, and lag and DLQ metrics. For each piece, name the failure from ch51 it prevents (the lab's dual write, double SMS, poison loop, P5's 309 out-of-order events).
- The definition of done kills processes randomly during 1,000 orders, then counts lost events and duplicate SMS. Why must the test kill processes rather than stop them gracefully, and what does the reconciliation count compare?
- "Order latency is unchanged when the SMS provider is down." Explain how the outbox achieves that, and what changes for the user (the SMS arrives late, after recovery).
T6. Project 5: payments that survive failure
- The design: timeouts; idempotency keys stored with each attempt; retries only for transient failures, at one layer, with jitter; a circuit breaker with a "pay at counter" fallback; a bulkhead (
@ConcurrencyLimit); a reconciliation job for payments stuck in pending; a load test against a misbehaving stub. Which one piece, if missing, causes double charges? Which causes outages? - ch52's P2 showed
@Retryableon a charge whose response timed out making the provider charge 3 times. Explain why "the provider timed out" means "unknown outcome", and why the idempotency key must be created once per user intent and stored before the first attempt. - "When the provider is fully down, checkout responds within 1 s with the fallback, and the menu's p99 is unaffected." Which pieces deliver each half (the breaker and deadline for the first; the bulkhead for the second)? Use ch52's measurements.
T7. Project 6: a fast menu: caching and profiling
- The order of work: a baseline load test, a profile under load, then HTTP caching, Redis cache-aside, stampede protection, and an in-process cache with cross-instance invalidation, with JMH for hot code. Why profile before caching, and what might the profile show that caching wouldn't fix (serialisation cost, N+1, a slow regex, GC: ch41)?
- The definition of done: - ≥ 5× baseline throughput with p99 < 50 ms; - menu edits visible within the staleness budget; - expiring the hottest key during load causes one database query, not hundreds; - the service still works with Redis stopped.
Map each to ch53's techniques and measurements. 3. What's the staleness budget for the menu, who decides it, and how does it constrain each cache layer's TTL (ch53's C1: CDN 30 s, local 10 s, Redis 60 s)?
T8. Project 7: the test and build pipeline
- The pipeline's parts:
- a Gradle or Maven build with the wrapper,
--release, a BOM or version catalog, and dependency locking (ch42–43); - unit tests with properties for money; - Testcontainers repository tests and API tests; - WireMock stubs; - contract tests; - ArchUnit rules; - PIT on pricing and order state; - CI with a build cache, a reproducible image and an SBOM.
For each, name the risk it controls.
2. "Two clean builds of the same commit produce byte-identical JARs." P7 showed two builds giving different hashes (6fe73d48… against eb78fb0e…) and identical ones with jar --date (75cf0b08… twice). Why does reproducibility matter (supply-chain verification, caching, debugging "which build is running?"), and what else must be pinned (Gradle's preserveFileTimestamps = false and reproducibleFileOrder = true, the JDK version, dependency locks)?
3. "At most three application contexts" and "zero flaky tests in 20 consecutive runs". Which ch54 measurements explain why these are the right targets?
T9. Project 8: production readiness
- The pieces:
- liveness and readiness groups wired to probes;
- graceful shutdown with a readiness flip and a drain shorter than the platform's kill timeout;
- structured logs, RED metrics, saturation metrics, breaker state and consumer lag;
- traces across the service, broker and database;
- a runbook for the five likeliest incidents;
- startup tuning;
- a JDK 21 → 25 upgrade with
jdepsand a staged rollout.
Which ones does the on-call engineer use in the first five minutes of an incident?
2. "A rolling restart under steady load produces zero failed requests." Walk through the shutdown sequence (SIGTERM, readiness to OUT_OF_SERVICE, load balancer removal delay, stop accepting, drain in-flight requests, stop consumers and schedulers, close pools) and what goes wrong if the drain exceeds the kill timeout. P1's checkpoint showed the plain-Java version of the drain (a 2 s request completed after stop(5)).
3. "One simulated incident is diagnosed from telemetry alone by someone who didn't build the service." Why is that the real test of observability, and what must the runbook contain for "the database is slow", "the payment provider is down" and "the broker is full"?
Programming checkpoints
P1. Project 1: the concurrency, size-limit and shutdown harness
Build the checks for project 1's definition of done, against the JDK HttpServer:
1. 1,000 concurrent POST /v1/orders requests, counting 201s, distinct Location ids and stored orders, with a deliberately unsafe repository and a safe one;
2. the same repositories called directly from 8 threads × 10,000 creates with a start latch;
3. a 20 KB body refused with 413 and a problem body;
4. a graceful stop while a 2 s request is in flight.
P2. Project 2: the statement-count test, the conflict test and the import
Write the checks for project 2: 1. a statement-count test for the menu and order history (N+1 against fetch plans); 2. a concurrent-edit test giving one success and one 412; 3. a rollback test for a 5-line order with an invalid line; 4. importing 100,000 historical orders and timing it.
P3. Project 3: the token and ownership matrix
Build the access-control suite:
- every endpoint × {no token, expired, wrong audience, alg: none, HS256 signed with the public key, tampered payload, customer, staff, admin};
- the ownership case (a customer reading another's order);
- CORS from an allowed and a disallowed origin;
- CSRF on the BFF's cookie-authenticated writes.
Assert exact status codes.
P4. Project 4: the kill-at-random reconciliation
Write the chaos script and reconciliation for project 4:
1. place 1,000 orders while a loop kills the relay or a random consumer every few seconds (kill -9) and restarts it;
2. afterwards, compare committed orders with published events and with the SMS stub's ledger;
3. check per-order event ordering at the kitchen consumer;
4. send one poison message and check it reaches the DLQ after bounded attempts while others flow.
P5. Project 5: the misbehaving payment stub and the ledger check
Build a payment stub that can be slow, fail, time out after charging, or succeed after a delay, controlled per request or by percentages. Then: 1. run a load test with 20% timeouts-after-charge; 2. check the stub's ledger for double charges and the orders table for "paid without a charge"; 3. take the provider fully down and measure checkout's response time and the menu's p99; 4. watch the breaker's state metric through recovery.
P6. Project 6: the expiry-under-load and Redis-down checks
Write the caching checks: 1. a baseline and a final load test of the menu (throughput and p99); 2. during load, expire the hottest key and count database queries in the next second; 3. edit a menu item and measure the time until customers see it; 4. stop Redis during load and check the service keeps serving.
P7. Project 7: the reproducible build and the suite's health checks
Check: 1. two clean builds of the same commit produce byte-identical JARs (with and without fixed timestamps); 2. the Spring test suite's context count; 3. 20 consecutive CI runs with zero flaky failures (with random method order and the seed logged); 4. the mutation score on pricing with every surviving mutant explained.
P8. Project 8: the rolling-restart and runbook drill
Check:
1. a rolling restart under steady load gives zero failed requests (a load generator counting non-2xx and connection errors);
2. the shutdown order (readiness flip, delay, stop accepting, drain, consumers, pools) from the logs;
3. a simulated incident (the database slowed with pg_sleep in a trigger, or Toxiproxy latency) detected by an alert and diagnosed from telemetry by someone else, timed.
P9. A project README that's worth reading
Write the README template for the backend projects, then fill it for one project with real measurements: - the goal; - an architecture diagram (one image); - decisions with alternatives; - the definition of done as a table (check, target, result, how measured); - reproduced failures and their fixes; - limitations and next steps.
Then rewrite the unbacked claims ("blazing fast", "highly available", "secure", "scalable", "battle-tested").
Integration projects (chapters so far: Volume 1, Volume 2, and Volume 3's 33–54)
C1. The whole product, end to end
Join Volume 2's frontend projects with this volume's backend projects into one product: - the PWA and SSR storefront (Volume 2) talking to the order service through the BFF (project 3); - live order tracking over SSE from the order service (ch48), fed by events (project 4); - payments with the misbehaving stub (project 5); - the cached menu (project 6); - one pipeline building, testing and deploying both (project 7, Volume 2's project 8); - production readiness across both (project 8).
Define one end-to-end definition of done and run it.
Combines: every chapter of Volumes 2 and 3.
C2. Rebuild one backend project in a second stack and compare
Rebuild project 1 or project 4 in Go (net/http, database/sql or sqlc, a Kafka client) or Node (Fastify, Prisma, BullMQ). Keep the same API contract and definition of done, and compare:
- code size;
- startup time and memory (ch40's method);
- p99 under the same load;
- how each stack handles the concurrency, idempotency and shutdown checks;
- what each made easy or hard.
Combines: Volume 1's languages, ch38's concurrency models, ch40–41's measurement, ch51's messaging, and this chapter.
C3. A one-week hardening sprint on the finished backend
Plan and run a one-week hardening sprint on the finished service: - day 1: threat model and security review (ch50's C3); - day 2: a game day with five faults (ch52's C2); - day 3: load and soak tests (ch41, ch54); - day 4: a caching and database review (ch53's C3, ch49's S5); - day 5: fix the top findings and update the runbook and READMEs.
Report the findings with severity and the fixes made.
Combines: ch41's measurement, ch47's operations, ch49–54's reviews, and this chapter.
What the chapter leaves out
Working with product and other teams
Real backends are shaped by product decisions (the discount cliff in ch54's P4 is a product question), by the frontend team's needs (contract tests are a conversation, not just a tool), and by operations (who's on call). Practise writing an ADR that a product manager can read, and running an API review with consumers before building.
Choosing scope and finishing
Eight projects is a lot. Finishing three with their definitions of done met, measured and written up beats starting eight. Cut stretch goals first, then whole projects, but keep the measurements and the reproduced failures, because they're what make the work credible.
Code review and collaboration practice
Ask someone to review each project's pull requests using this volume's review exercises (the S2 exercises in each chapter), and review someone else's. Reviewing teaches you to see the failure modes in others' code, and then in your own.
Interview preparation from projects
System design interviews ask for designs like these projects (ordering, payments, notifications). Practise explaining one project in 5 minutes (S5), and be ready for "what happens when…" questions about every component: crashes between steps, duplicate messages, slow dependencies, cache staleness, token theft.
Keeping skills current
Java, Spring and the ecosystem move (Spring Framework 7's resilience annotations used in ch52 are recent; JDK releases every six months). Keep the projects alive: upgrade the JDK and Spring when new versions come out, rerun the definitions of done, and note what changed. That habit is itself a senior skill.
Senior exercises
S1. Review a teammate's backend portfolio project
A teammate's README for project 5 says: "Implemented payments with Spring Boot, Resilience4j and Kafka. Retries for reliability. Circuit breaker for resilience. Fully tested (92% coverage). Production ready." Review it, and list the questions you'd ask and the evidence you'd want.
S2. Design the backend of a food-ordering product in an interview
In a 45-minute system design interview: "Design the backend for a food-ordering app for 2,000 kitchens and 500,000 daily orders." Outline your answer: requirements and numbers, the API, data model, the order flow (with payments and notifications), consistency choices, caching, scaling, failure handling, observability, and what you'd build first. Point to where your projects give you evidence.
S3. Choose which projects to do, deliberately
You have 8 weeks of evenings (about 10 hours a week) and are targeting senior backend roles. Choose which projects to do, in which depth, and which stretch goals, with reasons. What would change if you were targeting a platform or SRE-leaning role instead?
S4. Turn the projects into a team training programme
You lead a backend team of six (two juniors, three mid-level, one senior). Design a 10-week programme based on these projects: - pairing; - who does what; - weekly demos with measurements; - review practice; - how you assess progress (mastery levels); - how it connects to real work.
S5. Tell a project story in an interview
Prepare a 5-minute story about project 4 (or 5) for a senior interview, using the STAR shape: - the situation and goal; - the hard problem; - what you did, with alternatives; - the measured result; - what you learned and would do differently.
Then prepare answers to three follow-up questions an interviewer is likely to ask.