FIFO Engine
Allocation
Atomic
Transactions
PDF Export
Reports
Multi-site
Facilities
Ribbonwire is a full-stack inventory and supply chain management system built for a beef distributor. It manages the complete chain: raw materials, production runs, finished lots, customer purchase orders, and shipments — with end-to-end traceability from source to customer.
The core engineering challenge was implementing a FIFO (First In, First Out) lot-allocation engine that atomically reserves stock from the oldest lots by best-by date, preventing over-allocation across concurrent orders — a critical requirement for perishable goods management.
The FIFO allocation engine (allocateInventoryFIFO) queries available inventory with casesAvailable > 0, ordered by lot.bestByDate ascending. It walks through rows, updating casesReserved and casesAvailable, and persists POLineAllocation rows — all inside a Prisma transaction for atomicity.
Reverse allocation (releaseAllocations) processes lots in reverse order (newest first), and shipment processing (processShipmentFromAllocations) reduces casesOnHand in FIFO order. This three-operation design handles the full lifecycle: reserve → ship or release.
Data migration was a significant effort: scripts handle backfilling SKU IDs onto historical records, recalculating inventory snapshots from transaction history, and reallocating existing purchase orders when lot data was corrected — all designed to be idempotent and safe to re-run.