Short write‑ups of problems we hit running a real commerce operation and what we changed in the code because of them. No product announcements; just the reasoning.
A million invoices and fifty thousand credit notes, and the rule that governs all of them: an invoice is a frozen picture of an order at the moment it was billed, and nothing that happens later — a price change, a tax change, a product rename — can move it. How invoices are minted from orders, how credit notes reference the lines they return, how a paid status is derived rather than set, how invoices are categorised for the accountants, and how a PDF, an e‑invoice and an export all read from the same rows.
Weighted average cost and FIFO computed in one pass over the movement history, a group-level switch that decides which one is "official", and why LIFO is deliberately missing.
Selling across Europe and the UK means every order has to answer one question before a price is final — and the answer depends on two addresses, a postcode, and whether a VAT number is real. How aiku validates tax numbers against VIES and HMRC (with retries, rate limits and an audit trail), and the decision tree that turns a shipping address into a tax category, Canaries and Madeira included.
For years every line we sold carried the same VAT rate, so one rate per order was simply true. Then the range grew to include tea — zero‑rated in one market, reduced in another — and "which rate" became a question per line. The answer was not "read the product's tax code": it was presets instead of codes for staff, tax versioned like price on the historic line, frozen once sold, and a migration that re‑rated the open baskets to the penny.
A card payment arrives three ways at once — the browser says "done", the redirect says "done", and a webhook says "captured" — and only one of them is money. The payments layer we built this summer: server‑verified status, one processing path, locked idempotency, a recoverable state machine, a gateway log for every event, a sweeper, and a playbook that made the next provider a week's work.