Stock Loja disc

Stock Loja

TypeScript project · featured · web app, Postgres, TypeScript

A stock app for PTDF's branded stores at Lisbon Airport: every size on the shop floor and in two stockrooms, sales by barcode, and six stores in one database that never see each other's data.

Open it in the console Resume (PDF) LinkedIn
The stock, in the Calvin Klein look
The stock, in the Calvin Klein look
One product: every size on the floor and in both stockrooms
One product: every size on the floor and in both stockrooms
An exchange with a 20% discount
An exchange with a 20% discount
Questions and shift handovers
Questions and shift handovers
Management: the six stores side by side
Management: the six stores side by side

The problem

Stock in the airport stores lived on paper and in Excel. Nobody knew how many of a size were on the shop floor or in the stockroom without going to count, so a size could sell out on the floor while boxes of it sat downstairs. I built an app the staff can use on the shop's iPad and on their phones, for every brand PTDF runs at Lisbon Airport, with nothing to install from a store.

What I built

The hard part

Never selling the last unit twice. With several devices in one store and airport Wi-Fi that drops answers, two things went wrong in testing: two tills sold the same last unit at once, and a sale was recorded twice when its answer got lost and the device tried again. Every stock change now runs in a Postgres function that locks the size's row, checks the quantity and writes the movement in one transaction, so one of two simultaneous sales is refused; batches lock their sizes in a fixed order, so they can never wait on each other. Each operation also carries a request id the server remembers, so a repeat returns the first result instead of selling again. A load test runs 12 devices for 30 s on the same 16 sizes, sending 15% of requests twice, and checks that every size's history is one unbroken chain.

What it looks like

$ npm run e2e:load
12 devices × 30 s on 16 sizes
operations: 22648 (754.9/s), recorded 15996, refused for lack of stock 6652
latency: median 11 ms, p95 44 ms
✓ every operation recorded exactly once, repeats included (43286 = 43286)
✓ each size's history is one unbroken chain (0 breaks)
✓ final stock = opening + all movements, never negative
✓ no deadlocks, timeouts or other errors

Built with

More projects