Xheikh Talha
Contact me

FIFO inventory explained with a real system: keeping stock, invoices and ledgers in step

How FIFO inventory works, why it matters for retailers and e-commerce brands, and how StockFlow connects FIFO batches to purchases, sales and ledgers.

By Talha Yasin3 min read

FIFO stands for first in, first out. You sell, or account for, the oldest stock first. It sounds simple, and it is, until stock, invoices and ledgers live in different places. Then it becomes the reason the numbers never match.

This is how FIFO works and how I built it into StockFlow, an inventory and operations system delivered through SaleForgers.

FIFO in one example

Here is an example with made-up numbers. You buy 100 units at 200 each, then another 100 units at 220 each. Now you sell 150 units.

  • The first 100 units sold come from the first batch: 100 × 200 = 20,000.
  • The next 50 come from the second batch: 50 × 220 = 11,000.
  • Cost of goods sold is 31,000, and the 50 units left are valued at 220 each.

If you averaged the cost instead, your margin and your stock value would both look different. When purchase prices move, FIFO tells you what the stock you still hold actually cost.

Why retailers and e-commerce brands care

  • Accurate margins. You know what each sale really cost.
  • Expiry and freshness. Older stock leaves first, which matters for anything with a shelf life.
  • Honest stock value. Your balance sheet reflects recent prices.

Batches are the key idea

In StockFlow every purchase creates a batch with its own quantity and cost. Sales do not just reduce a product's count. They consume batches, oldest first, and remember which batches they used. That small design choice is what keeps everything else consistent.

Following a purchase through the business

  1. Purchasing. Record the purchase and the supplier behind the incoming stock.
  2. Supplier ledger. The supplier's financial record updates with the purchase.
  3. Inventory and FIFO. A new batch joins the queue for that product.
  4. Sales. An invoice consumes the oldest available batches.
  5. Customer ledger. The customer's record connects to the sale.
  6. Reporting. Purchasing, stock and sales come together in dashboards.

Exceptions belong in the system

Real operations are messy. Customers return items, stock gets damaged, counts drift. In StockFlow, returns and stock adjustments are part of the same workflow as purchases and sales, alongside expenses and estimates. If exceptions live outside the system, the system stops being the truth.

FIFO, LIFO or weighted average?

  • FIFO sells the oldest units first. Stock on hand is valued at recent prices. It matches how most physical goods actually move.
  • LIFO sells the newest units first. It is rarely used for physical goods and is not allowed under IFRS.
  • Weighted average blends all purchase costs into one average cost. It is simpler to compute but hides how prices are moving.

For retailers and e-commerce brands with changing supplier prices, FIFO usually gives the most honest picture.

A minimal data model for FIFO

You do not need a complicated schema. These pieces are enough:

  • Products: what you sell.
  • Batches: one per purchase line, with quantity received, quantity remaining and unit cost.
  • Sale allocations: which batch each sold unit came from and at what cost.
  • Ledger entries: supplier and customer balances that move with purchases, payments, sales and returns.

When a sale is posted, the system walks the product's batches from oldest to newest, takes what it needs from each, and writes the allocations. Cost of goods sold is the sum of those allocations, so it is always explainable.

Handling returns and adjustments

Returns are where FIFO systems often break. Two rules keep them sane:

  1. A customer return goes back to the batch it came from, at that batch's cost, so margins stay correct.
  2. Damage and count corrections are recorded as adjustments against specific batches, with a reason, never as silent edits.

Reports that become possible

Once batches and allocations exist, useful reports come almost for free:

  • Stock ageing: how long units have been sitting, by batch.
  • Batch-level margin: which purchases were actually profitable.
  • Supplier balances: what you owe, connected to what you received.
  • Reorder signals: fast movers running low, before the shelf is empty.

Signs you need this

  • Low stock surprises you.
  • Your margin report and your accountant disagree.
  • Supplier balances are tracked in a separate spreadsheet.
  • Returns are recorded "later".

If two of those sound familiar, it is time for one system where stock and records move together. You can read the full StockFlow case study or see how I approach e-commerce operations.

The project behind this article

StockFlow

Inventory and operations management for a retail business: purchasing, FIFO inventory, sales and the supplier and customer ledgers behind them, connected in one workflow.

Read the case study: StockFlow

Have a process that's slowing you down? Let's talk about it.

Tell me about the workflow and the problem behind it. The first call is free, and you get a written scope before anything is built.