mail@mabbaz.com Abu Dhabi, UAE

Traceability · Data Model · ERP

Batch Genealogy in Manufacturing

Genealogy is the structure that makes traceability queryable: one join table recording which input lots became which output lots, in what quantity, under which order. This is how to model it, how to query it in both directions, and the four structural decisions that determine whether it survives rework, repack and continuous blending.

Muhammad Abbas November 26, 2026 ~13 min read

Batch genealogy is the family tree of your material: for any lot, which lots it came from and which lots it became. Everything else in traceability is either the data collection that feeds it or the reporting that reads it. It is a small structure, usually one table, and it is the difference between holding lot numbers and holding traceability. Most operations that discover they cannot answer a traceability question find that this table was never populated, or was populated from the recipe rather than from what actually happened.

The message up front: genealogy is one join table keyed on (output lot, input lot, order), carrying the quantity consumed. Backward tracing walks it up, forward tracing walks it down, and both are the same recursive query with the join columns swapped. The four decisions that determine whether it holds are: whether quantity is recorded, whether the order is in the key, whether rework parentage is captured, and whether same-item splits are modelled separately from cross-item transformation.

1. What genealogy actually records

A genealogy row says: this much of that input lot went into this output lot, on this order. That is all. The power comes from the fact that output lots are themselves input lots to later transformations, so the rows chain into a graph.

OR-2026-0021 (oregano)  ↘
                           HP-2026-0455 (premix)  ↘
BA-2026-0017 (basil)   ↗                                   
                                                FG-2026-1144 (sauce)
TP-2026-0871 (paste)                             ↗
SA-2026-0310 (salt)                              ↗

two transformation levels, five input lots, one finished lot

Two things are worth noticing. The graph is a directed acyclic graph, not a tree, because one input lot feeds many outputs and one output has many inputs. And the number of levels is a property of your process, not a configuration choice: a business buying finished ingredients has one level, a business making its own intermediates has as many as its production structure.

This article is about the structure. The chain of transactions that populates it is in lot traceability from raw materials to finished goods, and querying it under pressure is in forward and backward traceability.

2. The table

CREATE TABLE lot_genealogy (
  output_lot_id  BIGINT NOT NULL,
  input_lot_id   BIGINT NOT NULL,
  order_id       BIGINT NOT NULL,
  qty_consumed   DECIMAL(18,6) NOT NULL,
  uom            VARCHAR(10) NOT NULL,
  relation_type  VARCHAR(16) NOT NULL,
    -- 'consumption' | 'rework' | 'repack' | 'split'
  recorded_at    DATETIME NOT NULL,
  PRIMARY KEY (output_lot_id, input_lot_id, order_id),
  KEY ix_fwd (input_lot_id),
  KEY ix_bwd (output_lot_id)
);

Four decisions are embedded in that definition, and each one is a failure I would expect if it were made differently:

  • qty_consumed is present. Without quantity, genealogy tells you a lot was involved but not how much, so you cannot reconcile it against consumption postings and cannot tell a trace amount from the main ingredient. A mass balance check across genealogy is one of the few ways to detect that the table is incomplete, and it needs quantity.
  • order_id is in the primary key. If the same input lot is consumed by two orders producing the same output item, keying on the two lots alone collapses them into one row and loses the second order's quantity.
  • relation_type distinguishes how the lots are related. A consumption, a rework, a repack and a split are structurally the same row and operationally very different, and a forward trace that cannot tell them apart will present a repack as a transformation.
  • Two indexes, one per direction. The index serving the backward walk does not serve the forward walk, and the forward walk is the one you run when time matters.

3. The two queries

Both directions are recursive common table expressions over the same table, differing only in the join column:

-- BACKWARD: all ancestors of an output lot
WITH RECURSIVE up (lot_id, lvl) AS (
  SELECT input_lot_id, 1 FROM lot_genealogy
   WHERE output_lot_id = :start
  UNION ALL
  SELECT g.input_lot_id, up.lvl + 1
   FROM lot_genealogy g
   JOIN up ON g.output_lot_id = up.lot_id
   WHERE up.lvl < 20
)
SELECT DISTINCT lot_id, MIN(lvl) FROM up GROUP BY lot_id;

-- FORWARD: swap the two join columns
-- SELECT output_lot_id ... WHERE input_lot_id = :start
-- JOIN down ON g.input_lot_id = down.lot_id

Three things that are easy to get wrong here and expensive to discover during an incident:

  • The depth guard is not optional. Rework can create a cycle, where a lot is eventually an ancestor of something that becomes its own input. Without lvl < n the query does not terminate, and the moment you find that out will be the worst possible moment.
  • DISTINCT matters. A diamond-shaped graph, where two paths reach the same ancestor, returns that ancestor twice. Reporting it twice is cosmetic; summing quantities across duplicated paths is not.
  • Test at production volume. A forward trace from a widely used raw material lot across several weeks is a different query from the same trace in a demo dataset. Record how long it takes, because that number is the real answer to "how fast can we scope a recall".
Mass balance as a completeness check

For any output lot, the sum of qty_consumed across its genealogy rows should relate sensibly to its own quantity, allowing for expected yield loss. Where it does not, genealogy is incomplete or an input was not recorded. This is one of very few automated checks that can detect a missing genealogy row, because the absence of a row is otherwise invisible: a trace with a missing branch returns a confident, well-formatted, wrong answer.

4. The cases that break naive models

Case What happens physically Correct modelling If got wrong
Rework A finished lot is reprocessed into a new lot Genealogy row, relation_type 'rework', old lot as input New lot looks like fresh production. Whole branch invisible, and old material gets a new expiry.
Repack Bulk split into retail packs Child lots, relation_type 'repack', date inherited Chain severed at the last step before the customer, the worst place.
Lot split One lot divided on partial rejection parent_lot_id on the lot record, not a genealogy row Modelled as transformation, so a split looks like a new product.
Continuous blending New material added to a partly full tank Time-boxed output lots, several inputs with estimated proportions, flagged as estimated Pretended precision, or no genealogy at all.
Co-products One run yields two saleable outputs Two output lots, each with the full input set Second output has no parentage and is untraceable.

The split versus transformation distinction in row three is the subtle one. Splitting a lot of the same item is a parent-child relationship on the lot record; transforming lots of one item into another is a genealogy row. Conflating them produces a structure that cannot represent a repack, because a repack is both: same material, new container, new identity.

The honest limit of continuous processes

Where material is continuously added to and drawn from the same vessel, the output genuinely contains several input lots in proportions nobody measured. No data model recovers that information. The defensible response is a time-boxed lot with the candidate inputs recorded and the proportions explicitly marked as estimated, so that a trace returns a wider but honest answer. A system that reports exact proportions here is reporting a calculation, not a measurement, and anyone relying on it should know which.

5. Retention, and why genealogy outlives stock

Genealogy has to survive long after the material is gone. A lot consumed two years ago is still an ancestor of finished goods that may still be in the market, so archiving or purging lot records by stock balance will silently break historical traces.

The practical rule: retention is driven by the longest shelf life in the chain plus whatever period your obligations require, not by whether there is stock on hand. Note that retention periods are jurisdictional and sector-specific. The European Commission's guidance on the EU general food law traceability duty suggests around five years by analogy with tax records, with shorter periods for some perishable foods, while Article 18 itself sets no minimum. Your own obligations may differ, and this is a question for your regulatory advisers rather than for an article.

6. Where it goes wrong

  • Genealogy derived from the bill of materials. Records the recipe, not the event. Invisible, and wrong whenever a substitution or a second lot occurred.
  • No quantity column. Cannot mass balance, so missing rows stay undetected.
  • Order not in the key. Two orders on the same lot pair collapse into one row.
  • Rework treated as fresh production. Severs the branch and re-dates old material.
  • No depth guard on the recursion. A cycle hangs the query.
  • One index only. The forward trace, the one that matters under pressure, is the slow one.
  • Lot records purged when stock reaches zero. History quietly disappears.

The idea to walk away with

Genealogy is one join table and it is the whole traceability feature. Key it on output lot, input lot and order, carry the quantity, distinguish consumption from rework, repack and split, index both directions, and populate it from actual consumption rather than from the recipe.

Then add the mass balance check, because a missing genealogy row produces no error, no warning and a perfectly plausible answer.

Final thoughts

If you want to know whether your genealogy is real, pick a finished lot and sum the input quantities recorded against it. If the total has no sensible relationship to the output quantity, the table is incomplete, and no amount of reporting on top of it will help. That check takes one query and tells you more than reviewing the configuration.

How all of this comes together as a designed system, rather than a set of transactions that happen to work, is in how to design an end-to-end manufacturing traceability system.

Genealogy that cannot be queried?

Independent advisory on genealogy data models, recursive trace queries, rework and repack parentage, and the consumption capture that populates them. 22+ years across enterprise systems implementation.

Book a conversation

Related reading: Lot traceability: raw materials to finished goods, Forward and backward traceability, Batch vs lot vs serial number, Lot and batch tracking, CAFM data migration strategy.

Muhammad Abbas

CMMS / CAFM Manager & Independent Advisor · 22+ years across enterprise CMMS, EAM, CAFM and ERP implementations in utilities, oil and gas, manufacturing, government and facility operations.

Work with me
Mass balance test

One query tells you whether your genealogy is complete.

Get in touch
MAbbaz.com
© MAbbaz.com