- Architecture
- PostgreSQL
- E-commerce
Keep prices and stock on the server
In SAFFRON HOUSE and Sportswear Warehouse the browser never decides what something costs or how much is left. Here is why that boundary matters.
When I built SAFFRON HOUSE, a complete restaurant platform on one PostgreSQL database, the tempting shortcut was to calculate the cart total in the browser. The menu is already there, the discount rules are simple, and the UI can show a number instantly. That shortcut breaks the moment two people order the last item at the same time, or a coupon is applied twice, or someone edits the request before it is sent.
The browser can display a price. It should never be the thing that decides it.
One transaction, not three writes
In SAFFRON HOUSE, prices, discounts and loyalty are all calculated on the server, and ordering, stock and coupons run inside a single transaction. That means the order row, the stock decrement and the coupon redemption either all happen or none of them do. There is no window where a customer has paid for something the kitchen cannot make.
The same principle shaped Sportswear Warehouse, an inventory and stocktake ERP for t-shirts and sportswear. There, an atomic movement log is the single source of truth. Every receipt, issue and adjustment is a movement, and the current stock level is derived from that log rather than stored as a number someone can quietly overwrite. Physical stocktakes require manager approval before they change anything.
What the interface gets to do
Moving the rules to the server does not make the interface less useful. It makes its job clearer. The client collects intent, shows the server's answer, and renders the state it is given. In SAFFRON HOUSE that means the customer store, the thirteen-page admin dashboard, and the kitchen, cashier and delivery screens all read the same numbers from the same place.
- Validate the request on the server rather than trusting values assembled by the UI.
- Calculate prices, discounts and stock inside the same transaction that writes the order.
- Derive balances from an append-only movement log instead of a mutable counter.
- Require an explicit approval step before a physical count changes recorded stock.
The payoff is not elegance for its own sake. It is that when a number is wrong, there is exactly one place to look, and the answer is the same for every screen that shows it.