Apply Now Apply Now Apply Now
header_logo
Post thumbnail
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING

Building a Data Pipeline for ML: Step-by-Step Guide

By HCL GUVI

A data pipeline for ML is an automated system that moves data from source systems through extraction, validation, transformation, feature engineering, and storage steps to produce clean, model-ready datasets for training and inference. Unlike general data pipelines, ML data pipelines must handle versioning of datasets alongside models, serve features consistently between training and production inference, and maintain reproducibility so that any training run can be exactly reconstructed from its inputs.

Table of contents


    • TL;DR Summary
  1. The Core Problem ML Data Pipelines Solve
  2. Stage 1: Data Ingestion
  3. Stage 2: Data Validation
  4. Stage 3: Data Transformation
  5. Stage 4: Feature Engineering
  6. Pipeline Orchestration
  7. Conclusion
  8. FAQs
    • What is a data pipeline for ML? 
    • What is training-serving skew and how do I prevent it? 
    • What tools are used to orchestrate ML data pipelines? 
    • What is point-in-time correctness in ML pipelines? 
    • What is a feature store and do I need one? 

TL;DR Summary

  • A data pipeline for ML automates the flow of data from raw sources through cleaning, transformation, and feature engineering to training-ready datasets
  • The five core stages are data ingestion, validation, transformation, feature engineering, and serving to training and inference
  • The training-serving skew problem occurs when features are computed differently during training versus inference, causing production models to underperform despite strong offline evaluation
  • Feature stores solve training-serving skew by providing a single source of truth for feature computation shared by both training pipelines and production inference

The Core Problem ML Data Pipelines Solve

General data pipelines move data from sources to destinations reliably. ML data pipelines are more complex because they must support reproducibility and training-serving consistency.

Reproducibility: Every training run should be reproducible from the same data, transformations, and feature logic. This requires versioning datasets, transformation code, and model artifacts.

Training-serving consistency: Features used during training must be computed identically during inference. Differences can cause training-serving skew, leading to silent model performance degradation.

Want to build strong data engineering and MLOps skills covering pipeline design, feature stores, and production ML infrastructure? Explore HCL GUVI’s Artificial Intelligence & Machine Learning Course, designed to help you develop the data engineering foundations that modern ML roles demand. 

Stage 1: Data Ingestion

Stage 1: Data Ingestion

Data ingestion moves raw data from source systems into pipeline storage. Common sources include databases, data warehouses, event streams, APIs, flat files, and third-party providers.

  1. Batch vs Streaming Ingestion
ApproachLatencyBest For
BatchHours to daysHistorical training and periodic retraining
Micro-batchMinutesNear-real-time features
StreamingSecondsReal-time inference and fraud detection

Most ML pipelines use batch ingestion for training data and streaming or micro-batch ingestion for real-time features. Tools such as Fivetran and Airbyte support managed batch ingestion, while Apache Kafka handles high-throughput streaming.

Read More: How to Build RAG Pipelines in AI Applications

  1. Change Data Capture

Change Data Capture (CDC) captures only inserted, updated, or deleted database records instead of repeatedly extracting entire tables. This reduces source-system load and ingestion time. Debezium is a widely used open-source CDC tool that integrates with Kafka.

  1. Raw Data Storage

Raw data should be preserved in a data lake before transformation. Object storage such as AWS S3, Google Cloud Storage, and Azure Data Lake provides scalable storage.

Keeping raw data makes it possible to reprocess historical records when transformation or feature definitions change.

Stage 2: Data Validation

Data validation checks incoming data against expected schemas, value ranges, and statistical properties before transformation and feature engineering.

  1. What to Validate

Schema validation checks that expected columns and data types are present and detects unexpected changes.

Value validation checks numerical ranges, categorical values, and required fields. Invalid or unexpected values can indicate upstream data problems.

Statistical validation compares incoming data distributions with historical reference data. Significant changes may indicate source-system changes or distribution drift.

  1. Validation Tools

Great Expectations is an open-source framework that defines validation rules as expectations using Python or YAML and generates validation reports.

Deequ, developed by Amazon, provides similar capabilities and is optimized for large-scale data processed with Apache Spark.

  1. Handling Validation Failures

Validation failures should have predefined policies. Minor issues can generate warnings, while serious problems—such as critical features arriving entirely null—should stop the pipeline and alert the team.

Stage 3: Data Transformation

Stage 3: Data Transformation

Transformation converts validated raw data into a clean format suitable for feature engineering.

  1. Core Transformation Operations

Deduplication: Removes duplicate records caused by repeated ingestion, CDC replay, or upstream issues.

Type casting and standardization: Converts data into consistent formats, such as UTC timestamps and standardized numerical or string types.

Joining across sources: Combines information from multiple systems into unified records for feature engineering.

Handling missing values: Applies strategies such as mean or median imputation, mode imputation, or missing-value indicators.

  1. Point-in-Time Correctness

Point-in-time correctness ensures that a training example only uses information available before the prediction time.

Using information from after the prediction time creates target leakage. Such models may appear highly accurate during offline evaluation but fail in production because future information is unavailable.

To enforce point-in-time correctness, pipeline records should be timestamped and filtered so that only data available before the label timestamp is used.

💡 Did You Know?

Uber’s Michelangelo processes more than 10 TB of feature data daily. Training-serving skew caused by inconsistent feature computation was a major source of unexplained production model degradation, making consistent feature computation a key architectural priority.

Stage 4: Feature Engineering

Feature engineering transforms cleaned data into the numerical representations consumed by ML models. It is one of the most ML-specific stages and can significantly affect model performance.

  1. Common Feature Engineering Operations

Numerical features: Scaling, log transformations, binning, and rolling aggregates such as 7-day averages or 30-day totals.

GUVI Ad

Categorical features: One-hot encoding, target encoding, and embeddings for high-cardinality entities such as users and products.

Time-based features: Extracting hour, day, month, and cyclical representations using sine and cosine transformations.

Interaction features: Creating products, ratios, and differences between existing features to capture useful relationships.

  1. Feature Store Integration

A feature store centrally manages computed features and serves them to both training and production inference.

It helps prevent training-serving skew by allowing the same feature computation logic to be used for both training and serving instead of maintaining separate implementations.

Feature StoreTypeKey Strength
FeastOpen-sourceFlexible and cloud-agnostic
TectonCommercialManaged and streaming support
HopsworksOpen-source + commercialBatch and streaming
AWS SageMaker Feature StoreManagedAWS integration
Vertex AI Feature StoreManagedGCP integration

Stage 5: Dataset Versioning and Serving

The final stage packages feature-engineered data into versioned training datasets and serves features to production systems.

  1. Dataset Versioning

Every training dataset should record:

  • A snapshot of the training data
  • The feature engineering code version
  • The time range of the data
  • The dataset version used by the model

DVC (Data Version Control) can version large datasets alongside Git-tracked code while storing the actual data in cloud storage.

Recording dataset lineage helps teams identify exactly which training data and feature versions were used when investigating model performance problems.

  1. Training Dataset Serving

Training datasets are commonly stored as Parquet files in object storage. Date-based partitioning allows training jobs to load only the required time ranges.

Parquet’s columnar format also reduces I/O by allowing training jobs to load only the feature columns they need.

  1. Inference Feature Serving

Real-time inference requires low-latency feature access. Precomputed features can be stored in systems such as Redis or DynamoDB for fast retrieval.

On-demand features can be calculated by the feature store’s online serving layer and cached to reduce repeated computation.

💡 Did You Know?

Google’s TFX (TensorFlow Extended) makes data validation, schema tracking, and training-serving consistency core pipeline stages. This helps prevent silent model quality regressions from reaching production unnoticed.

Pipeline Orchestration

Orchestration tools schedule pipeline stages, manage dependencies, monitor execution, and handle failures. They replace manual triggers and fragile cron jobs with structured workflows.

  1. Apache Airflow

Apache Airflow is widely used for ML pipeline orchestration. It represents workflows as Directed Acyclic Graphs (DAGs), where tasks are connected through dependencies.

GUVI Ad

Airflow provides monitoring, retry mechanisms, logs, and workflow management through its web interface.

  1. Prefect

Prefect provides easier local testing, support for dynamic workflows, and simplified deployment through Prefect Cloud.

  1. Kubeflow Pipelines

Kubeflow Pipelines provides Kubernetes-native orchestration and integrates closely with ML training infrastructure. It is particularly suitable for teams already using Kubernetes.

Want to build strong data engineering and MLOps skills covering pipeline design, feature stores, and production ML infrastructure? Explore HCL GUVI’s Artificial Intelligence & Machine Learning Course, designed to help you develop the data engineering foundations that modern ML roles demand. 

Conclusion

A well-built data pipeline for ML transforms data preparation from a manual, error-prone activity into a reliable engineering system that every model in your organization can depend on. 

The five stages of ingestion, validation, transformation, feature engineering, and versioned serving address the specific requirements of ML pipelines that general data engineering frameworks were not designed for: reproducibility, training-serving consistency, and point-in-time correctness.

FAQs

What is a data pipeline for ML? 

An automated system that moves data from raw sources through ingestion, validation, transformation, feature engineering, and versioned storage to produce reproducible, model-ready training datasets and consistently served inference features.

What is training-serving skew and how do I prevent it? 

Training-serving skew occurs when features are computed differently during training versus production inference, causing silent performance degradation. A feature store with shared feature computation logic used by both training and serving pipelines prevents it.

What tools are used to orchestrate ML data pipelines? 

Apache Airflow is the most widely adopted option. Prefect offers easier testing and dynamic workflows. Kubeflow Pipelines integrates with Kubernetes ML infrastructure. All three schedule, monitor, and manage task dependencies across pipeline stages.

What is point-in-time correctness in ML pipelines? 

It ensures that training examples only include features computed from data available before the label timestamp, preventing target leakage where future information is included in features for past predictions.

What is a feature store and do I need one? 

A feature store is a centralized system that stores and serves computed features consistently to both training pipelines and production inference. You need one when training-serving skew from inconsistent feature computation becomes a recurring source of production model degradation.

Success Stories

Did you enjoy this article?

Schedule 1:1 free counselling

Similar Articles

Loading...
Get in Touch
Chat on Whatsapp
Request Callback
Share logo Copy link
Table of contents Table of contents
Table of contents Articles
Close button

    • TL;DR Summary
  1. The Core Problem ML Data Pipelines Solve
  2. Stage 1: Data Ingestion
  3. Stage 2: Data Validation
  4. Stage 3: Data Transformation
  5. Stage 4: Feature Engineering
  6. Pipeline Orchestration
  7. Conclusion
  8. FAQs
    • What is a data pipeline for ML? 
    • What is training-serving skew and how do I prevent it? 
    • What tools are used to orchestrate ML data pipelines? 
    • What is point-in-time correctness in ML pipelines? 
    • What is a feature store and do I need one?