all_lessons / ml_system_design / 03e · pipeline registry lesson 3e / 34

Training pipeline, registry, and lineage

A model artifact is only meaningful if you can explain where it came from and safely move it into production. The pipeline turns data snapshots into checkpoints; the registry turns checkpoints into deployable versions; lineage connects every deployed prediction back to code, data, features, labels, config, and eval. Without that graph, rollback and debugging are guesswork.

The production invariant
For any prediction in production, you should be able to answer: which model version produced it, trained from which data snapshot, with which feature definitions, code commit, hyperparameters, and eval gate? If not, you do not have an ML system. You have a model-shaped script.
Plain English dictionary
A pipeline is the repeatable factory that turns data into a model artifact. A registry is the controlled shelf of model versions allowed to serve traffic. Lineage is the receipt that proves what data, code, features, labels, and tests produced that artifact. A gate is a test the artifact must pass before it can move closer to users.

0 · Think of release, not training

Beginners often stop at "train a model." Production thinking starts with a stricter question: what would make this model safe to release and easy to roll back? The answer is linear:

  1. Freeze the training inputs: data snapshot, labels, feature definitions, code, config.
  2. Run training and produce an artifact: weights plus preprocessing, thresholds, tokenizer or schema, and serving config.
  3. Evaluate the artifact against offline metrics, slices, calibration, cost, and safety gates.
  4. Promote it through staging, canary, and production only when each prior promise is true.
  5. Rollback the whole bundle if a promise breaks, not just the weights.

This lesson is the release discipline that keeps ML from becoming a pile of unrepeatable experiments.

1 · The artifact graph

General ML lifecycle design is a lineage problem. The output artifact is not just weights; it is a bundle of dependencies that must travel together.

code commit data snapshot feature defs labels training run config + seed + env candidate model artifact eval gate offline + safety registry staging/prod A registry promotion should be impossible unless the artifact carries enough lineage to reproduce and rollback it.
ArtifactWhy it must be versionedCommon bug if missing
Code commitTraining logic and preprocessing define the learned functionMetric cannot be reproduced
Data snapshotRows change, late labels arrive, deletes happenRollback model retrains differently
Feature definitionsFeature code is part of the modelTrain/serve skew after a feature patch
Model configHyperparameters and seeds affect artifact"Same" run produces incompatible output
Eval reportPromotion needs a gate and audit trailBad model ships on anecdote
Serving contractInput schema, output schema, thresholds, calibrationModel scores change meaning in production

2 · Pipeline stages and gates

A robust training pipeline is a sequence of gates. The point is not bureaucracy; it is to fail early while the blast radius is small.

  1. Ingest gate: schemas valid, source freshness inside SLO, required fields present.
  2. Feature gate: point-in-time joins pass, train/serve parity checks pass, feature distributions inside expected ranges.
  3. Label gate: label maturity window satisfied, label coverage and class balance within bounds.
  4. Training gate: run completed, no NaNs, expected loss curve shape, resource budget respected.
  5. Offline eval gate: task metrics improve or hold, segment regressions bounded, calibration checked.
  6. Release gate: shadow/canary/A/B guardrails clear, rollback path exists.
Why the gates are linear
A downstream gate cannot repair an upstream broken contract. A high AUC cannot forgive leaked features. A green canary cannot make an unknown training dataset reproducible. Each gate consumes the guarantees before it and adds one new guarantee.
Sample release checklist
A candidate can enter staging only if the dataset snapshot is immutable, the feature definitions are versioned, the labels are mature, the run has no NaNs, and the offline metric beats the current production model on the primary slice with no critical slice regression. It can enter canary only if shadow traffic meets p99 latency and output-schema checks. It can enter production only if online guardrails hold: error rate, latency, cost, calibration, and business-critical segments stay inside declared bounds. Each item is pass/fail, not vibes.

3 · Experiment tracking vs model registry

These are often conflated, but they answer different questions.

SystemQuestion answeredWrites many or few?User
Experiment trackerWhat did we try, and what happened?Many runsResearchers / MLEs
Model registryWhich artifact is allowed to serve traffic?Few promoted versionsProduction / release
Feature registryWhich feature definitions are valid and owned?ModerateData + ML platform
Dataset registryWhich immutable snapshots can train or evaluate?ModerateTraining + audit

A model can be a great experiment and a bad registry candidate. Promotion requires more than a metric: lineage, serving compatibility, calibration, safety, cost, and rollback.

4 · Promotion is a state machine

Treat model lifecycle as explicit state transitions, not a folder naming convention.

candidate │ offline eval + schema + lineage ▼ staging │ shadow traffic + load test + calibration check ▼ canary │ online guardrails + p99 + cost + segment metrics ▼ production │ ├── rollback → previous production artifact └── retire → archived, still reproducible
TransitionMust proveRollback object
candidate -> stagingOffline metrics, schema compatibility, lineage completeDo not promote
staging -> canaryServing p99, resource cost, output contract, shadow no-op safetyRemove canary route
canary -> productionOnline primary metric wins; guardrails holdPrevious prod model + previous feature set
production -> retiredNo active traffic, audit retention satisfiedArchived artifact

5 · The reproducibility budget

Perfect bitwise reproducibility is expensive and sometimes unnecessary. But the level should be chosen deliberately:

LevelGuaranteeEnough for
Audit reproducibleCan explain data/code/config/eval lineageMost product ML
Metric reproducibleRetrain lands within expected metric bandRegression debugging
Artifact reproducibleSame weights/logits from same inputsRegulated or safety-critical workflows

Do not pay artifact-level complexity if audit-level is enough. But do not accept "we think this was the data" for any model that gates money, safety, or user access.

Decision rule
Use audit reproducibility for low-risk personalization where rollback is easy. Use metric reproducibility when a regression can cost real money or trust and you must debug why a metric moved. Use artifact reproducibility when regulation, safety, finance, or legal review requires proving the exact output. The higher the harm and the harder the rollback, the more reproducibility you buy.

What carries forward