The TiffinBox BuildOne system, every chapter
0 / 0

Workbench / The TiffinBox Build

The Build

The TiffinBox Build

One real system, built a little more with every chapter you read, from a command-line tool in Volume 1 to a secure, observable, AI-assisted platform by the last volume. Each stage tells you what to add and why it matters in the real world, what theory you need, how to build it, and what a senior engineer or architect would decide and measure. Nothing is thrown away: every stage stands on the ones before it.

56 chapters◷ ~6 h to read ✓ 336 topics

The system you're building

TiffinBox is an ordering platform for a group of South Indian tiffin centres in Hyderabad. Customers browse menus and order, kitchens see a live queue, delivery partners pick up, and payments, notifications, analytics and an AI assistant sit around that core. It's the running example in every volume of the textbook, so each chapter already speaks its language. Here you build it, for real, one stage per chapter.

The build starts as a command-line tool that does one thing correctly. Each chapter adds the next piece that chapter makes possible: a data structure the kitchen queue needs, a durable log, a hand-written HTTP server, a web app, a Spring service, a real database, replication, deployment, observability, security, AI. By the end it's the system that Volume 19 (Capstone) describes, built by you, with a record of every decision and measurement along the way.

How the system grows across the volumes

VolumeWhat TiffinBox gainsWhat you'll be able to defend
1 Foundations of ComputingThe core engine as a CLI and library: the domain model, a menu index and kitchen queue, scheduling and routing algorithms, a binary order log on disk, a hand-written TCP and HTTP server, a small rules language for discountsWhy each data structure and algorithm, measured; what "durable" means at the OS level; how a server really handles bytes
2 The Web FrontendThe customer web app and the kitchen display, talking to the stage-1 serverRendering strategy, state, accessibility and performance budgets, with numbers
3 The BackendThe order service rebuilt on Spring Boot with PostgreSQL, security, messaging, caching and testsTransaction boundaries, idempotency, retries and back-pressure under failure
4 DatabasesThe schema designed properly: indexes, isolation levels, migrations from the stage-8 logQuery plans, locking, and when to denormalise
5 Distributed SystemsReplication, events between services, consistency choices, sagas for order and paymentWhich guarantees each flow needs, and what it costs
6 Infrastructure · 7 CloudLinux hosts, containers and networking, then the system deployed to a cloudNetwork paths, resource limits, managed against self-run, cost
8 DevOps, CI/CD and IaCGit workflow, pipelines, environments as codeRepeatable builds and releases, rollback
9 Observability and SREMetrics, logs and traces across every component; SLOs and alertsError budgets and what to page on
10 Security · 11 TestingA threat model with controls; a test strategy across the whole systemRisk-based trade-offs; confidence per release
12 System Design · 13 ArchitectureTiffinBox scaled to many cities; module boundaries, ADRs and refactoring of what earlier stages got wrongCapacity estimates and architectural decisions with alternatives
14 AI and ML · 14b Applied AIDemand forecasting for kitchens; semantic menu search and a support assistant with retrievalWhen ML beats rules, evaluation, cost and safety
15 Product · 16 Production DeploymentProduct metrics and experiments; release strategies (canaries, flags)Shipping safely and measuring whether it mattered
17–20 Depth, Sequence, Capstone, RevisionA chosen deep track; the build converges with the Capstone's milestones and evidence; a full review of past decisionsThe whole system, end to end, in an interview or design review
21 Data Engineering · 22 Mobile · 23 i18nAn analytics pipeline; a delivery-partner mobile app; multiple languages, scripts and currenciesBatch against streaming; offline-first; Unicode and locale correctness
24 Senior Engineering CraftDesign docs, RFCs and reviews written for TiffinBox itselfLeading the system's next year, not just building it

This table is the plan, not a promise: each stage is written when you reach its chapter, so it can build on what you actually did in the stage before.

Stages so far

How each stage works

The briefWhat TiffinBox gains in this stage, why a real company would need it, and what you'll have when you're done.
Theory to ownThe ideas from the chapter that this stage depends on, framed as questions you must be able to answer before building.
Build itStep-by-step guidance with checkpoints. Each checkpoint's hints and reference solution unlock after you write your own answer.
Senior and architect lensThe decisions behind the code: options, trade-offs, what breaks at scale, and the decision record (ADR) to write.
EvidenceThe measurements and demonstrations that prove the stage is done. This is what goes in your README and your interviews.
Carry forwardWhat later stages will rely on, so you don't paint yourself into a corner.

Rules of the build

  1. One repository for the whole journey. Stages add to it; they never start over. When a later chapter shows an earlier choice was wrong, you refactor it and record why.
  2. Decisions are written down. Every stage ends with at least one short ADR in docs/adr/: the context, the options, the decision, and what would make you revisit it.
  3. Done means evidence. A stage is done when its evidence list is met: real outputs, tests and measurements, not "it works on my machine".
  4. Reproduce failures before fixing them. For anything about concurrency, durability, networking or security, first write the script that shows the problem.
  5. Small is fine. Each stage is sized for a few focused sessions. If a stage runs long, ship the core and list the rest under "next steps" in its README.

Mastery levels

L1 RecognitionDefine it and identify it.
L2 WorkingUse it correctly in code or config.
L3 InternalsExplain why it works.
L4 DebuggingDiagnose failures and performance problems.
L5 DesignChoose among competing approaches.
L6 ProductionOperate it under scale, failure, security and cost.

Reference implementations were built and run on a Linux lab machine (Java 21, GCC 13, Python 3.13); outputs quoted in solutions are real. Your code will differ, and should: the solutions show one defensible way, not the answer.

Contents

  1. S1 · V1·01The Toolbox and the First ToolVolume 1, chapter 01. TiffinBox starts as a repository and one honest command-line tool, `tbx orders stats`: it reads a day's orders, totals them in…11 min
  2. S2 · V1·02The Domain ModelVolume 1, chapter 02. TiffinBox gets its core vocabulary as code: `Money`, `Dish`, `OrderLine`, `Order`, and the order lifecycle as a sealed set of…7 min
  3. S3 · V1·03Indexes and QueuesVolume 1, chapter 03. TiffinBox's core gets its first data structures chosen for real access patterns: a `Menu` with O(1) lookup by dish id and…7 min
  4. S4 · V1·04Rankings and RoutesVolume 1, chapter 04. TiffinBox learns to rank its most popular dishes (a count plus a size-k heap) and to find the fastest delivery route across a…7 min
  5. S5 · V1·05Proving the LifecycleVolume 1, chapter 05. The order lifecycle stops being checked by a few examples and is checked exhaustively: every state against every event against…8 min
  6. S6 · V1·06A Versioned Binary RecordVolume 1, chapter 06. Orders get a compact binary form: a magic number, a version byte, varint lengths, strict UTF-8, a CRC-32, and an extension…8 min
  7. S7 · V1·07A Day in ColumnsVolume 1, chapter 07. A day's orders are turned into columns, each field in its own primitive array with ids encoded as small integers, and the…7 min
  8. S8 · V1·08A Durable Order LogVolume 1, chapter 08. "Saved" gets a precise meaning: an order change is acknowledged only after its record is fsynced to an append-only log. One…8 min
  9. S9 · V1·09An HTTP Server by HandVolume 1, chapter 09. TiffinBox gets a network face: a small HTTP/1.1 server written on plain sockets, one virtual thread per connection, serving…8 min
  10. S10 · V1·10A Language for DiscountsVolume 1, chapter 10. Discount rules get their own small language ("rule "Big order" when total >= ₹1000 then ₹100 off"): a lexer that understands…9 min
  11. S11 · V1·11Release 0.1Volume 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…8 min
  12. S12 · V2·12One Origin for App and APIVolume 2 begins. TiffinBox gets its first web page, served by stage 9's server from the same origin as the API, so the browser's same-origin policy…9 min
  13. S13 · V2·13Ordering With No JavaScriptVolume 2, chapter 13. The customer's whole ordering flow (menu, search, order form, review, place order, receipt) is built as server-rendered HTML…7 min
  14. S14 · V2·14A Design System in TokensVolume 2, chapter 14. The stage 13 pages get one stylesheet: cascade layers in a fixed order, design tokens as the only place colours and sizes are…8 min
  15. S15 · V2·15Search as You TypeVolume 2, chapter 15. The first JavaScript in TiffinBox: the stage 13 menu search, enhanced to search as you type. A tested helper module (debounce…7 min
  16. S16 · V2·16One Contract, Checked on Both SidesVolume 2, chapter 16. The JSON the server sends gets one description, `contract/api.json`. A small generator turns it into TypeScript types and…7 min
  17. S17 · V2·17The Kitchen Display, LiveVolume 2, chapter 17. Kitchens get a live display: the server streams each kitchen's order changes as Server-Sent Events, with ids that survive…7 min
  18. S18 · V2·18Profiling the DisplayVolume 2, chapter 18. The stage 17 kitchen display, measured with 500 open orders on a CPU slowed four times: applying the first snapshot took 1,482…5 min
  19. S19 · V2·19Safe Retries and a Revalidated MenuVolume 2, chapter 19. Kitchen actions become safe to retry: each tap carries an Idempotency-Key, stored in the order log with the event, so a repeat…7 min
  20. S20 · V2·20The Display, HeardVolume 2, chapter 20. The kitchen display is checked through Chromium's own accessibility tree, the one screen readers are given, and three of the…6 min
  21. S21 · V2·21A Display With an ArchitectureVolume 2, chapter 21. The kitchen display had grown to 200 lines of flags, handlers and DOM code. Stage 21 splits it into a pure core (a connection…7 min
  22. S22 · V2·22The Display in ReactVolume 2, chapter 22. Stage 21 gave the kitchen display a pure core; stage 22 puts a second view on it, in React 19, and measures what that costs.…7 min
  23. S23 · V2·23The Display in AngularVolume 2, chapter 23. A third view of the kitchen display, in Angular 22, on the same store as the plain and React views. The store becomes a signal…7 min
  24. S24 · V2·24Keep the First ScreenVolume 2, chapter 24. The kitchen page has been server-rendered since stage 21, but the React and Angular views threw that work away: they removed…6 min
  25. S25 · V2·25State in the Right PlaceVolume 2, chapter 25. Three pieces of state get a proper home. The plain kitchen view moves onto the shared store and the page's embedded state, so…6 min
  26. S26 · V2·26Tests That Catch ThingsVolume 2, chapter 26. The stage scripts so far were evidence, run by hand; this stage builds the regression net and then tests the tests. A pytest…4 min
  27. S27 · V2·27Budgets That Gate ChangesVolume 2, chapter 27. The performance work of stages 18–25 becomes rules a change must pass. One measurement module times what the kitchen display's…6 min
  28. S28 · V2·28Lock the SinksVolume 2, chapter 28. Escaping has protected TiffinBox's pages since stage 12; this stage adds the layers that work when escaping fails. Trusted…5 min
  29. S29 · V2·29Keep Working OfflineVolume 2, chapter 29. A kitchen tablet loses Wi-Fi in the middle of lunch; until now the display went blank on reload and a tap failed with "check…6 min
  30. S30 · V2·30What Ships, and Can We Rebuild It?Volume 2, chapter 30. The frontend has grown to three views, a service worker, a generated contract and two TypeScript versions, built by a script…5 min
  31. S31 · V2·31Ship Without Breaking Open TabsVolume 2, chapter 31. Until now a deploy meant replacing files in web/ while kitchen tablets kept old pages open, and every visit downloaded every…5 min
  32. S32 · V2·32See What Users SeeVolume 2, chapter 32. Every measurement so far was taken in the lab: one browser, one machine, a test that knew what to look for. This stage adds…5 min
  33. S33 · V2·33Release 0.2.0, Gated by Real UsersVolume 2, chapter 33, the end of the volume. The chapter's eight projects are the ones TiffinBox has already built across stages 12–32; this stage…4 min
  34. S34 · V3·33The Language, AuditedVolume 3 begins: the server half of TiffinBox, in Java, chapter by chapter. Its first stage turns chapter 33's sharp edges (silent overflow, boxed…4 min
  35. S35 · V3·34Add a Case, Count the PlacesVolume 3, chapter 34. TiffinBox models orders the "other way" the chapter describes: data (sealed records for states and events) plus one pure…4 min
  36. S36 · V3·35The Queue Is an IndexVolume 3, chapter 35. The kitchen queue was a PriorityQueue, and the server only ever removed its head. A test with three orders showed the cost…4 min
  37. S37 · V3·36Typed KeysVolume 3, chapter 36. The log's extensions were a Map and four int constants, so every reader decoded bytes by hand and nothing stopped one from…4 min
  38. S38 · V3·37One ClockVolume 3, chapter 37. The pricing rules were pure: they saw the time only through Facts. But the review page built its preview with Instant.now(), so…4 min
  39. S39 · V3·38Two Kinds of TimeVolume 3, chapter 38. Stage 38 put a fixed clock into a server test, which showed what else read that clock: the deadline that stops a client…4 min
  40. S40 · V3·39The Next JDKVolume 3, chapter 39. TiffinBox compiles with --release 21, so it should build on JDK 25 unchanged. It didn't: javac 23 added a warning…4 min
  41. S41 · V3·40Starting and StoppingVolume 3, chapter 40. Started on a port another process held, the TiffinBox server printed a BindException and then hung: main had died, but the…5 min
  42. S42 · V3·41Measured, Then ChangedVolume 3, chapter 41. Measured at 2,000, 20,000 and 50,000 orders, the TiffinBox server held two copies of every changed order (its retry table kept…5 min
  43. S43 · V3·42One Runtime, RebuiltVolume 3, chapter 42. TiffinBox's jars were reproducible with fixed timestamps, until they were built on JDK 25: 13 of 106 class files changed…5 min
  44. S44 · V3·43A Build That Knows Its InputsVolume 3, chapter 43. TiffinBox's build was four shell scripts run in order: 75 seconds every time, whatever changed. Copied into Gradle for…5 min
  45. S45 · V3·44Find One RequestVolume 3, chapter 44. A TiffinBox user who got an error saw "internal error", and the operator got one line on stderr with no path, no request and a…5 min
  46. S46 · V3·45Through the MiddleVolume 3, chapter 45. Put behind nginx configured as a shared cache, TiffinBox failed in three ways its own tests couldn't see: nginx spoke HTTP/1.0…5 min
  47. S47 · V3·46Wired, Not Reached ForVolume 3, chapter 46. TiffinBox priced every order in a time zone that was a static constant on Server, which Pages also read directly: no test could…4 min
  48. S48 · V3·47Ready, Then GoneVolume 3, chapter 47. TiffinBox had one health URL that said 200 as soon as the socket was open, while its first requests took twenty times as long…5 min
  49. S49 · V3·48Typed at the DoorVolume 3, chapter 48. TiffinBox's Server held the sockets, the routes, every order, the queues and the rules for changing them in 681 lines; its…6 min
  50. S50 · V3·49The Ledger Carried ForwardVolume 3, chapter 49. TiffinBox's order log has been its database since stage 8: one file, replayed into memory on every start. Recovery read the…5 min
  51. S51 · V3·50Whose Order Is It?Volume 3, chapter 50. For fifty stages TiffinBox believed the X-Customer-Id header: anyone could place an order as anyone, read any order by counting…5 min
  52. S52 · V3·51Later, ReliablyVolume 3, chapter 51. TiffinBox's background work had no home: the RUM summary was computed on request while holding the lock every beacon needs, so…4 min
  53. S53 · V3·52When the Disk Is SlowVolume 3, chapter 52. A game day on TiffinBox: one of two instances behind haproxy gets a disk whose fsyncs take 2 seconds longer, injected with a…4 min
  54. S54 · V3·53Computed Once per ChangeVolume 3, chapter 53. TiffinBox has no database to cache in front of, and still had a stampede: after a deploy every kitchen tablet reconnects, and…3 min
  55. S55 · V3·54Tests That BiteVolume 3, chapter 54. TiffinBox has 78 server tests, a golden master, a contract test and a browser suite; this stage tests the tests. A hand-rolled…4 min
  56. S56 · V3·55Release 0.3.0, Checked at Every DoorVolume 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…8 min