Build a Till and Stockroom for a Tapas Bar
A 38-seat tapas bar took fifteen orders for eleven portions of grilled octopus when its terrace wifi dropped and its till, two handhelds and a delivery app each sold from the number they last saw. You will build the replacement, from publishing a menu and firing a round to selling the last portion of a plate exactly once across every seller and closing the business day. You prove it in a simulated Friday where a handheld loses wifi, a card reader times out and the delivery app repeats itself.
The brief
The client
I own a 38-seat tapas bar. Guests order small plates a round at a time, from the till at the bar, from two waiters' handhelds on the terrace and through one delivery app. Last Saturday I had eleven portions of grilled octopus when the terrace wifi dropped for forty minutes, and the till, both handhelds and the app each sold from the number they last saw, so we took fifteen orders for it and four tables had to choose again. A guest on a split check was charged twice when the card reader timed out, which I only learned when she emailed me. We close after 01:00, so Saturday's late takings landed on Sunday's sheet, and my pen count on Monday showed we had been short on squid all week. I need the last portion sold once, a card charged once, and a Monday count that tells me what we really used.
The problem
Orders come from four sellers that each keep their own idea of how many portions of a limited plate are left. Two sellers that see 1 left at the same moment both sell it, and a handheld that loses wifi sells from a stale number until it reconnects, so the oversell is found after the tables have been told yes.
Ingredient stock is a different problem. It is counted by hand once a week, so food cost is a guess and a plate runs out mid-service with nobody warned. The day also has two meanings: the owner closes at 04:00 and reads takings per night, while the bookkeeper's sheet uses the calendar date, so an order rung at 01:30 on Sunday sits on the wrong row. A manager approves voids at the till and nothing records who. The bad Saturday cost four re-ordered tables, one double-charged guest and a day of reading three screens to find which order was a duplicate.
The client's name and figures are invented for this brief; the rules and the failures are ones that real businesses of this kind work with.
The spec
Requirements
- Let the owner publish plates with a price, a recipe in grams and, for a limited plate, a portion count for the day, and keep every earlier version of a price and recipe readable.
- Let a waiter place an order in rounds, fire a round, and show each station (kitchen and bar) only its own plates, with bump and recall.
- Void or comp a line as a new record that names the approver. Nothing is edited or deleted.
- Sell a limited plate no more times than there are portions, across the till, both handhelds and the delivery app at once, and show the plate as sold out on every connected seller within 10 seconds of its last portion being sold or the chef taking it off. A handheld with no connection learns when it reconnects.
- Let a handheld that lost wifi keep taking orders from the portions it was given, and merge its orders when it reconnects without losing or duplicating one.
- Split a check across cards and cash, charge each card part exactly once even when the provider answers late, and settle the check only when its parts add up to its total.
- Accept an order from the delivery app once, even when its message arrives twice, and reject it when the plate is gone or the app's 3-minute accept window has passed.
- Take each fired round's ingredients out of stock once, record deliveries, counts and waste with the person who decided, and list the ingredients whose counted usage differs most from what the recipes predict.
- Close the business day at the site's cutoff and produce the Z report (the end-of-day sales summary) that the owner checks against the bookkeeper's sheet, with each fact assigned to a day by the cutoff and not the calendar date.
- Erase a delivery guest's name and phone on request and keep the orders and payments, identified by ID.
Deliverables
- Your repository starts the whole product with one command, plus stand-ins for a waiter's handheld, the delivery app and the card provider that can cause the failures this brief names.
- A README that takes a reviewer from a fresh clone to a closed simulated Friday with its Z report in 20 minutes, and lists the command for each test.
- Documentation for the people and devices that talk to the product: how a handheld uploads orders, how the delivery app's messages are received, how the card provider's notices are received, and how staff publish a plate, place an order, take a payment, record a count and read a report.
- A test suite that includes the simultaneous-seller race, plus the results of the simulated Friday from the final Phase committed to your repository.
- A way to run the bar's Friday faster than real time with a fixed seed, so two runs on a fresh install give the same totals.
- An operations note, stated as outcomes: how an operator finds and finishes an order or a stock change that a crash left half done, how to compare a closed day's report with the figures recomputed from its orders, and how to read the consistency check.
Out of scope
- Several sites, a central menu and stock transfers. This is one bar. Multi-site data is the subject of Build a Restaurant Group Back-Office, the next step up.
- Table booking, a waitlist and no-show fees. The bar takes walk-ins, and a booking is a different scarce thing with one holder and no offline seller. Build a Table Book for a Small Bistro covers booking at a smaller size, and the next step up covers it with a waitlist.
- Rosters, rest rules, clocking and tip pooling. The owner cooks and runs five staff, so the report shows food cost only and prime cost is out.
- Purchase orders, supplier invoices, three-way matching, lot recalls and fridge logs. A delivery is one stock entry here, and matching three documents belongs to the next step up.
- Allergen derivation from recipes. A line may carry a free-text note for the kitchen, and working out a plate's allergens from its ingredients is catalogue work for the next step up.
- Adding a tip after capture, refunds with a named approver and the card processor's tip window. A tip is recorded when a part is captured, and deadlines set by a processor belong to the next step up.
- Card payments taken offline and offline limits per terminal. The handheld orders offline and does not take card money. Offline liability is a payments question that the next step up owns.
- Platform settlement reconciliation and commission. Money from the delivery app is paid to the bar outside this system, so only the order is in scope.
- Tax lines, the VAT split, fiscalisation and real card processing. Prices and totals are gross amounts in euro cents, and the card provider is a stand-in you write. The bookkeeper also needs turnover per VAT rate, which the Z report does not show, so it is a summary the owner checks and not a filing.
- Stock of drinks. Drinks are plates with an empty recipe, because counting bottles is a different problem from counting grams.
- A front end, a booking site and a staff app. Requests you document and the simulator scripts stand in for them, because every check is on behaviour.
- Logins and identity checks. Staff are named by a staff id and a staff role that each staff request carries, and the product trusts and records them. Do not put this product on the internet.
- A correction for a handheld's wrong clock. The time a handheld says an order was taken is trusted as sent.
- Kubernetes or cloud deployment. Everything runs on one machine.
Architectural constraints
- Amounts are exact to the cent. Prices and totals are whole euro cents and weights are whole grams.
- A limited plate is never sold more times than there are portions, across every seller, including while a handheld has no connection.
- A card is never charged twice for one payment, however many times the provider answers, repeats itself or arrives out of order. No card number is ever stored or logged, only a token and the last four digits.
- A message from an outside party that arrives twice changes nothing the second time, and an older message never overwrites newer news.
- A crash between saving something and the effect that should follow it loses nothing and doubles nothing.
- Every fact belongs to a business day set by the bar's zone, Europe/Amsterdam, and its 04:00 cutoff, never by the calendar date. What happened first stands, whichever message arrives first.
- Nothing is edited or deleted. A void, a comp, a count and a waste entry are added records that name the person who decided.
- An issued Z report never changes. A fact that arrives after its day closed appears as a correction that names the difference.
- A delivery guest's name and phone are erased on request once the order's business day is closed, and the orders, payments and stock records stay, identified by ID. No log, file or store the product keeps holds them afterwards. The bar must keep its business records for 7 years under Dutch rules (Belastingdienst), which is why they stay; a guest's name and phone are not part of what that rule requires.
Prerequisites
You have built one application with a database, in any language and framework. You have run it, tested it and fixed a bug you found by running it. You do not need distributed systems experience, and you do not need restaurant knowledge, because the first Phase explains how a tapas bar sells, serves and counts its plates and the words the brief uses, and each Checkpoint explains the problem it checks. You will run several things at once on one machine: the product, two handheld stand-ins, a delivery-app stand-in and a card-provider stand-in. Having once watched two people overwrite each other's change in an application you built will make Phase 3 familiar. The beginner project Build a Table Book for a Small Bistro covers the same domain at a smaller size and is not required.
Free to start. An account is what keeps track of the checkpoints you finish.
Take orders and fire rounds
Produces orders placed in rounds with every line sold at the price in force then, kitchen and bar tickets with bump and recall, and voids and comps that name an approver. A limited plate has no portion limit yet, and nothing can be paid until Phase 4.
Acceptance criteria
A waiter places an order with a request that names a staff id and a staff role (waiter, manager or owner). The waiter supplies an order id the device or till makes (optional at the till), a table label (1 to 20 characters), covers (1 to 38) and 1 to 12 lines. Each line names a plate, a quantity (1 to 12), a round number (a positive whole number) and an optional note of up to 200 characters. The answer holds the order id, an open status, the till as its source, the business night, the total in cents, and every line with its id, the plate version it was sold at, its price in cents, its station and its note.
For table T12 with 2 covers, round 1 holds 2 patatas bravas at 650 cents and 1 grilled octopus at 1450 cents, and round 2 holds 2 cana at 350 cents. The total is 3450 cents (1300 plus 1450 plus 700).
Each line keeps the price and plate version in force when it was added. After the owner publishes version 2 of patatas bravas at 700 cents, reading the order still shows version 1 at 650 cents for those lines and a total of 3450. A request that adds a line in round 3 sells it at version 2 and 700 cents.
With the product's clock fixed at 12 Jun 2027, 00:30 UTC (01:30 local), an order gets the business night 2027-06-11. At 12 Jun 2027, 02:00 UTC it gets 2027-06-12.
These are refused, and each stores nothing: an unknown plate, a withdrawn plate, a quantity of 0, covers of 0 or 39, 13 lines, a round number of 0, and a request that names no staff id or role. A limited plate has no limit yet in this Phase, so six orders of 12 portions of grilled octopus are all accepted.
Architectural guidance
If an order keeps only the plate and looks the price up when the report runs, last week's takings change the day the owner edits a price. The business night is set when the order is placed, so it cannot move later if the zone or the cutoff is changed.
Acceptance criteria
Sending the same order a second time, with the same order id and the same content, returns the first answer and there is still one order. Sending the same order id with different content is refused and changes nothing.
Twenty identical requests sent at the same instant by separate clients end with exactly one order, and every client is told about that same order. The test runs enough times that a race would show, and the README records one run.
Killing the product in the middle of placing an order leaves either the whole order with all its lines or nothing. After a restart, sending the order again succeeds and produces exactly one order with all its lines.
Architectural guidance
A handheld on weak wifi cannot tell whether its order reached the server, so the waiter sends it again. If the second copy becomes a second order, the table is billed for double and the kitchen cooks everything twice. The case that goes wrong is the one where both copies are in flight together, which a test sending them one after another never produces.
Acceptance criteria
Firing a round creates one ticket for each station that has at least one line in that round, and the answer lists the tickets. For the T12 order, firing round 1 creates one kitchen ticket holding the 2 patatas bravas and the octopus, and firing round 2 creates one bar ticket holding the 2 cana. A round with a kitchen plate and a bar plate creates two tickets.
Firing the same round again returns the same tickets and creates no new one. Three fire requests for round 1 leave one kitchen ticket. Firing a round number that has no lines is refused. Adding a line to a round that was already fired is refused, and adding a line to a new round number is accepted and firing it creates a new ticket.
A request for a station's tickets lists the fired tickets that are not bumped, oldest fired first. Each shows the table label, the round, and its lines with plate name, quantity and note. A kitchen plate never appears in the bar list and a bar plate never appears in the kitchen list. A line with the note "no shellfish" shows that note on the ticket.
Bumping a ticket removes it from the station list. Bumping an already bumped ticket changes nothing. Recalling a bumped ticket puts it back at its original place, so a ticket fired before another still comes before it. Recalling a ticket that is not bumped is refused. The order, when read, shows each ticket's history: fired, bumped, recalled, with the time of each.
Killing the product right after a round was fired leaves, after a restart, the ticket on its station's list exactly once and the order showing the round as fired.
Architectural guidance
A station finishes work on its own clock, and a table can add a round halfway through the meal, so the kitchen must see only its plates and see each one once. A waiter's double tap that fires the same round twice sends the kitchen a second ticket, and the kitchen cooks the same dishes again. Phase 5 takes ingredients out of stock for each fired round, so a round fired twice also takes the ingredients out twice and every Monday count looks short.
Acceptance criteria
A void request and a comp request on a line take a reason from: guest changed their mind, wrong plate, kitchen error, service recovery and other. Each also names the staff id and role. Each adds one correction to the order that records the kind, the line, the approver's staff id, the role, the reason, whether the line was already fired, the time and the business night. The line itself does not change, and a test compares it before and after.
A waiter can void a line whose round has not been fired. A waiter who voids a fired line, or who comps any line, is refused and nothing is written. A manager or an owner can do all three. A request that names any other role, or claims to be the product itself, is refused. A missing or unknown reason is refused.
The T12 order starts at 3450 cents. Voiding the patatas bravas line (2 at 650, so 1300) before round 1 is fired brings the total to 2150, and the voided line does not appear on the kitchen ticket when round 1 is fired. Comping the octopus line (1450) brings the total to 700 and the line stays on the bill at 0. Voiding a line after its round was fired keeps the line on the ticket, shown struck through, and records that it was fired.
A line that already has a correction cannot be corrected again, and the second request is refused. A line of another order is reported as not found. A round whose lines are all voided cannot be fired. A correction never changes the price or plate version on the line. Reading the order lists the corrections with approver, role, reason and time.
Architectural guidance
A void after the round was fired differs from one before it, because the kitchen has already spent the food, so it needs a manager and it leaves the ingredient use for that round in place. This brief does not check who a person is, and it records the name and role that arrive in the request so that the question "who" has an answer.
Acceptance criteria
A script places the T12 order of 3450 cents from twenty clients at the same instant and ends with exactly one order. It fires round 1 three times and ends with one kitchen ticket, and fires round 2 and ends with one bar ticket. It voids the patatas bravas line before round 1 is fired and comps the octopus line, and the total is 700 cents with the voided line absent from the kitchen ticket and the octopus line on the bill at 0.
A second correction on either line, a void by a waiter on a fired line and a comp by a waiter are each refused and write nothing. The product is killed once between placing and firing and once between firing and a correction. After each restart the order, its tickets and its corrections are the same as before the kill, and a repeat of the same requests changes nothing.
Architectural guidance
Two requests at once, or a crash between placing and firing, can leave an order twice, a ticket twice or a line corrected twice. The kitchen then cooks what one record says while the bill shows what another says.
Architectural walkthrough
The failures here are small and each costs the kitchen or the bill. A past order changes price when the menu does. A request sent twice makes two orders, or fires a round twice, and the kitchen cooks the same plates twice. A void erases who made it and what the line looked like before, so nobody can answer a guest or the owner.
Tapas arrive in rounds. A table asks for a few plates, then a few more, and each round is sent to the kitchen and the bar on its own clock. A line is a fact about one sale, so it keeps the price and recipe it was sold at, whatever the owner publishes later. A waiter on a handheld whose wifi hiccups sends the same order again, and the bar must end up with one order and one set of tickets, because a second set means a second dish nobody ordered.
A correction is a statement that someone decided something. If the line is edited in place, the owner loses the name of the person and the bill as it stood. A void after the kitchen cooked is a different fact from a void before it, because the food is spent, and a waiter should not be able to make it alone.
Limited plates have no portion limit in this Phase, so ordering twelve octopus portions six times succeeds. Phase 3 changes that.
Sell the last portion once
Produces limited plates that sell exactly as many portions as exist across the till, two handhelds and the chef's 86, including a handheld that loses wifi. The delivery app is not a seller yet, so its two octopus portions stay unsold, and nothing is paid for.
Acceptance criteria
The owner divides a limited plate's portions for a business night among four sellers: the till, handheld 1, handheld 2 and the delivery app. A manager or an owner asks, with a request you document, for a number of portions (1 to 12) of one plate for one seller. The answer is a share with an id, the seller, the plate, the quantity, the time it ends (30 minutes after it was given) and the business night. A seller that is none of the four is refused.
The first request for a plate on a business night fixes that night's total from the portions per day of the version in force at that moment, here 12 for grilled octopus. Many first requests sent at once fix one total. Publishing version 2 of the plate with 20 portions per day afterwards leaves that night at 12. The next business night starts its own count of 12.
With 12 portions left, a test starts more separate clients than there are portions, each asking for 1 portion. Exactly 12 requests are given a share and the rest are refused as not enough portions left. The portions left end at 0 and never go below. A second run in which each client asks for 3 gives a share to exactly 4 clients and refuses the rest. A request for 5 when 4 remain is refused whole and 4 still remain. A request for 4 then succeeds. A refused request leaves no share behind.
These are refused, and each stores nothing: a plate that is not limited, a withdrawn plate, a quantity of 0 or 13, and a request that names no staff id or role.
The README records a run of the same race against a version of your own build that you made wrong on purpose, with the number of shares it gave out, which is above 12. It shows that the test can fail.
The README states the share rules in your own words: what a seller has sold is at most what it was given, what was given is at most what exists, a share ends 30 minutes after it was given, and what happens to portions nobody reports.
Architectural guidance
The failure exists only while two requests are in flight together, so a test that sends them one after another passes and proves nothing. A rule that has never been seen to fail may be checking nothing.
Acceptance criteria
A limited plate can now be ordered only from a share the seller holds. The till is a seller, and a manager or an owner gives it a share with a request you document. You build a stand-in for the first handheld, which the tests run as handheld 1. It can ask for a share, sell from the share it holds and report what it sold.
Seed the night with 12 octopus portions. At 19:00:00Z give the till a share of 4 and handheld 1 a share of 3. The portions left to give out are now 5.
The till takes four orders of 1 octopus and its share reaches 0. Reporting the share at that point returns 0 unsold portions, because all 4 were sold. A fifth order for 1 octopus asks for a top-up of 1, which is granted, and sells. The portions left to give out are now 4.
When a line needs more than the seller holds, the product asks for a top-up of exactly the missing quantity. With the till holding a share of 2 and an order line of 3, a top-up of 1 is granted and the order succeeds. When the top-up is refused, the whole order is refused as sold out, nothing is stored, and the till's share is still 2. The earlier Phase 2 test that accepted six orders of 12 octopus portions is replaced by this rule.
An order the till's share covers is accepted even when no new share can be requested, so the till keeps selling while no new share can be given for the length of the test.
Handheld 1 sells 1 of its 3 portions at 19:01:00Z, and a fourth sale prints that the plate is sold out at this device. It refuses to sell after the time its share ends, judged by its own clock.
A seller never sells a limited plate it was not given. A request that would sell more than the seller holds and more than any top-up can supply is refused and stores nothing.
Architectural guidance
A seller that has to ask a central count at the moment of every sale stops working when the connection does, and a handheld on the terrace loses wifi for forty minutes. The bar's share rule lets a seller keep selling without a connection and caps what it can sell. The cost is that a seller can run out of portions while another seller still holds some, so a seller asks for a top-up when it can and shows the plate as sold out when it cannot.
Acceptance criteria
A share ends 30 minutes after it was given. After that the seller may not sell from it. The unsold portions come back to be given out again only when the seller reports what it sold, and the report may arrive after the share ended. A share nobody reports stays counted as sold for the night. A seller reports a share as soon as it reaches zero.
Seed the night with 12 octopus portions. The till takes a share of 4 and handheld 1 takes 3 at 19:00:00Z, so 5 are left to give out. The till sells 4 and reports at once, and a top-up of 1 is granted, so 4 are left. Handheld 1 sells 1 at 19:01:00Z and goes quiet. At 19:30:00Z its share ends with 3 unreported portions, and 4 are still left to give out. The 3 portions are never given out again while nobody reports them.
At 19:35:00Z handheld 1 reports that it sold 1. The report is accepted even though the share ended, 2 portions come back, and 6 are left to give out. Reporting the same share a second time changes nothing. Two reports of the same share sent at the same instant return the 2 portions once. A report of more sold than the share held, or from a device that is not the holder, is refused and changes nothing.
A till share given at 19:00:00Z that still holds 2 portions cannot be sold from at 19:31:00Z. The till's next attempt to sell that plate reports the share as sold for the quantity it used and then asks for a new share.
A process killed right after a share was given and before the seller heard about it leaves the portions counted as sold until the business night ends. The portions left to give out stay where they were, and a request for more than they hold is refused.
Architectural guidance
A seller that stops reporting could have sold the portions or not, and the product cannot tell which. Giving them out again risks telling a second table yes to a plate that is gone. Counting them as sold costs the bar a few unsold portions, which is the cheaper mistake. A crash between giving a share and the seller learning of it leaves the same doubt.
Acceptance criteria
A plate is sold out when no portions are left to give out and no share has portions unsold. A share has nothing unsold once its holder reported it or its time ended unreported. The plate is on sale again when a report returns portions to an empty night.
Seed 12 octopus portions. At 19:00:00Z the till takes 4, handheld 1 takes 3 and handheld 2 takes 3. The till sells 4 and reports, handheld 2 sells 3 and reports, handheld 1 sells 1 and goes quiet, and the till takes a top-up of 2 and sells both. No portions are left to give out, but handheld 1 still holds a share that is neither reported nor ended, so the plate is still shown on sale. At 19:30:00Z that share ends and the plate shows as sold out. A report from handheld 1 at 19:35:00Z that it sold 1 returns 2 portions and the plate shows as on sale.
A view lists every plate that is not withdrawn as on sale or not on sale and, when not on sale, the reason: sold out or eighty-sixed. After the plate sells out, a till order for 1 octopus is refused as sold out and nothing is stored. After the portions come back it is accepted again.
A seller whose own share is empty and whose top-up was refused shows the plate as sold out at that seller, even while another seller holds portions. When no portions are left to give out and handheld 1 holds 2 unsold, handheld 2 prints that the plate is sold out at this device and the view still lists the octopus as on sale.
A connected handheld shows a change from the view within 10 seconds of the change happening, for a plate selling out and for a plate coming back. A handheld with no connection shows it as soon as it reconnects.
The chef's 86 takes any plate off sale until she restores it. A manager or an owner can 86 or restore a plate, and a waiter is refused with nothing written. The product records who and when. Eighty-sixing a plate that is already 86'd changes nothing. Restoring a plate that is not 86'd is refused. While a plate is 86'd, the view shows it as not on sale with the eighty-sixed reason, a new order that contains it is refused as eighty-sixed, and an order already placed keeps its lines. A connected handheld shows the plate as sold out within 10 seconds of the 86.
Killing the product right after the last portion sells leaves, after a restart, the plate shown as sold out within 10 seconds, and a till order for it refused.
Architectural guidance
A plate can look available to a seller while its last portions sit with another seller, and a chef's 86 can be called while a handheld is out of range. Each extra table told yes to a plate that is gone costs a re-order and a bill adjustment, and the bar promises that connected sellers learn within 10 seconds. A sold-out plate that is only noticed when the next order fails tells the guest too late. An 86 is something only the chef knows, so the product has to record that she said it and when.
Acceptance criteria
The handheld stand-in can now take whole orders while offline and upload them. It makes each order id and the time each order was taken on the device, sells limited plates from its own share, and keeps its orders across a restart of the stand-in. You document what a handheld uploads: a batch of orders, each with its order id, the time it was taken, a table label, covers, lines (plate, quantity, round, an optional note, and the share it sold from for a limited plate) and the round numbers the waiter fired. The product records when each order arrived and never takes that from the device.
The product merges the orders of a batch in the order they were taken, whatever order they arrive in, and each order succeeds or fails on its own. The answer is sent after each order is stored, and tells the handheld for every order whether it was added, was already known, or was refused, with a reason. A refused order does not stop the others. A merged order has a handheld source, the business night of the time it was taken, and every line sold at the plate version in force when it was taken, not when it arrived. Fired rounds create tickets.
Uploading the same batch a second time reports every order as already known and leaves the orders and tickets unchanged. Two uploads of the same batch at the same instant leave one copy of each order. An order id reused with a different content is refused for that reason and changes nothing. A line that would sell past its share is refused for exceeding the share, and nothing of that order is stored. A share that does not belong to this device is refused as unknown. Orders that are invalid in the earlier Phase's sense (13 lines, covers of 0, an unknown plate) are refused with a reason.
A sale made on the device before its share ended is accepted even if the upload arrives after the share ended.
The chef 86s cured tuna belly at 11 Jun 2027, 19:30 UTC and restores it at 19:40:00Z. Handheld 1 was given a share of 3 tuna at 19:16:00Z, which ends at 19:46:00Z, and was offline from 19:20:00Z. It took order O1 (1 tuna) at 19:28:00Z, O2 (1 tuna and 1 marinated olives) at 19:31:00Z, O3 (2 patatas bravas) at 19:25:00Z and O4 (1 tuna) at 19:45:00Z. It uploads at 19:55:00Z in the order O2, O4, O3, O1. The result is the same for every upload order:
- O1 stays as sold, at 1250 cents. It was taken before the 86.
- O2 is added and its tuna line is voided automatically, with the reason that the chef had taken the plate off sale and no staff approver. Its total is 400 cents. The line stays on the ticket struck through, and the correction records that it was fired.
- O3 and O4 are added unchanged, because O3 holds no 86'd plate and O4 was taken after the restore.
- A conflict note on the orders names the 86 at 19:30:00Z and the sale at 19:31:00Z, and says the earlier time stands.
- The voided portion is not returned to the share. The share shows 3 of 3 taken.
A sale at exactly 19:30:00.000Z counts as after the 86. A staff request that claims to be the product itself is still refused. The product can say whether a plate was 86'd at a given instant.
Killing the product halfway through a batch and uploading the same batch again ends with every order added exactly once and none lost.
Architectural guidance
A buffered order arrives after it happened, so its price, plate version and business night come from when it was taken and not from when it arrived. The device cannot know whether its first upload reached the server before the connection dropped, so the same order may arrive twice. If the outcome of a sale and an earlier 86 depended on which batch arrived first, the same Friday would give a table its plate or take it away depending on whose wifi came back first. The guest's order, the ticket and the reason for the void all stay readable.
Acceptance criteria
A test replays the client's bad Saturday with separate clients and the full product running. The plate is grilled octopus with 11 portions for the night, the till holds a share of 4, handheld 1 holds 3, handheld 2 holds 3, and 1 portion is left to give out. The delivery app is not a seller yet.
Fifteen orders of 1 octopus each are taken at the same time: 6 at the till, 5 on handheld 2, and 4 on handheld 1, which is offline and uploads its orders after the others finish. Exactly 11 orders are accepted and 4 are refused, and every refusal says the plate is sold out, whether the server or the offline device refused it. The sum of all shares is 11. No seller's share is below 0, no portions are left to give out, and what each seller sold is at most what it was given. Once every share is reported, the plate shows as sold out. The test runs repeatedly, enough times that a race would show, and every run ends with the same counts. The README records the output of one run.
The suite also runs the same race against the deliberately wrong version from the first Checkpoint of this Phase, now applied to the till's share, and the README records the number of orders it accepted, which is above 11.
Two further scenarios run on a new business night with 11 portions. In the first, handheld 2 takes a share of 3, sells 1 and never reports. After 30 minutes the share ends and 8 are left to give out. The other sellers sell everything the product allows, 8 portions in all, and a request for 1 more is refused. A report from handheld 2 that it sold 1, made 15 minutes later, returns 2, and exactly 2 more portions can then be sold, so the night ends with 11 sold. In the second, the product is killed after a share of 3 was given and before the seller heard about it. 8 are left to give out, no seller holds the share, a request for 9 is refused, and the 3 portions stay counted as sold until the business night ends.
An operator can run a consistency check, and a script can tell when it fails because it exits non-zero. This version has one rule: for every limited plate and night, what was sold is at most what was given, and what was given is at most the night's total. It prints one line per rule with PASS or FAIL and the numbers, and names the plate and night on failure. The README records it failing once on a night broken on purpose in a way you describe, and passing after the repair.
Architectural guidance
A race shows only when two requests are in flight at the same time, so the proof needs separate clients running together against the real product. A single-threaded test cannot interleave two requests, and it passes while the product is still wrong. The kept wrong version matters for the same reason: a test that has never failed against a known bug may be asserting nothing. The consistency check states the portion rules in a form an operator can run, so a broken rule shows up in its output and not in a guest's complaint.
Architectural walkthrough
This Phase is the client's bad Saturday. Eleven portions of grilled octopus, four sellers, and fifteen orders. Each seller believed its own number, so every table was told yes until the kitchen ran out.
Two sellers that ask at the same moment are the first problem. Both see 1 portion left, both say yes, and one guest is told later that the plate is gone, usually after the table has ordered the rest of the meal around it. A handheld with no wifi is the second problem. It cannot ask anyone, so it cannot find out that the other sellers sold the portions it thinks it has, and it cannot stop selling either, because the terrace is full.
The bar's answer to the second problem is a rule about shares. The owner divides a limited plate's portions among the sellers, each seller sells only from its own share, and a share lasts 30 minutes. A seller that reports back returns what it did not sell. One that never reports leaves those portions counted as sold, because the product cannot know whether they were sold, and the bar would rather lose a portion than tell a second table yes to a plate that is gone.
Two facts reach a seller late: a plate sells out on another seller, and the chef calls an 86 (taking a plate off sale until she restores it) that an offline handheld cannot hear. Connected sellers must learn within 10 seconds. The handheld learns when it reconnects, and its orders from the offline stretch are then judged by when they were taken, so a table that ordered before the 86 keeps its plate and a table that ordered after loses it, whichever upload arrives first.
The last Checkpoint replays the Saturday. A test that runs one request at a time proves nothing here, because the failure only exists while two requests are in flight together.
Take payments and delivery orders
Produces split-check payments against a card-provider stand-in you write, delivery-app orders against a second stand-in, and tests that replay every outside message. Tips after capture, refunds, card payments taken offline and settlement with the delivery app are left out.
Acceptance criteria
You build a stand-in for the card provider that the product talks to, and that the test suite can start. It approves or declines a charge for a token and an amount, answers with the last four digits for an approval, and can show what it was asked and what it captured. Its message formats are yours, and you document them. Later Checkpoints make it fail on demand.
A request opens a payment for an order, with the order's total. Opening it twice returns the same payment. An order whose total is 0 settles at once with no parts. Once a payment is open, adding, voiding or comping a line on that order is refused.
For the T12 order with a total of 3450 cents, a waiter adds parts to the payment. Each part carries a part id the waiter's device makes, a tender (cash or card), an amount in cents, a tip in cents (card only) and a card token (card only). The answer shows the part's outcome, the last four digits for a card, and the amount still to pay. The parts arrive in this order:
- Cash 1000 cents is taken, and 2450 remains.
- A card part of 1450 with a tip of 150 is captured. The stand-in shows a charge of 1600, and 1000 remains, because a tip is not part of the total.
- A card part of 1000 with the stand-in's declining token is declined. 1000 still remains and the payment stays open.
- A new part with a new part id and a good token for 1000 is captured, and the payment is complete.
Sending a part with a part id that exists returns the first result, creates no second part and makes no second call to the provider. A part of 1100 when 1000 remains is refused because it exceeds the amount still to pay, nothing is stored, and the stand-in shows no call. A cash part with a tip, a part of 0 and a card part with no token are refused.
Reading the order shows its parts with tender, amount, tip, outcome and last four digits. When the parts that were captured add up to the total, the order becomes closed. Until they do, it stays open. A closed order refuses new lines, firing, voids, comps and a second payment.
The product stores a token and the last four digits only. A search of every file and store the product writes, logs included, for the test card number finds nothing.
Architectural guidance
A check closes when what was paid adds up to the total, because closing on the first payment hides a short check until the bar's evening count. The total is fixed once payment starts, since a void that changes it after a card was charged leaves money that no order explains, and refunds are outside this brief. A card number that lands in a log is a breach waiting for someone to read the log.
Acceptance criteria
The stand-in gains a fault you can switch on per token. It captures the charge, records it, and waits 10 seconds before answering. The product gives up on a call after 5 seconds.
For the T12 order, a card part of 1450 using the timeout token comes back after about 5 seconds with the part marked as unconfirmed. The part is neither captured nor declined, and the stand-in shows one capture for that payment. The product asks the provider again about the same payment, not as a new charge, at 10, 30, 60, 120 and 300 seconds after the timeout, until it gets an answer. The first ask is answered with the stored result, so the part becomes captured and the stand-in still shows one capture and two requests. Asking again after that changes nothing. If the provider answers declined on a retry, the part becomes declined and the held amount is released. After the fifth ask with no answer the part stays unconfirmed, reading the order marks it as needing attention, and no sixth ask is made.
While a part is unconfirmed, its amount is held. With 1450 held, a second card part of 2000 is accepted and a part of 2001 is refused because it exceeds the amount still to pay. The payment does not complete while any part is unconfirmed, and it completes when the last one is answered. A waiter who sends the same part id again gets the part as it stands, with no second call to the provider.
The provider also sends the product a notice when a late capture finishes. The product checks a shared secret that the notice carries and refuses a wrong secret, storing nothing. A notice about a payment the product does not know is acknowledged and changes nothing. The product's own repeat ask and the provider's notice can arrive in either order, and a test runs both orders and ends with one capture and one captured part each time.
A run in which your product is made to send a fresh charge after a timeout, as if it were a new payment, shows two captures at the stand-in for one part. The README records that count, and the run is then restored.
Architectural guidance
A timeout does not say whether the charge happened. Charging again as if it were new takes the money twice, and that is the Saturday the client described. Treating the timeout as a failure lets the waiter take a different payment while the first capture still stands. The amount stays held so the same 1450 cannot be paid twice with a fresh part while the answer is unknown.
Acceptance criteria
The stand-in can send the product a notice about a payment more than once, late, and in a different order from the one in which things happened. Each notice carries the time at the provider and the shared secret.
The stand-in sends the notice for one captured part several times, some of them at the same instant. The order shows one captured part, and the amount still to pay is reduced by the part's amount once.
A notice about a part arrives before the product has handled the answer to its own charge. The part ends captured once. A notice saying declined for a part that is already captured is ignored and the part stays captured. A notice saying captured that is older than a notice saying declined for the same part is ignored, and the later notice stands, whichever arrives first.
A notice for an unknown part is acknowledged and changes nothing. A notice with a wrong secret is refused and changes nothing. The order reads the same after each case, and the README lists the cases with the result of one run.
Architectural guidance
Providers do not promise to deliver in the order things happened, and they do repeat themselves. A late "declined" that overwrites "captured" leaves the bar with a guest who paid and an order that shows unpaid, and the next waiter charges again. A repeat that is counted twice reduces the amount to pay twice and closes a short check. The product must go by what the provider says happened first, not by what reached it first.
Acceptance criteria
You build a stand-in for the delivery app that the product talks to. It sends order messages to the product and receives availability news on its own address. Each message holds an id, an order reference, the time the guest placed it (UTC with milliseconds), the guest's name and phone, and lines of plate and quantity. The message format is yours, and you document how the product receives it. Faults you can switch on: send the same message twice, send a message after its 3-minute accept window, send a message for a plate that just sold out, and fail one availability push. The product checks a shared secret on every message.
The delivery app is the fourth seller. A manager gives it a share of 2 of the 12 octopus portions at 18:00:00Z, and it sells from that share with the same rules as the till: the same 30-minute end, the same report at zero and the same top-up.
The messages, with the product's clock set to when each arrives:
- M1 was placed at 18:00:00.000Z and arrives at 18:01:00Z, with 1 grilled octopus and 2 jamon croquetas. It is accepted. The product creates an order with a delivery-app source, a total of 2950 cents (1450 plus 1500), the app's order reference, and lines sold at the versions in force when it was placed. The order is in round 1 and fired, so the kitchen ticket shows it. It is closed at once, because the app collected the money. The app's share goes from 2 to 1.
- M1 sent twice leaves one order, one decision and a share of 1.
- M2 was placed at 18:00:00.000Z and arrives at 18:03:00.000Z with 1 marinated olives. It is accepted. M3 was also placed at 18:00:00.000Z and arrives at 18:03:00.001Z. It is rejected because the accept window passed. No order is created and no portion is taken.
- M4 asks for 2 octopus when the app's share is 1 and no portions are left to give out. It is rejected because the plate is unavailable. Its other lines are not ordered, and the share is still 1. A message for a plate that is 86'd or withdrawn is rejected the same way.
The decision on each message is readable by order reference as received, accepted or rejected, with the reason. An accepted order is placed and its portions taken together: an order that the product refuses leaves the share unchanged.
Killing the product after it acknowledged a message and before the order exists never leaves the app believing the order was accepted with nothing in the kitchen. After a restart the order exists exactly once, whether or not the app resends the message.
The product tells the delivery app a plate's availability within 10 seconds of it selling out, coming back, being 86'd or being restored. A push that fails is tried again after 2 seconds, up to 5 attempts, with the first push failing. Eighty-sixing a plate and restoring it within a second leaves the stand-in showing the plate available.
Architectural guidance
The platform decides when its messages arrive and how often, so exactly-once acceptance cannot be asked of the platform and has to be done on the bar's side. A message accepted twice sells the same octopus to two guests. A message accepted after its window sells food the app has already told the guest was refused. An availability push delayed by a retry must never overwrite a later state, or the app keeps selling a plate the chef has pulled.
Acceptance criteria
For the T12 order of 3450 cents, the last part is captured and the order closes, with the business night of the close time. Reading the order shows it closed once. The day's sales count the order once.
The product is killed right after the last captured part was stored and before the order closes. After a restart, the order is closed, exactly once, and it is not left open with a complete payment. A test kills the product at that point on every run and gets the same result.
The last part sent twice at the same instant leaves one closed order and one captured part. A closed order cannot be paid again, and a part sent for it is refused with nothing stored.
The README says, in plain words, what an operator sees if an order stays open after a complete payment, and how to find such an order.
Architectural guidance
The guest has paid and the check still shows open. The waiter does not know, the table is billed again, or the end-of-day close refuses to run because an order is still open. Closing twice is as bad: the day's sales count the order twice, and the Z report overstates the night. The crash window is short, so it will not show until the day it matters.
Acceptance criteria
The tests run the full product against the stand-ins. Each case states a number, and the README records the result of one run.
Provider cases, each on the T12 order of 3450 cents:
- The stand-in sends the notice for one captured part several times, some at the same instant. The order has one captured part, and the amount still to pay is reduced by the part's amount once.
- A notice arrives before the charge answer is handled. The part ends captured once.
- A timeout after capture is resolved by the product's repeat ask and by the notice in both orders, and the stand-in shows one capture each time.
- A late notice that says declined for a part that is already captured is ignored.
- A split check where one card part is declined and the retry succeeds ends with the captured amounts adding up to 3450 and one closed order.
- The last payment is recorded and the product is killed before the order closes, more than once, and every run ends with one closed order.
Delivery-app cases:
- Many clients post message M1 at the same moment. There is one order, one decision and one portion taken.
- A message the product acknowledged but never placed is posted again by the stand-in and ends with one order.
- With every other octopus portion sold and 1 left to give out, the till and the app each ask for a top-up of 1 at the same moment, over many runs. In every run exactly one gets it, the other is refused as sold out or unavailable, and the portions sold equal 12.
- A message that arrives after its accept window while the plate is also sold out is rejected once, with one reason.
The consistency check gains three rules. It fails when a payment attempt has two captures at the provider, when a closed order has captured parts that do not add up to its total, and when a part has been unconfirmed for more than 300 seconds. Each rule prints PASS or FAIL with the numbers it counted. The README records the check failing once for each rule on a night broken on purpose in a way you describe, with the offending order or part named, and passing after the repair.
Architectural guidance
A repeated message is only harmless if every effect of it holds up when repeated, and these cases try each effect once. The cases with many clients at the same moment matter most, since a check that works one request at a time passes in a single-threaded test and fails under load. A late message with older news must not overwrite newer news, because providers and platforms do not promise order. The consistency rules state the same claims in a form an operator can run on any day's data, so a double charge shows up in a report before it shows up in an email from a guest.
Architectural walkthrough
Two outside parties talk to the product, and both misbehave in ways real ones do. The failures are the client's double charge on a split check, and a delivery order that is accepted twice or sells a plate that is gone.
A card provider can charge a card and then fail to answer in time. The product cannot tell a charge that happened from one that did not, and both guesses cost money: charge again and the guest pays twice, give up and the bar may serve a meal it was never paid for. The provider can also send its news twice, send it late, or send "declined" for a payment it already reported as captured. A delivery app can send the same order twice, send it after its 3-minute accept window, or send it for a plate that has just sold out.
You write a stand-in for each party, because you cannot make the real ones misbehave on demand, and a failure you cannot trigger is a failure you have not tested. Each stand-in must be able to cause every behaviour named above, and the tests must run the product against them.
Last, a crash between taking the final payment and closing the order leaves a table that has paid and a check that stays open. Phase 5 reads everything this Phase produces. A payment counted twice or an order accepted twice shows up as a wrong total in the Z report, and it is cheaper to prove here that neither can happen than to find it on the bookkeeper's sheet.
Count the stock, close the day and prove it
Produces ingredient stock, the variance report, the day close with its Z report, erasure of a delivery guest, and a simulated Friday checked by a consistency check. Purchase orders, supplier invoices, prime cost and several sites are left for the next step up.
Acceptance criteria
Each ingredient has an opaque lowercase id such as potato. Its balance is what its deliveries, counts, waste and use add up to, and the product shows it. Every change to a balance is a record you can read, with its kind (use, delivery, count or waste), signed grams, the night it belongs to, the time it happened, when it was recorded and who decided. No request changes or deletes one.
Use the recipes patatas bravas at 250 g potato and 15 g olive oil, and grilled octopus at 180 g octopus and 12 g olive oil. Firing round 1 of the T12 order, with 2 patatas bravas and 1 grilled octopus, takes 500 g of potato, 42 g of olive oil and 180 g of octopus out of stock, each as one record with the round's business night. Firing the round again, a waiter's double tap, and the product's recovery after a crash all leave those three records.
The product is killed right after the fire was stored and before the stock changed. After a restart, each ingredient has been taken out exactly once, not zero times and not twice. A line voided before its round is fired adds no use. A line voided after its round was fired leaves its use in place and adds none. A comped line that was fired counts as made and keeps its use. A drink with an empty recipe adds none.
A delivery request names an entry id the device or till makes, an ingredient and grams (positive). A delivery of 2000 g of potato followed by the use above gives a balance of 1500. A second order that uses 1750 g takes the balance to -250 and the request is not refused, because a negative balance is allowed. A count request names an entry id, an ingredient and the counted grams, and needs a manager or an owner. A count of 1200 records +1450, so the balance is 1200, and records who counted. A waste request names an entry id, an ingredient, grams (positive) and a reason of 1 to 200 characters, needs a manager or an owner, and records a negative amount and who decided. A waiter is refused on a count or a waste and nothing is written. Sending a delivery, count or waste with an entry id that exists and the same content returns the first record and adds nothing, and with different content is refused.
The owner sets a cost for an ingredient in whole cents per kilogram, and only an owner may. A new cost is added and the earlier ones stay readable. Potato at 120, olive oil at 900 and octopus at 2200 are the costs used from here on. The cost recorded with a use stays as it was when a later cost changes.
Architectural guidance
Stock follows what the kitchen made, not what was ordered, because only a fired round consumes food. If a double tap or a retry takes the same potatoes out twice, or a crash between the fire and the stock change means they are never taken out, every Monday count looks short or long for a reason nobody can find. A balance that overwrites itself on a count hides the difference the owner most wants to see.
Acceptance criteria
The variance report takes a start and an end business date and lists the ingredients whose counted usage departs from the recipes by at least 3% of theoretical usage. For each ingredient the period runs from its previous count to its latest count dated at or before the end date. Theoretical usage is the grams of use records in that period, and waste is not counted in it. Unexplained variance is the negative of the difference the latest count wrote, so a positive variance means more was used than the recipes predict. Waste is already in the stock history, so it is not variance.
The answer gives each ingredient's id, the theoretical grams, the variance in grams (signed) and the variance percent to 2 decimals. It is ordered by the absolute value of the variance percent, largest first, with ties broken by ingredient id. The 3% threshold is compared before rounding.
Over one week with an opening count and a closing count for each ingredient:
- Squid: opening count 6000 g, deliveries 8000 g, theoretical use 10,000 g, waste 200 g and a closing count of 3100 g. The balance before the count is 3800, the count writes -700, and the variance is +700 g, 7.00%. It is listed first. This is the pen count that showed a week of short squid.
- Olive oil: theoretical use 8000 g and a count that writes +500. The variance is -500 g, -6.25%. It is listed second.
- Potato: theoretical use 20,000 g and a count that writes -600. The variance is +600 g, 3.00%. It is listed third, because the threshold is at least 3%. With a count that writes -599, the variance is 2.995% and potato is not listed.
- Octopus: theoretical use 7200 g and a count that writes -60. The variance is 0.83% and octopus is not listed.
An ingredient with no earlier count has no period and is listed separately as not countable, with the reason that it has no opening count. An ingredient with theoretical use of 0 and a non-zero variance is listed with a variance percent that is empty. The report changes when a later count arrives and when the end date moves. Voids after a fire leave the theoretical figure as it was.
Asking for the same period twice, and asking after the product has been restarted, gives the same list.
Architectural guidance
Theoretical usage is what the recipes predict from what was sold, and the count is what the shelf shows. The difference is the number the owner cannot see any other way: portion drift, waste nobody wrote down, a delivery short on the scale. Ordering by percentage and not by grams stops a bag of flour from hiding a few grams of saffron. The 3% threshold is the brief's choice so that the criteria can be checked, and a bar with different margins would set another.
Acceptance criteria
For each business night the product reports sales (the sum of closed order totals), orders closed, covers, voids, comps, tenders, tips, food cost, and delivery-app orders accepted and rejected. Each fact is counted on its own business night.
Food cost is the sum over the night's use of grams times the cost per kilogram recorded with that use, divided by 1000 once and rounded to the nearest cent, halves away from zero.
On Friday 11 Jun 2027, order A (3450 cents, 2 covers, paid in cash 1000 and cards 1450 and 1000 with a tip of 150), order B (2100 cents, 3 covers, one card part) and order C (1250 cents, 1 cover, cash) close. One void and one comp were recorded on drink lines with no recipe. Round 1 of order A used 500 g potato, 42 g olive oil and 180 g octopus at 120, 900 and 2200 cents per kilogram. The figures are 6800 sales, 3 orders closed, 6 covers, 1 void, 1 comp, 2250 cash, 4550 card, 150 tips and a food cost of 494 cents. That is the cost of the one round with recorded stock use, not a share of the 6800 in sales, because the other lines in the sales carry no recorded use.
Closing a business day needs a manager or an owner. It is refused for the current business night, because the night is not over. It is refused when any order of that night is still open, and the answer lists each open order's id and table label. Once every listed order is closed, the close succeeds and issues the Z report with the night's totals. Closing again returns the same report. Without anyone asking, the product tries to close the night that just ended at each 04:00 cutoff, and when that is blocked it records the open orders where the Z report for that date shows them as not closed.
Reading the Z report for a date returns the report as issued, when it was issued and a list of corrections. The report is never recomputed after it was issued.
A handheld uploads at 05:10 on 12 Jun 2027, after the close, an order taken at 11 Jun 2027, 23:50 UTC with 2 covers. It belongs to 11 Jun 2027, because 23:50Z is 01:50 local. The product records a correction for that date with a difference of +2 covers. The issued report still shows 6 covers, the list of corrections holds the difference, and the daily summary for the date shows 8. When the order is paid on 12 Jun 2027, its sales land on 12 Jun 2027.
An operator can ask for the figures, for any date, recomputed from that night's orders, payments and stock records. For a closed date they equal the issued report plus its corrections. Running it twice gives the same figures, and two facts that arrived in the opposite order from the one in which they happened give the same figures as in the right order. The operations note says how to use it.
Architectural guidance
A Z report that changes after the owner checked it against the bookkeeper's sheet stops them trusting any figure from the bar, so a late fact has to appear as a visible difference that names what changed. Closing a night while a table is still open turns that table's takings into a correction on the next day. A report that cannot be recomputed from the day's records cannot be checked when the owner doubts it.
Acceptance criteria
Use the test guest "Test Guest" with the phone "+31 6 12345678" on an accepted delivery order with the app's order reference P-4471, placed on 11 Jun 2027. An erase request for that guest, by order reference, needs a manager or an owner and is refused for a waiter. While 11 Jun 2027 is open, the request is refused because the day is not closed, and nothing changes. After the day closes, it succeeds.
The erasure clears the name and phone everywhere the product holds them, including the saved copy of the original message, and records the time and who erased. The delivery order shows no guest, the erase time and the staff id. Asking a second time succeeds with the same erase time and changes nothing. A reference that is unknown, or that belongs to a till order, is reported as not found.
After the erasure, a search of every store, log, saved copy of a failed message and file the product keeps for "Test Guest" and for "12345678" finds no match. The delivery-app stand-in's own files are outside the product and are not searched. A test posts the original message again, with the same message id, and the product acknowledges it, keeps nothing from its body, and the name does not return. The product logs no request bodies.
The order and the stock records its fired round wrote stay. The delivery app collected the money, so the order has no payment. The number of orders, payments and stock records, the order's total of 2950 cents and the order as read are the same before and after, with the app's order reference P-4471 still shown. The issued Z report for 11 Jun 2027 is unchanged, and the recomputed figures are the same.
The README holds one paragraph on retention. It says that the product erases a guest on request after the order's business night is closed, that the bar must keep its business records for 7 years under Dutch rules (Belastingdienst), so orders, payments and stock records stay by ID, and that a guest's name and phone are not part of what that rule requires.
Architectural guidance
Erasure works only if the personal data was kept in a small number of places from the start. A name that was copied into a log line, a saved message or a note about a failure can no longer be found when a guest asks to be forgotten, and the bar then holds data it said it removed. The erase waits for the closed day because the bar may need to phone the guest during service, and everything the books need after that is identified by ID.
Acceptance criteria
A simulator plays Friday 11 Jun 2027 against the running product. It moves a clock that the product reads, makes everything the product does over time happen on the simulated schedule, and takes a seed, so two runs on freshly installed copies with the same seed give the same counts and totals. It plays the till, handheld 1, handheld 2, the delivery app and the provider's faults. The README gets a reviewer from a fresh clone to the finished run in 20 minutes and states how long the run takes.
The day holds 90 covers and 300 order lines: 40 covers at the till, 18 on each handheld and 14 through the delivery app, which is 15.6% of covers. Doors open at 18:00 local and orders stop at 02:00. At opening the 12 octopus portions are given 4 to the till, 3 to each handheld and 2 to the app, and every seller tops up on demand. These happen during the run:
- Handheld 1 loses its connection for 40 minutes from 21:00 local, keeps selling from its share, and uploads its orders in an order that differs from the order they were taken.
- The chef 86s cured tuna belly at 21:15 and restores it at 21:45. Handheld 1 was given a share of 2 tuna at 20:55 and sells one at 21:20 while offline, and the merge voids it automatically and records one conflict.
- One card part times out after capture and is resolved, and one card part of a split is declined and paid again.
- The delivery app sends one message twice, and one message after its 3-minute accept window.
- A manager voids one line after its round was fired.
- Every order is paid and closed before 02:30. The night closes at 04:00 and the Z report is issued. At 09:00 on 12 Jun 2027 a manager counts every ingredient that has records.
The simulator writes a results file that you commit to your repository. It lists covers (90), order lines (300), orders by source, portions sold for each limited plate, orders refused as sold out, the conflict count (1), parts declined (1), unconfirmed parts resolved (1), duplicate delivery-app messages ignored (1), delivery-app orders rejected (1, because the accept window passed), the Z report totals and the top of the variance list.
An operator can run a consistency check that prints PASS or FAIL for each of seven rules with the numbers it counted, names the offending ids on a failure, and exits non-zero when any rule fails. The rules are:
- For every limited plate and night, what was sold is at most what was given, and what was given is at most the total.
- No payment attempt has two captures at the provider.
- No closed order has captured parts that do not add up to its total.
- No part has been unconfirmed for more than 300 seconds.
- Every fired round has taken each ingredient in its recipes out of stock exactly once.
- Every ingredient's balance equals its deliveries, counts, waste and use added up.
- For each closed date, the issued Z report plus its corrections equals the figures recomputed from that night's records, and the issued report is unchanged.
After the Friday, all seven rules print PASS. Then the README records two planted failures. The product is killed after one round was fired and before its stock changed, which makes the rule on stock use FAIL and name the order and round, and the recovery in the operations note makes it PASS. One figure the product reports for a closed night is made wrong on purpose, in a way the README describes, which makes the last rule FAIL and name the date and figure, and the recovery makes it PASS.
The Z report for 11 Jun 2027 shows 90 covers, and its sales equal the sum of the totals of the orders closed on that night. The whole test suite and the consistency check exit 0.
Architectural guidance
Each earlier Phase proved one failure alone, and a simulated day finds the failures that only appear together, such as a handheld's late order meeting a chef's 86 while a card part is unconfirmed. The consistency check states in one run what the Phases promised, so a broken promise fails a command and does not wait for a bookkeeper to notice. The killed process in the stock rule is the crash window from Phase 2, shown once with a real symptom: a fired round with no stock change. A seed and a simulated clock make the run repeatable, which lets a reviewer compare their results file with the committed one.
Architectural walkthrough
The failures here are a Monday count nobody can explain, a Z report that changes after the owner checked it against the bookkeeper's sheet, and a guest's name that cannot be removed because it was copied into places nobody remembers.
Ingredient stock is a different kind of number from a limited portion. A portion is a promise and has to be right at the moment of sale. Stock follows what happened and is corrected by counts. A fired round takes ingredients out, a delivery adds some, and a count says what the shelf really holds. Between counts the balance may be wrong, even negative, and that tells the owner something: more went out than came in on paper, so a delivery is missing or portions are bigger than the recipe. If a fired round is counted twice, or not at all, every Monday count looks short or long for a reason nobody can find.
A Z report is the end-of-day sales summary. Once the day closes and the owner has checked it against the bookkeeper's sheet, a fact that arrives later, such as a handheld that uploads at 05:00, cannot change it. It has to appear as a visible difference that names what changed, or the owner can never again trust a filed figure.
A delivery guest's name and phone are personal data. The bar must erase them on request while the order, the payment and the stock records stay, identified by ID. If those values were copied into a log, a saved message or a note about a failure, the erasure leaves traces that nobody finds.
The final Checkpoint plays a whole Friday with every failure from the earlier Phases happening on the same night, then runs the consistency check. Failures that are harmless alone, such as a late card answer during a handheld merge, are what fills a Friday with surprises.
Architectural walkthrough
Four sellers, one number
The client's bad Saturday had eleven portions of grilled octopus and fifteen orders. The till, both handhelds and the delivery app each held their own copy of the number and subtracted from their own copy. Nothing could say how many portions existed, because four places each believed a different answer. Four tables had to choose again, and each of them had already been told yes.
An offline handheld makes it harder. It cannot ask anyone, yet it must not stop selling for forty minutes, and it must not sell what the other sellers have already sold. A sold-out plate also has to reach the other sellers fast. The bar promises 10 seconds, because every extra table told yes to a gone plate is a re-order and a bill adjustment. Check your build with fifteen orders arriving at once and read the count.
A charge that may or may not have happened
A card reader that times out does not say whether the card was charged. If the till charges again to be safe, the guest pays twice, which is how last Saturday's guest found out, by email. If it does not charge again, the bar may serve a meal it is never paid for. The same doubt applies to every outside message. The delivery app may send an order twice. The provider may send "declined" after it sent "captured". Check what each repeated, late or out-of-order message does to the totals.
Stock that is allowed to be wrong
The last portion of a plate is a promise to a guest and has to be right at the moment of sale. Ingredient stock is a running estimate that nobody checks until the weekly count, so it drifts, and a plate runs out mid-service with nobody warned. The count is where the owner sees the drift, and the pen count that showed a week of short squid shows what the owner loses without it: she cannot tell portions that grew from a delivery nobody entered.
The night is not the calendar date
The owner closes at 04:00 and reads takings per night. An order rung at 01:30 on Sunday belongs to Saturday's night, and twice a year the clocks change in the middle of that stretch. An owner who checks a Z report against the bookkeeper's sheet and sees it change afterwards stops trusting every other figure, so a late fact has to show up as a visible difference and never as a quiet edit.
A crash between two steps
A process can die after a payment is saved and before the order closes. It can die after a round is fired and before the stock reflects it, or after a delivery-app message was accepted and before the order exists. The first leaves a table that has paid and a check that stays open. The second leaves Monday's count short for ingredients the stock never recorded as used. The third leaves the app believing an order was accepted that the kitchen never received. Kill the product at each of these points and look at what the owner would see.
Where it shows if you cut a corner
If sellers keep their own copy of the count, the fifteen simultaneous orders in Phase 3 sell more than eleven portions. If a retry is treated as a new payment, the split check in Phase 4 charges a card twice. If the sum of what was paid is not checked against the total, a short check closes. If the Z report is computed from the calendar date, the simulated Friday puts the 01:30 takings on the wrong night, and the consistency check reports a closed day that differs from its issued report.