Skip to content

Build a Two-Room Stock and Order Book

Davor Minchorov•Beginner•1 to 2 weekends•October 29, 2026

A one-person candle shop keeps its stock in a spare room and a friend's garage, and once sold the same gift set twice. You will build the small order book that counts both rooms, takes an order only when every line can be filled, and tells the owner what to make next.

The brief

The client

I make candles and small ceramic dishes and sell them online, about ten orders on a good day. I keep the stock in two places: the spare room in my flat and my friend Ilija's garage, where the big batches go. The counts live in a notebook and a spreadsheet, and I update them when I remember.

Once I sold the last "Winter Set" twice, because I had already packed one for a market stall and never wrote it down. I spent an evening apologising to a customer by email. I want one small tool that knows how many of each thing I have in each place, takes an order only when I can fill all of it, and tells me what to make next.

The problem

Stock counts live in two places and a notebook, so no single number says how many of a product can be sold. An order is accepted without a check, and the shortfall is found when the parcel is packed. That costs an apology and sometimes a refund.

The owner also does not know which products are running low until a customer asks for one. She makes everything by hand, so a product that runs out stays out until she has time to make more.

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

  • Add products with a price and a reorder level, and record how many units of each sit in the spare room and in the garage.
  • Change a product's price. Orders already placed keep the price they were placed at.
  • Show, for any product, its count in each room and its total across both.
  • Place an order of one or more lines, and take the units from the spare room first and from the garage for the rest. If the same product appears on two lines, the lines are checked together.
  • Look up one order, and list all orders.
  • Refuse an order that cannot be filled in full, say which product is short and by how many, and change no count.
  • Cancel a placed order and put each unit back in the room it came from.
  • List the products whose total across both rooms is at or below their reorder level.
  • Keep every count and order after the program is stopped and started again.

Deliverables

  • A product that starts with one documented command. The owner can use it through whichever interface you chose: a web page, an HTTP API that other programs call by sending requests, or a command-line tool.
  • A README that gets a reviewer from a fresh copy of your repository to a refused order, a split order and a cancelled order in 10 minutes.
  • A short note of the shop's stock rules with three hand-worked example orders.
  • Automated checks, code that drives the product and compares its answers with what you expect, that a reviewer can run with one command, covering the edges of the order rule.
  • A way to replay one week of orders with a time supplied for each, and the hand-worked table of expected results it is compared against.

Out of scope

  • Two people ordering the last unit at the same moment. One person uses the tool at a time here. The next project up, Build a Two-Location Online Shop, takes on the last-unit race.
  • Taking payment or refunding. An order records a total in cents and nothing more, because payment would add rules that teach nothing about stock.
  • Shipping, parcels and returns. An order is either placed or cancelled; shipping part of an order or receiving a return is a later problem.
  • Customer details such as names, addresses and email. They would add forms and rules that teach nothing about stock.
  • Logins and user accounts. One person uses the tool on one machine. Do not put it on the internet: with no login, anyone who can reach it can read the orders and change the stock.
  • A search page or a shop front. The owner enters orders herself.
  • Moving stock from one room to the other. Setting the two counts by hand is enough.
  • More than two rooms, or choosing the room by distance or cost. The order of rooms is fixed, so the rule can be checked.
  • Running on more than one machine, or as a hosted service. One person uses it on one machine, so the stock rule is the whole project.

Architectural constraints

  • Amounts are in euro and exact to the cent. A price, a line price or an order total is never a fraction of a cent.
  • Every time shown carries its time zone, or is shown in Europe/Amsterdam. The person or the request can supply the current time, so a reviewer can place an order at 00:30 without waiting for midnight. This exists for testing.
  • A refused order changes nothing: no count, no order.
  • A count never goes below zero.
  • A quantity is a whole number of units greater than zero.
  • An order shows the price per unit it was sold at and how many units on each line came from each room, and that stays the same after later price and count changes.
  • Counts and orders survive stopping and starting the program.

Prerequisites

You can write a small program in a language of your choice and have saved data to a database or a file once. You do not need to know any framework, and you do not need to have written automated tests. You do not need to know how a home maker keeps stock in two places; the first Phase explains the business and the words the brief uses. Having kept track of anything in a spreadsheet and watched it drift from reality will make the problem familiar.

Create a free accountSign in

Free to start. An account is what keeps track of the checkpoints you finish.

Phase 1

Write the rules and count the stock

Produces a one-page note of the shop's stock rules and a program that holds products with a count in each room, shown per room and in total. Leaves orders for the next Phase.

Research

Implementation

Implementation

Architectural walkthrough

How a home maker keeps stock in two places

A maker of candles and small ceramic dishes sells her work online, about ten orders on a good day. She makes everything by hand, so a product that runs out stays out until she has time to make more. Her stock sits in two places: the spare room in her flat, which holds about 30 units, and a friend's garage, where the big batches go.

An order can name several products, and a customer expects all of it or none of it. One of her products is the Winter Set. Each product has a price and a reorder level, the count at which she wants to make more. She wants to know at any time how many of a product she can sell, and which products are running low.

The words this brief uses:

  • Product: one thing she sells, with a price and a reorder level.

  • Room: one of the two places stock is kept, the spare room or the garage.

  • Count: the number of units of a product in one room.

  • Total: a product's count in both rooms added together.

  • Order line: one product and a quantity inside an order.

  • Reorder level: the total at or below which she wants to make more.

  • Short: not enough units to fill an order line.

Why the rules go into a note first

Before the program exists, the rules go into a note with numbers in it. If "filled in full", which room is used first and what a cancel does live only in the owner's head, each gets decided differently every time it comes up, and the client finds the difference when a count is wrong. The three worked examples in the note come back later as the first automated checks, so the effort is not spent twice.

The shop's numbers first go wrong in three plain ways: a total that disagrees with the rooms, a price that drifts by a fraction of a cent, and stock forgotten on a restart.

Counts are plain numbers here and the room sizes are not enforced. The spare room holding about 30 units is a rough size, not a limit for the program to police.

Phase 2

Take orders that cannot oversell

Produces placing an order that takes stock from the right room and refuses one that cannot be filled in full, with automated checks on the edges of that rule. Leaves cancelling and the reorder list for the next Phase.

Implementation

Implementation

Implementation

Testing

Architectural walkthrough

This Phase has to survive an order that cannot be filled in full: a covered first line followed by a short second line, or one product on two lines whose combined quantity is more than the stock.

Afterwards the order must still show where each unit came from, what it sold for and when it was placed, in a time that carries its zone. The Phase ends with automated checks on the edges of the rule.

Phase 3

Cancel, restock and prove a week

Produces cancelling with each unit returned to the room it came from, a list of products to make next, and a repeatable replay of a week of orders checked against a hand-worked table. Leaves payment and shipping out.

Implementation

Implementation

Testing

Architectural walkthrough

Cancelling has to undo exactly what placing did, once, however often it is asked. The reorder list has to be right at the moment the owner looks.

The last Checkpoint replays a week against a table worked out by hand before anything runs.

Architectural walkthrough

An order is filled in full or not at all

The client's trouble was selling the last Winter Set twice. A notebook cannot refuse anything, so the shortfall surfaced when she packed the parcel and ended in an apology. The product has to refuse an order it cannot fill in full, and it has to do that without costing her stock she still holds.

A refused order that still takes stock

An order can have a covered first line and a short second line. If the units of the first line leave the count before the shortage on the second line shows, the order is refused and the candles have still vanished from the spare room. The counts are then lower than the shelves, which is the notebook problem again, with no order to explain the difference.

The same hole opens when one product appears on two lines. Three Winter Sets on one line and three on another each look fine against five in stock, and together they want six.

Cancelling into the wrong room

A cancelled order has to put units back on the shelf they were taken from. If everything goes back to the spare room, its count rises above what the shelf holds and the garage count falls below its shelf. The next order then promises units from a room that has none, and she finds out while packing.

Cents, prices and midnight

A total that is one cent off cannot be explained to a customer, and amounts like 0.1 + 0.2 do not add up exactly in most languages. Changing a price today must not rewrite last week's orders, or her records stop matching what customers paid. An order placed at 00:30 on the 6th in Amsterdam is still the 5th on a server in another zone, so a day's orders land in the wrong day unless every time shows its zone.

Where it shows if you cut a corner

A week of orders, worked out by hand before the run, shows what the earlier Checkpoints missed: counts a few units off after the refused orders, units back on the wrong shelf after a cancel, or old orders that changed when a price did. A table copied from the program's own output would agree with the program even where it is wrong.

The next project up in this domain is Build a Two-Location Online Shop. It keeps this rule and adds what happens when two people order the last unit at the same moment.