Skip to content

August 15, 2026 • Ibexcode

From Notebook to Production: Building a Reliable ML Pipeline with Airflow and CI/CD

Diagram of a production ML pipeline orchestrated with Airflow and CI/CD

Getting good results in a notebook is one thing. Running the same model every day, without manual intervention and with data that isn’t always perfect, is quite another.

During experimentation, the main question is usually:

Can the model learn something useful from the available data?

Once it reaches production, the questions change. What happens if data arrives late? If its schema changes? If a task fails after writing part of its output? If a new code version is incompatible with an older model? If inference needs to be rerun? If the server restarts midway through a job, or an external dependency becomes temporarily unavailable?

In a daily pipeline, these aren’t hypothetical edge cases. Eventually, they will happen.

That led us to organize the pipeline around a simple idea: inference is more than running a script. It is part of a processing chain whose inputs, outputs, dependencies, and success conditions must be explicit.

This article explores the engineering decisions that keep that chain running over time: ingestion, data checks, Apache Airflow orchestration, environment isolation, CI/CD, deployment, and observability. The model itself isn’t the focus.


1. A Notebook Is Not a Production Unit

In a notebook, the workflow is often straightforward: load data → compute features → load the model → predict → inspect results.

The developer naturally fills in any gaps. They check whether a file exists, rerun a cell, investigate an unusual distribution, or delete an intermediate result before trying again. These small decisions happen almost automatically.

Production can’t depend on someone always being there to make them.

The pipeline needs to determine for itself whether inputs are available and valid, which steps should run, which can be replayed, whether an existing output can be reused, whether an error is transient or blocking, and whether the results are ready to publish.

Productionizing a notebook isn’t simply automating its cells. It means turning the decisions previously made by a developer into explicit rules the pipeline can enforce and verify.


2. Separate the Pipeline into Clear Responsibilities

We started by separating responsibilities rather than keeping one long script that did everything.

A simplified view of the pipeline looks like this:

Responsibilities of the different pipeline components

The benefit is practical: an ingestion failure should be identified as an ingestion failure, and a Python process exiting successfully shouldn’t automatically authorize publication of incomplete results.

Each stage therefore has a clear contract with the next. Inference shouldn’t have to guess whether the raw data is complete; that should already have been checked. Likewise, publication receives predictions that have passed validation rather than inventing its own checks on the fly.

The guiding rule is simple: a stage must not silently conceal problems inherited from the previous one.


3. Airflow and DAGs: Orchestrate Without Absorbing Business Logic

We use Apache Airflow and its DAGs (Directed Acyclic Graphs) to coordinate these processes.

A DAG describes a workflow: the tasks that need to run and the dependencies that determine their order. For example:

acquisition → validation → preparation

validation can run only after acquisition, and preparation depends on successful validation. Acyclic simply means those dependencies cannot form a loop: an upstream task cannot ultimately depend on a downstream task.

A DAG defines what runs, in what order, and under which conditions. Airflow handles orchestration; it shouldn’t contain all the business logic. It can manage dependencies, execution order, triggers, retries, timeouts, resource requirements, and task states.

We therefore keep business logic in independent Python components. A pipeline tightly coupled to Airflow quickly becomes difficult to test or run outside the orchestrator. When Airflow tasks invoke components with explicit interfaces, those components can be run and tested independently.

DAGs Aligned with Operational Boundaries

The entire platform doesn’t need to fit into a single DAG.

When ingestion, inference, and publication have different lifecycles, separating them makes it possible to rerun each independently and reuse intermediate results.

Three-DAG architecture: ingestion, inference, and publication

Each DAG produces a state that the next can consume. This is particularly useful for recovery after an incident. A new inference run doesn’t necessarily require another ingestion if a validated dataset already exists. Publication can likewise be replayed from validated predictions without recalculating the entire ML chain.

Retries and failure handling can then be applied where they make sense, without restarting everything unnecessarily.

Lightweight DAGs, Independent Components

Separating responsibilities doesn’t mean moving their implementations into Airflow files. An inference DAG might define:

preparation → inference → validation

But the actual processing remains in dedicated Python components.

  • The DAG describes orchestration.
  • The Python component performs the work.

That preserves the ability to test inference or validation independently. Nor does every tiny operation need its own DAG. A boundary is useful when it reflects a real operational responsibility: a different execution lifecycle, independent replay, reusable intermediate state, or distinct success criteria.

The right design lies between a monolithic DAG that absorbs all business logic and a maze of DAGs with no meaningful operational boundaries.

Airflow controls when, in what order, and under what conditions work runs. Application code defines what that work does.


4. Depend on State, Not Just a Schedule

A common mistake is to coordinate processing entirely by the clock:

05:00 → ingestion
06:00 → inference
06:30 → publication

That schedule assumes every previous stage finishes on time and without errors. There is no guarantee it will.

At 6 a.m., the data may still be missing even though ingestion was supposed to finish an hour earlier. Ingestion may have taken longer than expected, validation may have failed, or the expected data may simply not be available yet.

The real condition isn’t it's 6 a.m.; it’s validated dataset available.

Orchestration should express these dependencies explicitly. A downstream task becomes eligible to run when the state it depends on actually exists and meets its requirements, not merely because the clock has reached a planned time.

This matters especially when several DAGs work together. The inference DAG depends on a dataset that has passed the necessary checks, not just the nominal completion of the ingestion DAG. Publication depends on validated predictions, not merely on an inference task having ended.

Schedules are useful for triggering or checking work. They aren’t evidence that upstream work succeeded. Airflow lets us reason about actual system states and dependencies, rather than a series of scripts assumed to have finished at fixed times.


5. Idempotency as a Pipeline Property

Being able to rerun a task without making matters worse is essential in production.

A task might fail after downloading data, creating some files, writing records, computing features, or beginning publication. If every retry assumes a clean slate, even a minor failure requires manual cleanup.

We therefore design processing steps to be idempotent wherever possible:

run(x)
run(x)
run(x)

Repeated execution should converge to the same final state as one successful run.

Depending on the component, that may involve deterministic writes, stable identifiers, controlled artifact replacement, transactions, temporary files followed by atomic renames, upserts, or checking existing state before modifying it.

That’s the value of idempotency: a retry becomes a normal recovery mechanism, not another opportunity to create duplicates or inconsistent data.


6. Retrying Must Not Hide Errors

Not every error should be retried blindly.

A temporary network outage and a schema incompatibility are different incidents. Retrying the former is reasonable; the latter should generally stop the pipeline.

Repeatedly attempting to process a file whose schema has changed won’t fix it. It only delays diagnosis.

Our recovery policy therefore distinguishes transient errors from structural ones. That also produces more useful alerts: an issue likely to resolve on the next retry doesn’t deserve the same priority as a broken input-data contract.


7. Validate Data Before Inference

An HTTP 200 response doesn’t guarantee that the returned data is usable. Checks must examine the content, not just source availability.

Before the pipeline proceeds, we can verify expected fields, types, required values, cardinalities, unknown categories, volumes, distributions, outliers, and consistency across related objects.

A silent change in the data can be harder to detect than an outright outage. If a source stops responding, the pipeline stops. If it continues responding but changes a distribution or the meaning of a field, inference may keep producing technically valid yet statistically inconsistent results.


8. From Schema Checks to Distribution Checks

Checking columns and types is necessary, but not enough. Two datasets can have identical schemas and very different distributions.

The pipeline also monitors statistical properties of its inputs and can compare them against historical baselines.

Diagram of data distribution checks

Not every variation should block the pipeline; some changes are perfectly normal. The goal is to distinguish structural invariants that must halt processing, serious anomalies requiring investigation, and ordinary statistical variation that should simply be recorded.

That hierarchy avoids both extremes: checking nothing, or building a system so sensitive that normal changes constantly bring it down.


9. Version ML Artifacts as a Consistent Set

Deploying a model isn’t just copying a weights file onto a server. Its predictions also depend on preprocessing, vocabularies, configuration, and potentially calibration.

A deployable artifact might conceptually contain:

model/
├── model
├── configuration
├── feature definition
├── categorical vocabulary
├── preprocessing metadata
├── calibration
└── evaluation metadata

The aim is to avoid combinations where the model belongs to one version, the categorical vocabulary to another, preprocessing to whatever code currently happens to be on the server, and calibration to a different experiment altogether.

Such combinations may execute without errors while producing incorrect predictions. Deployment must therefore preserve compatibility across code, data, and ML artifacts.


10. CI: Build and Validate

Continuous integration catches as many problems as possible before deployment. Depending on the component, that includes unit tests, integration tests, configuration validation, dependency checks, image builds, pipeline-component verification, and publication of deployable artifacts.

It’s better to discover an incompatibility in CI than after a new version reaches production.

Continuous integration validation stages

An image that cannot be built has no reason to reach the server. An invalid configuration shouldn’t have to wait until Airflow starts to be discovered. This reduces the number of failures first detected in the most expensive environment: production.


11. CD: Deploy a Reproducible State

Continuous delivery isn’t just about sending a new version to a server. We also need to identify exactly what was deployed and reproduce that state.

A production environment that depends on manual changes or files existing only on the server will eventually drift away from its sources of truth. We therefore rely on identifiable artifacts and automated procedures.

Continuous deployment and reproducible state

Infrastructure and service configuration are described declaratively wherever possible. The server is not the source of truth. It’s a target on which a state defined elsewhere must be reproducible.


12. Why Manual Changes Become Dangerous

Changing a production server directly can solve an immediate problem. The trouble starts when that fix exists nowhere else.

If the change lives only on the server, the actual production state begins to diverge from the state described by the sources of truth. It may disappear during the next deployment, when the declared state is reapplied.

During that period of drift, the running production environment can no longer be reconstructed solely from identified, versioned inputs.

Any lasting change belongs in code, configuration, or declarative infrastructure and should reach production through the deployment process. Production must remain the result of those sources of truth, not become a parallel configuration source.


13. Containers Alone Don’t Guarantee Reproducibility

Docker helps reproduce the runtime environment by packaging the Python version, libraries, system dependencies, application, and runtime configuration.

That boundary makes it possible to build, test, and execute a given service version with the same software and system dependencies.

But the guarantee extends only to what the image actually contains. A container doesn’t guarantee the version of the data, the compatibility of ML artifacts, or the transformations the model relies on.

A perfectly versioned Docker image running a model with incompatible preprocessing is still an incorrect system.

Containerization is an important part of reproducibility, but it cannot make an entire ML system reproducible on its own.


14. Observability: Know What Actually Happened

Automating a pipeline doesn’t automatically make it observable. Knowing that a task ran isn’t always enough to know whether it produced the expected result.

Orchestration provides a first layer: task states, duration, retries, dependencies, logs, and execution history.

But technical success is not necessarily functional success. A task can complete and produce zero results. Ingestion can finish without an exception while returning an abnormally small dataset. Inference can generate scores with an unexpected distribution.

Observability therefore needs to cover several layers:

  • Infrastructure : Are the server and required services available?
  • Processes : Are the components running correctly?
  • Pipeline : Have all expected stages completed?
  • Data : Are the inputs complete and consistent?
  • ML : Do the outputs remain consistent with expected behavior?

This prevents us from treating a successful process exit as sufficient proof that the system is healthy.


15. Decouple the ML Pipeline from the Product

Predictions aren’t sent directly to the client. The pipeline publishes only validated results to a dedicated backend layer, which then exposes them to the product.

That backend is the interface between two systems with different responsibilities and lifecycles.

Separation between ML computation and the end product

The ML pipeline can be recalculating, temporarily unavailable, or undergoing deployment without necessarily depriving the application of the last valid published state. Conversely, changes to the product don’t have to require changes to the inference pipeline.

This separation lets us develop and operate ML computation and user-facing services independently.


16. Design for Incidents, Not Just the Happy Path

When everything works, the process is simple: data arrives, tasks run in sequence, and results are published.

The real challenge begins when a stage fails or produces something unexpected.

For each stage, we need to define not only what success looks like, but also the state the system should be left in when it fails. An interruption shouldn’t leave that outcome to chance.

Depending on the stage, the appropriate behavior may be to replay an idempotent operation automatically, stop when a contract is broken, prevent dependent tasks from starting, discard partial output, retain the last valid state, or record enough information to diagnose the incident.

Trying to eliminate every failure is unrealistic. The goal isn’t a pipeline that never fails; it’s one where failure leads to a known, observable, controlled state.

That matters more to robustness than shaving a few seconds off the happy path. Nor does robustness mean adding infrastructure for its own sake: every component should address a real operational problem and remove more complexity than it introduces.


17. Operational Invariants of the Pipeline

Over time, a few rules have helped keep the pipeline predictable and maintainable.

1. Downstream tasks don’t compensate for invalid inputs. Data must explicitly pass the necessary checks before the next stage consumes it.

2. Replaying a task must converge to a consistent state. Retries are part of normal operation and shouldn’t routinely require manual cleanup.

3. Technical success doesn’t guarantee functional success. Exit codes are supplemented with checks on produced data and artifacts.

4. Models are deployed with everything they need to run. Weights, configuration, preprocessing, vocabulary, and calibration belong to one logical version.

5. Publication happens after validation. Partial or inconsistent output must not automatically replace the last valid state.

6. Production isn’t a source of truth. Lasting changes must be reproducible from code, configuration, and automation.

7. Observability covers the entire chain. Infrastructure, orchestration, data, and ML outputs require distinct checks.

8. Dependencies are explicit. A schedule doesn’t replace an availability contract between processing stages.

9. The orchestrator doesn’t own business logic. DAGs coordinate tasks and dependencies; independently testable components implement the processing.

10. The product is decoupled from ML computation. Temporary pipeline unavailability shouldn’t automatically become user-facing downtime.

These invariants make it possible to reason about the pipeline independently of whichever algorithm is currently deployed.


18. Conclusion

Moving a model from a notebook into production takes far more than scheduling a Python script.

The model now operates alongside occasionally incomplete data, external services, failure-prone processing stages, and changing versions. The reliability of the whole chain matters, not just that of the algorithm.

Robustness depends on operational properties:

  • tasks run only when their dependencies are genuinely satisfied
  • errors and retries lead to known, controlled states
  • code, configuration, and artifacts make the deployed state reproducible
  • outputs are validated before reaching the product, which remains decoupled from ML computation.

At that point, the question is no longer just:

“Does the model produce good predictions?”

It becomes:

“Can we explain, reproduce, and control the path that produced each result?”

That’s the difference between a collection of automated scripts and an ML pipeline that can genuinely be operated in production.