Automating and orchestrating ML pipelines · Topic 1 of 2
Building, Validating and Orchestrating ML Pipelines
Build ML pipelines with Agent Platform Pipelines, Airflow or Ray, validate data and models before deployment, and keep preprocessing consistent in serving.
- 5 min
- Agent Platform Pipelines runs KFP and TFX pipelines serverlessly with lineage and caching.
- Airflow orchestrates across systems; Ray handles distributed Python; Kubeflow on GKE is self-managed.
- Start from Google Cloud Pipeline Components and templates.
What it is
An ML pipeline is a graph of steps (components) such as ingest, validate data, transform, train, evaluate and deploy, run automatically with each step's inputs and outputs recorded. Pipelines make training reproducible and let a team rerun everything with one command or trigger.
Good pipelines also validate what flows through them: data is checked before training, models are checked before deployment, and preprocessing is shared so serving sees data the same way training did.
How it works
Choosing the orchestrator
| Option | Managed? | Choose it when |
|---|---|---|
| Agent Platform Pipelines | Serverless | ML workflows written with the Kubeflow Pipelines (KFP) SDK or TFX; automatic lineage, caching, pay per run |
| Kubeflow Pipelines on GKE | Self-managed | Must run open-source Kubeflow on your own cluster |
| Managed Service for Apache Airflow | Managed Airflow environment | Scheduling ML pipelines together with many non-ML jobs and dependencies across systems; often triggers Agent Platform Pipelines runs |
| Ray on Gemini Enterprise Agent Platform | Managed Ray clusters | Distributed Python for data processing, training or tuning written with Ray |
| Cloud Build, Cloud Scheduler | Managed | Triggering runs, not orchestrating ML steps |
Templates or custom pipelines
| Approach | Use |
|---|---|
| Google Cloud Pipeline Components | Prebuilt components for platform tasks: create datasets, run AutoML or custom training, batch inference, deploy to endpoints, BigQuery ML steps |
| Pipeline templates | Ready-made pipelines (for example Tabular Workflows) that you run with parameters |
| TFX standard components | ExampleGen, StatisticsGen, SchemaGen, ExampleValidator, Transform, Trainer, Evaluator and Pusher for TensorFlow models |
| Custom KFP components | Your own Python functions or containers |
Start from templates and prebuilt components; write custom components only for logic they lack.
A small KFP pipeline with a model gate
from kfp import dsl, compiler
@dsl.component(base_image="python:3.11")
def evaluate(model_uri: str) -> float:
# load the candidate model and return its AUC on the test split
return 0.91
@dsl.component(base_image="python:3.11")
def deploy(model_uri: str):
print(f"deploying {model_uri}")
@dsl.pipeline(name="churn-train")
def churn_pipeline(model_uri: str):
auc = evaluate(model_uri=model_uri)
with dsl.If(auc.output >= 0.85):
deploy(model_uri=model_uri)
compiler.Compiler().compile(churn_pipeline, "churn_pipeline.yaml")
from google.cloud import aiplatform
aiplatform.PipelineJob(
display_name="churn-train",
template_path="churn_pipeline.yaml",
pipeline_root="gs://my-bucket/pipeline-root",
parameter_values={"model_uri": "gs://my-models/churn/candidate"},
).submit()
Steps whose inputs have not changed can be skipped through execution caching, which saves time and cost on reruns.
Validating data
| Check | Catches | Tools |
|---|---|---|
| Schema | Missing columns, wrong types, new categories | TFX SchemaGen and ExampleValidator, TensorFlow Data Validation, SQL checks |
| Statistics | Nulls, ranges, shifted distributions versus the last training set | TensorFlow Data Validation, BigQuery queries |
| Volume and freshness | Empty or stale loads | Row counts and timestamps in a pipeline step |
| Leakage | Features unknown at prediction time | Review and time-based splits |
A failed check should stop the pipeline before training wastes compute or produces a bad model.
Validating models
| Check | Purpose |
|---|---|
| Metric threshold | The candidate must reach a minimum quality |
| Compare with champion | The candidate must match or beat the production model on the same test set |
| Slice metrics | No important segment gets worse |
| Infrastructure check | The model loads and answers in its serving container |
TFX's Evaluator marks a passing model as "blessed"; in KFP, a conditional step like dsl.If deploys only models that pass.
Consistent preprocessing between training and serving
Training-serving skew appears when serving transforms data differently from training. Prevent it by having one implementation:
| Method | How |
|---|---|
| TFX Transform (tf.Transform) | Computes statistics once and exports a transform graph that is attached to the serving model |
| BigQuery ML TRANSFORM clause | Preprocessing stored with the model |
| Preprocessing inside the model | Keras preprocessing layers or a saved scikit-learn Pipeline |
| Feature Store | Training and serving read the same registered features |
| Shared component or library | The same versioned code runs in the pipeline and in the custom prediction routine |
"Normalization statistics in serving differ from training" points to computing them once in the pipeline (for example with TFX Transform) and shipping them with the model.
A worked example
A team retrains a demand model by running six notebooks in order. Last quarter an upstream table lost a column and a broken model reached production.
The engineer rebuilds the process as an Agent Platform Pipelines run: data validation stops on schema or distribution anomalies; Google Cloud Pipeline Components handle training and batch inference; and a gate deploys only if the candidate beats the champion. Preprocessing moves into a shared component also used by the serving container.
How the exam asks about this
- "Run ML steps reproducibly with lineage and no infrastructure to manage." Agent Platform Pipelines with Kubeflow Pipelines or TFX.
- "Upstream schema changes sometimes produce bad models." Add a data validation step that stops the pipeline on schema anomalies.
- "The company already orchestrates hundreds of ETL jobs in Airflow and wants model training in the same schedule." Use Managed Service for Apache Airflow to trigger Agent Platform Pipelines runs.
What to remember for the exam
- Agent Platform Pipelines runs KFP and TFX pipelines serverlessly with lineage and caching.
- Airflow orchestrates across systems; Ray handles distributed Python; Kubeflow on GKE is self-managed.
- Start from Google Cloud Pipeline Components and templates.
- Validate data before training and models before deployment, and stop on failure.
- One preprocessing implementation for training and serving prevents skew.
A pipeline that deploys every model it trains is not safe automation. Always gate deployment on evaluation against a threshold and the current champion.
Common mistakes
Orchestrating ML steps with cron scripts. You lose lineage, retries and caching; use a pipeline service.
Running a self-managed Kubeflow cluster by default. It adds cluster operations that the managed service removes.
Recomputing statistics at serving time. Serving must use the training statistics, not new ones from live traffic.
Check yourself
Which managed service runs Kubeflow Pipelines and TFX pipelines without a cluster?
Agent Platform Pipelines, which runs compiled pipelines serverlessly and records artifacts and lineage.
How does a pipeline avoid deploying a worse model?
It evaluates the candidate against a metric threshold and the current champion and deploys only when the check passes, for example with a dsl.If condition.
How does TFX Transform prevent training-serving skew?
It computes preprocessing statistics once and exports a transform graph that is attached to the model, so serving applies exactly the training transformations.
Topic 1 of 2 in Automating and orchestrating ML pipelines
Test yourself on Automating and orchestrating ML pipelines
The full Google Cloud Professional Machine Learning Engineer question bank has 749 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Google Cloud. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.