Interview's MateData Science
Interview's Mate

Data Science

Python → ML → MLOps

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Science topics
Lesson 143/ 160
08. MLOps & Model Deployment

Data & Model Versioning with DVC

Version large datasets and models alongside Git without bloating the repository.

IntermediateDVC · Remote Storage3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

DVC lets you keep big data files out of Git while still remembering exactly which version of the data goes with which version of your code.

Think of it like…

A library catalogue card system for a huge archive. Git holds the small catalogue cards (hashes and instructions); the heavy books sit in a warehouse (remote storage), and the card for each edition lets you fetch exactly that edition, while identical pages shared across editions are stored only once.

Where you’ve seen it

The team has a 5 GB image-metadata dataset stored as 1,000 files of about 5 MB each. dvc add data/raw creates data/raw.dvc (a hash of the directory and a size field), Git commits that tiny file and dvc push sends the objects to s3://team-dvc/…. Version 2 changes 50 of the 1,000 files. DVC deduplicates by file content hash, so it stores only the 50 new files, 250 MB, instead of another 5 GB; after ten versions with 50 changed files each, remote storage holds 5 + 9 × 0.25 = 7.25 GB rather than 50 GB of full copies. The pipeline in dvc.yaml has four stages: prepare (cleans and splits), featurize, train (depends on params.yaml values such as max_depth) and evaluate (writes metrics.json). Total runtime is 40 minutes; when only train.max_depth changes, dvc repro detects that prepare and featurize are unchanged and reruns train (12 minutes) and evaluate (1 minute), 13 minutes instead of 40. dvc metrics diff and dvc params diff show the effect of a pull request (AUC 0.866 to 0.871), and dvc exp run tracks experiments as lightweight Git refs. To reproduce last quarter's model, a colleague runs git checkout model-2026-08 then dvc pull, getting the matching data, parameters and trained model. Practices: the remote is private with credentials stored outside the repository, dvc gc cleans unreferenced cache, CI runs dvc pull and dvc repro on a small sample, and every released model gets a Git tag so its data version is addressable. Large directories with millions of tiny files are first packed (for example into Parquet shards) because per-file hashing becomes the bottleneck.

Words you’ll hear

.dvc file
A small pointer file, committed to Git, holding the hash and size of tracked data.
Remote
Shared storage (S3, GCS, Azure, SSH) that holds the actual data objects.
dvc.yaml / dvc.lock
The pipeline definition, and the recorded hashes of its last run.
Content-addressed cache
Storage keyed by content hash, so identical files are stored once.

Visual diagram

Loading interactive diagram

Theory & deep dive

How DVC versions data and models

dvc add <path> hashes the file or directory (MD5 by default), moves the content into .dvc/cache under its hash, links it back into the workspace and writes <path>.dvc containing the hash and size, plus an entry in .gitignore. You commit the .dvc file with Git. dvc push copies cache objects to the configured remote; dvc pull and dvc checkout fetch and restore data for the current commit. Because storage is content-addressed, identical files are stored once: for a 1,000-file dataset in which 50 files change in a new version, only those 50 new objects (250 MB at 5 MB each) are added. Ten such versions occupy 5 + 9 × 0.25 = 7.25 GB, against 50 GB if each were a full copy. Deduplication works per file, so a single huge file that changes slightly is stored again in full; shard large datasets into files that change independently.

Models are versioned the same way: track the trained artefact as a pipeline output (outs: model.pkl) or with dvc add. Commit the pointer together with the code and parameters that produced it, and the commit becomes a complete, restorable snapshot. DVC complements an experiment tracker: DVC owns data and pipeline lineage (what inputs, which stage graph), while MLflow or similar owns run comparison and a model registry.

A pointer file

data/raw.dvc: outs: - md5: 4f1c…a9.dir, size: 5368709120, nfiles: 1000, path: raw. Git stores about 100 bytes; git checkout v1.2 && dvc checkout restores the 5 GB tree for that commit.

Key takeaway: DVC puts hashes in Git and bytes in a remote, deduplicating unchanged files so versions are cheap to keep.

Pipelines, parameters and metrics

dvc.yaml defines stages, each with cmd, deps (code and data it reads), params (keys from params.yaml), outs (what it writes) and optionally metrics and plots. For four stages (prepare, featurize, train, evaluate) taking 4, 8, 12 and 1 minutes plus 15 minutes of data loading, a full run is about 40 minutes. dvc repro computes hashes of each stage's dependencies and skips stages whose inputs match the last run recorded in dvc.lock: change only train.max_depth and just train (12 min) and evaluate (1 min) rerun, 13 minutes instead of 40. The DAG also guarantees consistency: if raw data changes, every downstream stage reruns.

dvc params diff and dvc metrics diff compare workspace and a Git revision, which makes pull requests informative (AUC 0.866 to 0.871, size and latency changes). dvc exp run -S train.max_depth=8 runs experiments as lightweight Git objects you can list, compare and promote. Good practice: keep the remote private with credentials outside the repo, run dvc gc to remove unreferenced objects, pack directories of millions of tiny files into shards (Parquet, tar) to keep hashing fast, run dvc pull and a small dvc repro in CI and tag releases (model-2026-08) so you can reproduce what was deployed. Compare alternatives by need: Git LFS for a few large files with minimal tooling, lakeFS or Delta Lake for branching and time travel on a data lake, DVC for code-adjacent datasets and pipelines.

Selective rerun

dvc.lock records hashes for prepare (4 min), featurize (8 min), train (12 min), evaluate (1 min), plus 15 min of loading. Edit train.max_depth in params.yaml → dvc repro reruns train and evaluate only: 13 min instead of 40. Edit raw data → all four stages rerun.

Key takeaway: Describe the workflow as a cached DAG with params and metrics so reruns are fast and every change is reviewable.

How it works, step by step

Step 1 of 4
Data scientist

1. Initialise and configure the remote

Run dvc init, add a private remote and keep credentials out of the repository.

dvc init · dvc remote add s3://team-dvc
Key numbers at this step
Keep
secrets out of Git

When to use it & trade-offs

What it is

DVC (Data Version Control) versions large datasets and models alongside Git without storing them in Git. dvc add data/raw moves the data into a content-addressed cache, replaces it with a small .dvc pointer file (a hash and a size, roughly 100 bytes) that Git tracks, and dvc push uploads the cached objects to a remote (S3, GCS, Azure, SSH). git checkout <tag> followed by dvc checkout restores the exact data of that version. A dvc.yaml file describes a pipeline of stages with dependencies, parameters, outputs and metrics; dvc repro reruns only the stages whose inputs changed, and a dvc.lock file records the hashes used. Alternatives include Git LFS, lakeFS and table formats with time travel such as Delta Lake.

Why it matters: Git is the right home for code and the wrong home for gigabytes. Yet a model's behaviour depends on the exact data and parameters used to train it, so reproducing or auditing a result needs all three versioned together. Without it, teams say "the model was trained on last month's data, I think", overwrite files, run out of disk on duplicate copies and can't roll a model back. DVC ties data versions to Git commits and turns a multi-step notebook workflow into a cached, reproducible pipeline.

When to reach for it

  • Datasets too big for Git that must match code versions
  • Reproducible multi-stage pipelines with caching
  • Auditing which data trained a released model

When to avoid or be careful

  • Committing multi-gigabyte files to Git
  • Overwriting dataset files without versioning
  • Packing a single huge file that changes a little each version

Versioning large files

DVC
Best for: Datasets, models and pipelines tied to Git commits

Strengths: Content-addressed dedup; pipeline caching; vendor-neutral remotes.

Watch out: Extra commands; per-file hashing overhead.

Git LFS
Best for: A few large binary files

Strengths: Simple Git extension.

Watch out: No pipelines; storage and bandwidth quotas.

lakeFS / Delta Lake time travel
Best for: Data lakes needing branching and rollback

Strengths: Scales to huge tables; atomic commits.

Watch out: Infrastructure to run; less tied to code repos.

Interview signals & numbers to know

When this topic comes up

  • “How do you version data?”
  • What a .dvc file contains
  • How dvc repro decides what to rerun
  • DVC versus Git LFS
  • Reproducing a model from last quarter

Benchmarks & rules of thumb

≈ 100 bytes -
size of a .dvc pointer in Git
7.25 GB vs 50 GB -
ten dataset versions with 5% changed, deduplicated versus full copies
13 min vs 40 min -
rerun time when only train params change

Common mistakes & follow-ups

Common interview mistakes

  • Forgetting dvc push, so teammates can't pull the data.
  • Storing credentials in the repository.
  • Skipping tags, then being unable to find the data behind a release.

Likely interviewer follow-ups

  • How would you reproduce a model trained three months ago?
  • How does DVC avoid storing duplicate data?
  • How do DVC and MLflow complement each other?
Interview tip: Describe a release as git tag plus dvc.lock plus params; it shows you think of a model as code, data and config together.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Data & Model Versioning with DVC with data science interview Q&A and hands-on practice.

Open Data Science Q&A →Machine Learning Q&A
Previous topic
Experiment Tracking with MLflow
Next topic
Feature Stores Basics (Feast)