šŸŽ‰ 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
šŸ’¼ Servicesā„¹ļø Aboutāœ‰ļø ContactView Pricing Plansfrom $10

Data Versioning with DVC

Module 15: Data Engineering and MLOps🟢 Free Lesson
Data Engineering

The one-line mental model

Git versions code but not gigabytes; DVC extends Git with pointer files and an external content-addressable store so a commit pins the exact dataset, model, and pipeline stage outputs that produced your results.

You will be able to:

  • Initialize DVC with a remote storage backend (S3, GCS, or local)
  • Track large files with dvc add and commit the resulting .dvc pointers
  • Define a multi-stage pipeline in dvc.yaml that is reproducible with one command
  • Use dvc checkout and dvc pull to move between data versions like Git branches

Prerequisites

  • !Git basics: add, commit, branch, remote
  • !Python environment and requirements management
  • !Comfort with a command line and YAML

What You'll Learn

  • 1Explain the pointer-file architecture that keeps Git repositories small
  • 2Configure an S3 or GCS remote and sync tracked artifacts
  • 3Author a pipeline stage with deps, outs, and params
  • 4Reproduce an entire experiment from a clean checkout with dvc reproduce

The pointer-file architecture

DVC does not stuff large binaries into Git. Instead dvc add moves the file into a local cache (.dvc/cache), writes an .dvc pointer file into the working tree, and adds a small .gitignore entry so Git tracks only the pointer. The pointer contains an MD5 hash of the content; the remote store (S3, GCS, Azure, or a plain directory) holds the actual bytes. Checking out a different Git commit and running dvc checkout swaps the real files to match the pointers recorded in that commit.

Architecture Diagram
my-project/
ā”œā”€ā”€ .git/                  # code + .dvc pointer files only
ā”œā”€ā”€ .dvc/
│   ā”œā”€ā”€ config             # remote URL, cache settings
│   └── cache/             # content-addressed local cache
ā”œā”€ā”€ data/
│   ā”œā”€ā”€ raw/
│   │   ā”œā”€ā”€ orders.csv     # gitignored real file
│   │   └── orders.csv.dvc # committed pointer
│   └── processed/
│       └── features.parquet.dvc
ā”œā”€ā”€ models/
│   └── churn_rf.joblib.dvc
ā”œā”€ā”€ dvc.yaml               # pipeline definition
ā”œā”€ā”€ params.yaml            # hyperparameters, versions
└── requirements.txt
ConceptRoleAnalog in Git
.dvc filePointer to content in cache/remoteBlob reference
.dvc/cacheLocal content-addressed storage.git/objects
RemoteShared object store (S3, GCS)origin server
dvc.yamlPipeline stages with deps and outsMakefile / CI job
params.yamlVersioned hyperparametersConfig file

The separation is what keeps git clone fast — the repository stays kilobytes while terabyte datasets live in cheap object storage, versioned by the same commit history as your code.

Setting up a remote

A remote is just a URL where DVC uploads and downloads cache objects. S3 and GCS are the production defaults; a network share or another developer's directory works for local pair programming. Credentials flow through the cloud SDK's normal environment variables, never through the repo.

# One-time project setup
git init
dvc init
git add .dvc .gitignore
git commit -m "Initialize DVC"

# S3 remote (team default)
dvc remote add -d storage s3://my-org-ml-bucket/experiments
dvc remote modify storage access_grants \
  profile my-profile
git add .dvc/config
git commit -m "Configure S3 remote"

# Or GCS
# dvc remote add -d storage gs://my-org-ml-bucket/experiments

# Or a local directory for pair programming
# dvc remote add -d storage /mnt/shared/ml-store

# Verify connectivity
dvc remote list

Once the remote is configured, dvc push uploads any cache objects not yet present, and dvc pull fetches them on a fresh clone. The remote is content-addressed, so identical files across branches or experiments are stored once.

Tracking data and models

dvc add is the analog of git add for large files. It creates the pointer, updates .gitignore, and leaves the real file untouched in your working tree. Committing the .dvc file pins that content to a Git revision.

# Track a raw dataset
dvc add data/raw/orders.csv
git add data/raw/orders.csv.dvc .gitignore
git commit -m "Add raw orders dataset v3"

# Track a processed feature store
dvc add data/processed/features.parquet
git add data/processed/features.parquet.dvc .gitignore
git commit -m "Add feature snapshot for churn model"

# Track a trained model artifact
dvc add models/churn_rf.joblib
git add models/churn_rf.joblib.dvc .gitignore
git commit -m "Baseline random forest, ROC-AUC 0.84"

# Push everything to the remote
dvc push

To return to the dataset as it existed three commits ago, check out the Git revision and let DVC restore the matching files:

git log --oneline -5
git checkout HEAD~3 -- data/raw/orders.csv.dvc
dvc checkout data/raw/orders.csv.dvc
# data/raw/orders.csv is now the exact bytes from HEAD~3

The mental model is exact: Git decides which version the pointer refers to, DVC materializes the content behind it. Nothing about the dataset lives in Git history bloat.

Parameters as versioned config

params.yaml holds every knob a pipeline stage depends on — learning rates, split fractions, feature lists — and DVC tracks changes to it like any other file. A stage that declares params: in dvc.yaml re-runs automatically when the relevant keys change, which is exactly the invalidation logic you want for hyperparameter sweeps.

# params.yaml
data:
  raw_path: data/raw/orders.csv
  processed_path: data/processed/features.parquet
  test_size: 0.2

features:
  numeric: [age, income, tenure_days, order_count]
  categorical: [region, plan]

model:
  n_estimators: 300
  max_depth: 8
  min_samples_leaf: 5
  random_state: 42

eval:
  primary_metric: roc_auc
  gate: 0.80

Because params.yaml is committed, every experiment's configuration is recoverable from the commit hash alone — no more "which branch had max_depth=6?" archaeology.

Defining the pipeline in dvc.yaml

dvc.yaml declares stages as a DAG: each stage has a command, input dependencies (deps), parameter dependencies (params), and output artifacts (outs). dvc reproduce walks the DAG in topological order, skipping stages whose deps and params have not changed — a content-based build system for data science.

# dvc.yaml
stages:
  prepare:
    cmd: python src/prepare.py
    deps:
      - src/prepare.py
      - data/raw/orders.csv
    params:
      - data.test_size
    outs:
      - data/processed/train.csv
      - data/processed/test.csv

  features:
    cmd: python src/features.py
    deps:
      - src/features.py
      - data/processed/train.csv
      - data/processed/test.csv
    params:
      - features.numeric
      - features.categorical
    outs:
      - data/processed/features.parquet

  train:
    cmd: python src/train.py
    deps:
      - src/train.py
      - data/processed/features.parquet
    params:
      - model.n_estimators
      - model.max_depth
      - model.min_samples_leaf
      - model.random_state
    outs:
      - models/churn_rf.joblib
      - metrics/train_metrics.json
    metrics:
      - metrics/train_metrics.json:
          cache: false

  evaluate:
    cmd: python src/evaluate.py
    deps:
      - src/evaluate.py
      - models/churn_rf.joblib
      - data/processed/test.csv
    params:
      - eval.primary_metric
      - eval.gate
    metrics:
      - metrics/eval_metrics.json:
          cache: false
    outs:
      - reports/confusion_matrix.png:
          cache: false

The metrics: key tells DVC these files hold scalar metrics the UI can display; cache: false keeps them in Git rather than the remote store, since they are small and diffable. Reproducing an entire run from a clean checkout is then a single command.

# Fresh clone: code + pointers only
git clone git@github.com:my-org/churn-model.git
cd churn-model
dvc pull                       # fetch pointer contents from remote

# Reproduce the full pipeline (skips stages already up to date)
dvc reproduce

# Change one hyperparameter and re-run only the affected stages
# (edit params.yaml: model.max_depth: 12)
dvc reproduce train evaluate

# Visualize the DAG
dvc dag

Because stage commands are plain Python scripts with no DVC imports, the same code runs unchanged in CI, on a colleague's laptop, or inside a container — DVC only orchestrates and tracks.

Reproducibility and experiment workflows

The combination of Git branches, DVC-tracked data, and dvc.yaml stages gives you experiment branching: branch the repo, change params.yaml, run dvc reproduce, and compare dvc metrics show across runs. dvc exp adds a lighter-weight experiment namespace that does not require a Git commit per trial.

# Run a sweep without polluting Git history
dvc exp run --set-param model.max_depth=6 \
            --set-param model.n_estimators=500
dvc exp run --set-param model.max_depth=10 \
            --set-param model.n_estimators=200

# Compare experiments
dvc exp show --sort-by eval_metrics.roc_auc --desc

# Apply the winning experiment to a real branch
dvc exp apply <exp-name>
git checkout -b experiment/deeper-trees
git add params.yaml
git commit -m "Try deeper trees from dvc experiment"
dvc push

For teams, dvc exp share publishes experiments to the remote server so reviewers can inspect metrics and artifact diffs without pulling every branch. This workflow keeps the main branch clean while still recording every trial's configuration and outcome.

When DVC is not enough

DVC versions files and pipelines; it does not version rows inside a live warehouse table, stream features in real time, or replace a feature store's online serving layer. For warehouse-native datasets, pair DVC with dbt or a table-level snapshot tool; for real-time features, use a feature store. DVC's sweet spot is the offline world: training snapshots, labeled datasets, serialized models, and the DAG that connects them — exactly the artifacts a reproducible ML project cannot live without.

Understanding this boundary prevents the common over-adoption failure: trying to force DVC to manage streaming pipelines or live feature stores it was never designed for. DVC's content-addressed model works beautifully for batch artifacts that change infrequently and can be snapshotted; it is the wrong tool for data that updates every few seconds or for features that must be served with single-digit-millisecond latency. Recognize the seam between offline versioning (DVC's domain) and online serving (a feature store's domain) early, and design the handoff — typically a materialized batch feature table that both training and serving consume — as an explicit interface rather than an afterthought.

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-13

—
ā˜†ā˜†ā˜†ā˜†ā˜†
0 ratings

Rate & Feedback

Need Expert Data Science Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement