Skip to content
Selected work

Full-Stack Engineering / Distributed Systems / Inventory Optimization

Inventory & Retail Operations Platform

Building reliable inventory operations across independently connected stores.

The production platform a chain of automated retail stores runs on: warehouse stock, replenishment, purchasing and reporting, kept correct even when store databases go offline.

Rack layout for an offline store opened from its last known data, with inactive positions holding unitsIllustrative
Interface recreation · synthetic dataInterface recreation based on the production application, using synthetic data.
On this page
  1. 01The project
  2. 02The problem
  3. 03Inside the platform
  4. 04How I solved it
  5. 05Behind the engineering
  6. 06Impact and reflection
01

The project

The system a retail chain runs on.

  • The challenge

    13 unattended stores, each with its own database, any of which can drop offline at any moment.

  • What I built

    Most of the platform, including the restocking forecast, offline-safe deliveries to stores, warehouse and purchasing workflows, and financial reports.

  • The outcome

    In production as the business's main operations system, used every day to run the stores.

What I worked on

As an AI Engineer at Unistop Tech, I developed the majority of the platform's functionality, spanning inventory operations, replenishment, backend workflows and operational reporting. I designed and built the replenishment forecast, the offline store-delivery pipeline, the snapshot sync service and the financial reporting logic. The repository has another contributor, whose work was mainly early interface and position-management screens.

  1. Full-stack application

    React screens and the Express API behind them, from top-up planning to purchasing and sales reports.

  2. Backend business logic

    Service-layer workflows in raw, parameterized SQL with explicit transactions and row locks.

  3. Replenishment forecasting

    The statistical demand estimate and the reorder-point and target policy behind every top-up list.

  4. Synchronization and delivery

    The durable per-store write queue, stock deltas, idempotent application at the store, and the separate snapshot sync service.

  5. Warehouse and purchasing

    Batches with expiry, first-expiry-first-out reservations, purchase orders and goods receiving with landed costs.

  6. Reporting and data integration

    Sales and profitability reports, cost-of-goods from a frozen cost ledger, and revenue allocated from what was actually charged.

  7. Operational interfaces

    Delivery-state badges, stale-data notices and conflict messages, so staff can see what each store will have.

02

The problem

Every store keeps its own records, and any store can go offline.

Each automated store runs its own database, which holds the truth about its shelves and sales. Head office reaches those databases over a private network, and any store can be unreachable at a given moment.

The platform still has to show stock across every store, plan restocking, run the warehouse and purchasing, and report on sales, without ever corrupting a store's stock count.

Office

Management platform

Office DB · snapshots · outbox

  • Store A · own MySQLreachable
  • Store B · own MySQLreachable
  • Store C · own MySQLunreachable
  • Store D · own MySQLsnapshot 3 h old
Simplified sketch with generic names. Each store keeps the source of truth for its own shelves; the office works from cached snapshots and live reads.

What could go wrong

  • 01Head office may be looking at stock figures that are hours old.
  • 02A change sent to a store can fail halfway through.
  • 03Sending the same change twice could add stock that doesn't exist.
03

Inside the platform

One place to run every store.

Interface recreation · synthetic data
Stock positions, store offlineEvery shelf position in a store. When a store is offline, it opens from its last known data and says so.
Top-up recommendationsEach recommended delivery, with the numbers behind it: what's on the shelf, the target and the warehouse stock.
Warehouse inventoryWarehouse stock and warnings, with every store's sync status in view.
SalesSales and revenue by product and store, reconciled to what customers actually paid.

More screens

Store-wide monitoringTemperature, cameras and today's sales for each store.
Top-up planningRestocking lists per store, with stores whose data is out of date flagged.
PurchasingPurchase orders tracked from order to receipt.
04

How I solved it

Three problems, three guided demos.

The three hardest problems are below, each as a short guided demo with made-up data. Start with the question, step through it, and open the technical mechanism if you want the detail.

Problem 1

What happens to a stock update when a store is offline?

A delivery to a store can't simply be sent and forgotten: the store may be unreachable, and a message may get lost on the way back.

Guided demonstration with made-up data, simplified from the production logic.

Step 1 of 5

Store C goes offline

Store C's connection drops. Its shelf holds 3 units of Product A, and it keeps selling on its own.

Head office

Deliveries for Store C

Nothing to send yet

Offline

Store C

Product A on the shelf

3of 12

Explore the technical mechanism

When a top-up is completed at the office, the units still have to reach the store's database, and the store may be unreachable. Writing to the store inside the request would lose the change whenever the store was down.

So completing a top-up writes the stock changes and a delivery job into the office database in a single transaction: a completed list can never exist without its delivery job. A background worker drains each store's jobs in order. If a store is unreachable, the job stays pending, later jobs for that store wait behind it, and retries back off exponentially.

The changes travel as deltas, "+4 to position P-12", not as final quantities. A delta stays correct however long the store was offline and however much it sold in the meantime; a final quantity computed at the office would overwrite those sales.

The hard case is a lost acknowledgement: the store committed the change, but the office never heard back and retries. The store applies each job inside one store transaction that also records a marker keyed by the job's id. A retry that finds the marker settles the office side from the recorded plan and leaves stock alone. Delivery is at-least-once; the stock effect is exactly once, because applying a job is idempotent. There is no distributed transaction across the two databases.

Interactive technical demonstration. Synthetic and simplified; not the production system or its data.

Office database · outbox for Store C

Empty. Complete a top-up to queue a delivery.

Store C database · unreachable

P-03
5
P-07
2
P-12
3

Applied-job markers

None yet

Event sequence

Try this: complete a top-up while the store is offline, run the worker, bring the store back with a lost acknowledgement, then run the worker twice.

Stock effects per delivery

0

Most times any one delivery changed store stock. 0 jobs pending.

How a delivery is applied at the store

  1. 1Lock the office delta rows for the job. Edits to a pending delivery take the same locks in the same order, so the two can't interleave.
  2. 2Open a store transaction and look for the job's marker.
  3. 3Marker found: the store already committed. Settle the office from the plan stored in the marker and stop.
  4. 4Otherwise lock the live store positions and plan the placement against them.
  5. 5Update each position, checking that exactly one row changed.
  6. 6Insert the marker in the same store transaction, then commit.
  7. 7Settle the office rows and commit. A crash between the two commits resolves correctly on the next retry.
  8. 8Units that can't be placed are recorded as issues for follow-up, never dropped silently.

Problem 2

How does the system decide how much stock a store needs?

Each restock, it estimates demand from recent sales and fills the shelf to last until the next visit. Pick a scenario to see what changes.

Guided demonstration with made-up data, simplified from the production logic.

Recommended top-up

+21units

On the shelf
2
Demand a day
3.0
Fill to
23

Customers couldn't buy this product on 50% of days because it was out of stock, so recorded sales understate demand. The system estimates 3.0 a day instead of the recorded 1.5.

Without the stockout correction it would recommend +12.

1.5 a day
50%
3 days
Advanced settings
none
2 units
30 units
95%
1.50× steady
View calculation

demand μ = (everyday 1.50 + min(basket 0, 4) / 14) × min(1 / in-stock 0.50, 2) = 3.00 a day

variance σ² = max(swing 1.50, 1) × μ = 4.50 · z(95%) = 1.64

reorder point = ⌈μR + z√(σ²R)⌉ = 16, R = 3 days

target = ⌈μP + z√(σ²P)⌉ = 23, P = R + 2 = 5 days, capped at shelf 30

top-up = target 23 − shelf 2 = 21

A simplified demonstration with illustrative values. The production calculation also blends several sales windows, sets the service level by demand band, and limits the list by warehouse stock and trip capacity. It is statistics and rules, not machine learning.

How the production forecast works

A plain average of past sales underestimates demand for exactly the products that matter most. If a product sold out on Thursday and stayed empty until Monday, those days recorded zero sales: not because nobody wanted it, but because there was nothing to buy. Dividing by calendar days bakes the stockout into the forecast, which then orders too little, which causes the next stockout.

The forecast blends several sales windows, weighting recent ones more, and divides each window's sales by the days the product was actually in stock, measured from hourly inventory history. The correction only applies when enough days were observed, and its uplift is capped, because availability sampling is imperfect.

One-off bulk purchases are capped per transaction unless a product shows recurring bulk demand, so a single large basket doesn't inflate the forecast. Variance is never assumed lower than a Poisson process, so slow sellers still get safety stock.

From there it is a periodic-review policy: a reorder point that covers demand until the next visit at a chosen service level, and an order-up-to target covering the visit interval plus a buffer, bounded by shelf capacity. Products are banded by demand, and each band has its own service level. The list is then limited by warehouse availability and by how many units a trip can carry, with the most urgent products filled first.

This is classical statistics and rule-based optimisation, not machine learning.

The production calculation, step by step

  1. 1Estimate daily demand from several weighted sales windows.
  2. 2Correct each window for stockouts by dividing by in-stock days, with coverage and uplift guards.
  3. 3Cap unusual bulk baskets unless bulk buying recurs.
  4. 4Floor the variance at the mean.
  5. 5Pick the service level from the product's demand band; convert it to z with an inverse-normal approximation written in-line.
  6. 6Reorder point = ⌈μR + z√(σ²R)⌉ for R days to the next visit.
  7. 7Target = ⌈μP + z√(σ²P)⌉ with P = R + buffer, between a minimum facing and shelf capacity.
  8. 8Top up only when stock is below the reorder point; push stock with expiring warehouse batches.
  9. 9Ration by days of stock remaining when a trip can't carry everything, and record what was deferred.

Problem 3

What if the shelf changes after a delivery is planned?

Plans are made from the last snapshot of a store, which may be out of date by the time the delivery happens.

Guided demonstration with made-up data, simplified from the production logic.

Step 1 of 3

The plan is made from the last snapshot

Head office's last snapshot shows 4 of 12 units on the shelf, so the top-up plan is to deliver 8.

Shelf in the snapshot · 4 of 12

Advanced placement and concurrency

Plans are made from cached snapshots so that an offline store can still be replenished. A store whose snapshot is old is still planned, with a notice; it is only refused if no snapshot has ever been captured.

That is safe because the plan is treated as a ceiling. When the top-up is completed, the platform re-reads the store's live stock and delivers the smallest of three numbers: what was planned, the room left on the shelf, and the room left below the target. Stale data misses recent sales, so a cached plan errs towards delivering too little rather than overfilling.

Live edits to a position use optimistic concurrency: the browser sends the values it expects, the server locks the row and compares, and a mismatch returns a conflict with the current values instead of overwriting someone else's change. Locks are always taken in the same order, office first and store second, which rules out deadlocks between edits and deliveries.

In the warehouse, stock is reserved first-expiry-first-out when a list is created, skipping expired batches. Editing a list reserves more or releases the excess; completing or cancelling consumes or releases it.

Interactive technical demonstration. One fictional product; simplified from the production placement logic.

1 · Completion: check the plan against live stock

The plan was made from a cached snapshot. Change the live quantities to see the delivery shrink to what is safe.

  • P-01 · snapshot 3 · live
    3
  • P-02 · snapshot 2 · live
    2
  • P-03 · snapshot 5 · live
    6
Planned
10
Shelf room
13
Target room
9
Safe
9

safe = min(planned, shelf room, target 20 − live 11) = 9

Queued deltas: +5 → P-01, +4 → P-02

2 · Delivery: the shelf changed while the job was queued

  • P-018 of 8
  • P-022 +6 of 8
  • P-036 +2 of 8

1 unit could not be placed. An issue is recorded for follow-up instead of the units disappearing.

  1. P-01: +0, 5 overflow
  2. P-02: +4
  3. spill P-01 → P-02: +2
  4. spill P-01 → P-03: +2
  5. 1 unit could not be placed → issue recorded
05

Behind the engineering

For engineers: how it fits together.

Optional detail for engineers: the architecture, the financial logic, the trade-offs behind the design, and its known limits.

View architecture
  1. React app → Express API
  2. API reads office snapshots in Office MySQL
  3. API writes stock deltas and an outbox job in one transaction
  4. Delivery worker drains the outbox to each store, in order
  5. Sensitive edits read the store live, with a row lock
  6. Snapshot sync pulls each store back into Office MySQL
Cached reads
Lists, planning and reports read snapshots in the office database, so they keep working when a store is unreachable. Each store's sync status is shown alongside.
Background sync
A separate service pulls each store into office snapshots, one store at a time, so one failing store doesn't stop the rest. A partial read never deletes office rows.
Queued writes
Changes for stores go into a durable per-store outbox in the same transaction as the office change; a worker delivers them in order, retrying with backoff.
Live stock changes
Anything that could corrupt stock if it acted on stale data reads the store live, locks the row and checks the values the user expected.
Simplified, with generic names. Store databases are reached over a private network; addresses, hosts and schema details are left out.
Accurate financial reporting

The customer paid $5.00, but the listed prices add up to $5.50. How do we avoid reporting revenue we never collected?

Add up the list prices

  • Product A$3.00
  • Product B$2.50
  • Reported$5.50

$0.50 more than the customer paid. The discount is invisible line by line.

Split the amount actually paid

  • Product A$2.73
  • Product B$2.27
  • Reported$5.00

List prices only decide the split. The lines always add up to the money taken.

Cost of goods and the technical detail

Profit reports are only useful if last month's numbers don't change when this month's prices do. The landed cost of each batch (unit price with tax and deposit) is fixed at goods receipt, using the rates in force then. When stock is delivered to a store, the cost of the batches it came from is frozen into an append-only delivery ledger.

Sales records don't say which batch an item came from, so exact per-unit FIFO isn't possible. Cost of goods is instead matched at the period boundary: for each store and product, units sold before the period are skipped off the front of the ledger, and the period's units consume the next costs in order. This is an approximation. Units the ledger can't cover use a fallback cost, and every report shows what share of units were costed from the ledger.

Revenue is allocated down from the amount the customer was actually charged. List prices and promotion formulas only decide how a basket's total is split between its lines, and the last line absorbs the rounding, so per-product revenue always adds up to the money taken.

Interactive demonstration with fictional figures.

Cost of goods sold · one product, one store

8 units
14 units
Frozen delivery ledger and the units this period consumes
LedgerLanded costThis period
Delivery 1 · 10 units$1.202 × $1.20
Delivery 2 · 10 units$1.3510 × $1.35
Delivery 3 · 10 units$1.502 × $1.50

COGS this period$18.90

Ledger coverage100%

Costs were frozen when each delivery was made, so this figure doesn't change if prices or tax rates change later.

Revenue · one basket

The list prices add up to $5.50, but the customer was charged $5.00. The discount isn't visible line by line, so revenue is allocated down from the charged amount, using list prices only as weights.

Revenue allocated from the charged amount
ItemListAllocated
Sample Product A$3.00$2.73
Sample Product B$2.50$2.27
Total$5.50$5.00

Built up from list prices, this basket would report $0.50 of revenue that was never collected. Allocated down, the lines always add up to the money actually taken.

The detail behind the numbers

  1. 1Landed cost = unit price × (1 + tax rate) + deposit, with the rates stamped onto the batch at receipt.
  2. 2Batches with no recorded cost are deliberately not frozen into the ledger, so free-looking stock doesn't overstate profit.
  3. 3Only sales after a product's first costed delivery are skipped at the period boundary; counting older history would wipe out the ledger.
  4. 4Discounts applied by the store's own recommendation system are matched to sales by store, product and time, used at most once, and dropped entirely if they don't reconcile with the charged total.
  5. 5Refunds are split into spoiled, not retrieved, and spoilage write-offs, so net revenue and profit after spoilage are reported separately.
Engineering decisions and trade-offs
Durable outbox instead of writing to stores during the requestDocumented
Reason
Writes made directly to a store were lost whenever that store was unreachable. An outbox row committed with the office change survives until the store comes back.
Trade-off
Stores become eventually consistent with the office, so the interface has to show delivery states: sent, queued or failed.
Stock deltas instead of absolute quantitiesDocumented
Reason
"+4 to P-12" stays true however long the store was offline and however much it sold meanwhile. An absolute quantity computed at the office would overwrite those sales.
Trade-off
Deltas need placement rules for full, moved or inactive positions, and pending deltas have to be added to cached and live quantities wherever stock is shown.
An idempotency marker instead of a distributed transactionDocumented
Reason
The office and store databases are independent servers. A marker written in the same store transaction as the stock change makes retries safe without coordinating a two-phase commit.
Trade-off
Each store database carries one extra table, and the protocol has to be reasoned through for every crash point.
Plan from cached snapshots, verify against live stockDocumented
Reason
Refusing to plan until a store is reachable would block replenishment for exactly the stores that need attention.
Trade-off
Plans can over-request. Completion trims the quantity against live stock and releases the extra warehouse reservation.
Statistical safety stock instead of simple sales averagesDocumented
Reason
Averages are biased low by stockouts and inflated by one-off bulk baskets, and they say nothing about how much buffer variability needs.
Trade-off
More constants to choose, and those constants need empirical validation.
Freeze historical costs instead of recalculating themDocumented
Reason
A closed period should report the same profit every time it is opened, even after prices or tax rates change.
Trade-off
Correcting a historical cost needs explicit tooling rather than an edit to a price.
Everything else the platform does
  • 01

    Warehouse batches and expiry

    Batch-level stock with expiry dates and reserved quantities; empty batches are archived.

  • 02

    Purchase orders and receiving

    Orders by vendor, item-by-item receiving with expiry checks and landed costs.

  • 03

    Promotions and pickup codes

    Per-store promotions, promo codes reconciled across stores, and pickup codes shared by every store.

  • 04

    Sales reports

    Revenue, cost of goods and profit, with refunds and spoilage separated, exported to PDF and CSV.

  • 05

    Store monitoring

    A live view across stores, plus each store's sync status and data freshness.

  • 06

    Users and permissions

    Role-based access with 40 fine-grained permissions and their dependencies.

  • 07

    Audit logs

    Before-and-after records of product, position and stock adjustments in one place.

Technical considerations and known limits
  1. Eventual consistency

    Store data in the office is a snapshot. Staleness is surfaced rather than eliminated, and change-data capture from the stores would narrow it.

  2. Forecast validation

    Backtest the forecast's weights, bands and caps against historical stockouts and sales.

  3. Test coverage

    There are 67 automated tests across the platform and sync service, but delta application, cost of goods and revenue allocation still need direct tests, and nothing yet runs against a real MySQL.

  4. Single-process queue

    Move per-store ordering from in-process state to a database lease so more than one backend can drain the queue.

  5. Historical data

    Sales from before the cost ledger existed use fallback costs, which is why every report shows its ledger coverage.

06

Impact and reflection

From implementation to daily operations.

The platform is deployed in production and has become the business's primary operational management system. Warehouse stock, store replenishment, purchasing, promotions and sales reporting for the store network all run through it.

  • Scope

    13

    automated stores operated from the platform

  • Capability

    The business's main operations system, in daily production use

  • Capability

    Replenishment keeps working while stores are offline

  • Capability

    Store deliveries apply exactly once, even after lost acknowledgements

These describe what the system covers and does. Measured impact will be added once it has been measured.

My contributionDeveloped the majority of a production retail management platform integrating warehouse inventory, purchasing, stock replenishment and operational reporting. Engineered statistical forecasting and offline-tolerant inventory synchronization across independently managed store databases.