Sub topic 3
MLflow: tracking client, backend store, and artifact store
This chapter explains how MLflow Tracking is put together and where your data lands. It assumes you can write a Python training script, you know what hyperparameters and validation metrics are, and you understand basic client-server communication over HTTP. It builds on the shared data model of experiments, runs, parameters, metrics, tags, and artifacts from the previous chapter.
The three pieces
MLflow Tracking is made of three components. Knowing which one holds which data explains most setup problems.
- Tracking client. The Python API (
mlflow.log_param,mlflow.log_metric, and so on) that runs inside your training process. It builds requests and sends them. - Backend store. A database or directory that holds run metadata: experiments, runs, parameters, metrics, and tags.
- Artifact store. Storage for large files such as model files, plots, and datasets. Examples are a local directory, Amazon S3, Google Cloud Storage, or Azure Blob Storage.
Between the client and the two stores there is often a fourth element, the tracking server. It is a web service that exposes a REST API and a web UI. It is optional, but a team needs one.
The tracking client and tracking URI
The client decides where to send data from the tracking URI. You set it in code or through an environment variable.
import mlflow
mlflow.set_tracking_uri("http://127.0.0.1:5000")
mlflow.set_experiment("churn-model")
with mlflow.start_run(run_name="baseline"):
mlflow.log_param("max_depth", 6)
mlflow.log_param("learning_rate", 0.1)
for step, auc in enumerate([0.84, 0.88, 0.91]):
mlflow.log_metric("val_auc", auc, step=step)
mlflow.set_tag("data_version", "2026-11-01")The same script works against different setups, depending only on the URI:
| Tracking URI | What happens |
|---|---|
| Not set | The client writes to a local `./mlruns` directory. |
| `file:///path/to/dir` | The client writes directly to files in that directory. |
| `sqlite:///mlflow.db` | The client writes directly to a SQLite database. |
| `http://host:5000` | The client sends REST requests to a tracking server. |
You can also set MLFLOW_TRACKING_URI in the environment, which keeps the address out of your code. Anything set with set_tracking_uri takes precedence over the environment variable.
Some behaviors are worth knowing:
mlflow.set_experimentcreates the experiment if it does not exist. Experiments are identified by name and by a numeric ID.mlflow.start_runused as a context manager ends the run when the block exits. If an exception escapes the block, the run is marked as failed.- Parameters are write-once per key within a run. Logging
max_depthagain with a different value raises an error. Metrics, by contrast, can be logged many times for the same key, and thestepargument orders them. - Parameter values are stored as strings. Tags are free-form key-value pairs and are the right place for things like a data version or a Git commit.
The backend store
The backend store holds run metadata. MLflow supports two kinds.
- File store. Metadata is written as files under a directory such as
mlruns. It is simple and needs nothing installed. It is fine for a single person trying things out. - Database store. Any SQLAlchemy-compatible database, in practice SQLite for single-user use and PostgreSQL or MySQL for teams. A database handles concurrent writers, supports queries, and is the store that newer MLflow features, including the model registry, are designed around.
Note that the model registry requires a database-backed store. If you point at a plain file directory, registry features may be unavailable or limited, depending on your MLflow version. Check the documentation for the version you run.
For a team, use PostgreSQL. SQLite locks the whole database file for writes, so several training jobs logging at once can produce "database is locked" errors.
A database also makes search practical. The client can query runs with filter strings:
import mlflow
mlflow.set_tracking_uri("http://127.0.0.1:5000")
runs = mlflow.search_runs(
experiment_names=["churn-model"],
filter_string="metrics.val_auc > 0.9 and params.max_depth = '6'",
order_by=["metrics.val_auc DESC"],
)
print(runs[["run_id", "params.max_depth", "metrics.val_auc"]])search_runs returns a pandas DataFrame. Notice that the parameter comparison uses a quoted string, because parameters are stored as strings.
The artifact store
Metrics and parameters are small. Models, figures, and data samples are not, so MLflow keeps them in a separate artifact store. The backend store only records where each run's artifacts live, in an artifact location (also called artifact URI).
You log files like this:
import mlflow
mlflow.set_tracking_uri("http://127.0.0.1:5000")
mlflow.set_experiment("churn-model")
with mlflow.start_run():
with open("report.txt", "w") as f:
f.write("validation report\n")
mlflow.log_artifact("report.txt", artifact_path="reports")
mlflow.log_dict({"features": ["age", "tenure"]}, "features.json")log_artifact copies a local file into the run's artifact location. log_dict, log_figure, and log_text are shortcuts that write the object for you.
The artifact location is fixed when an experiment is created. By default it is a local ./mlartifacts directory under the server's working directory. Changing it later affects only new experiments, not existing ones. To use object storage, you set it when starting the server or when creating the experiment.
Object stores need the matching client library and credentials. For S3, install boto3 and make sure the process that writes artifacts has AWS credentials.
Running a tracking server
The server is started with the mlflow server command. The simplest form uses defaults.
pip install mlflow
mlflow server --host 127.0.0.1 --port 5000With these defaults, metadata goes to a local store and artifacts go to a local directory, so this is for learning and testing only. A shared setup names the stores explicitly:
pip install mlflow psycopg2-binary boto3
mlflow server \
--host 0.0.0.0 \
--port 5000 \
--backend-store-uri postgresql://mlflow:CHANGE_ME@db-host:5432/mlflow \
--artifacts-destination s3://my-team-mlflow-artifacts \
--default-artifact-root mlflow-artifacts:/Here the server stores metadata in PostgreSQL and artifacts in the S3 bucket. Replace the placeholder password and bucket name, and prefer to supply the password through an environment variable or secrets manager rather than typing it into a shell history.
Proxied versus direct artifact access
There are two ways a client can reach the artifact store.
- Proxied access. The client sends artifacts to the tracking server, and the server forwards them to the store. The
mlflow-artifacts:/scheme in the example above selects this mode. Clients need no cloud credentials, which makes access control simpler. The cost is that all artifact traffic passes through the server, so large models can make it a bottleneck. - Direct access. The server only tells clients the artifact URI. Each client then talks to S3 (or another store) itself. This scales better, but every training machine needs credentials and network access to the bucket.
For most teams, proxied access is easier to secure and direct access is easier to scale. Pick based on artifact sizes and who holds credentials.
What the server does not give you
An open-source MLflow server is intentionally small, and some things are your responsibility.
- Authentication. By default, anyone who can reach the server can read and write. Place it behind a reverse proxy or SSO gateway, or use the basic authentication that recent versions provide, and check what your version supports.
- Network exposure. Binding to
0.0.0.0makes the server reachable from other machines. Do that only inside a trusted network. - Backups. You must back up the database and the bucket. Losing the database leaves artifacts with no record of which run produced them.
- Upgrades. Database schema changes between versions are applied with
mlflow db upgrade <backend-store-uri>. Back up first.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Runs appear in a local `mlruns` folder, not the server | Tracking URI was never set in the process | Call `set_tracking_uri` or set `MLFLOW_TRACKING_URI` |
| `Changing param values is not allowed` | The same parameter key was logged twice with different values | Log it once, or use a different key or a metric |
| `database is locked` | Several writers on SQLite | Move to PostgreSQL or MySQL |
| Artifact upload fails with a credentials error | Direct access mode, and the client lacks cloud credentials | Provide credentials or switch to proxied access |
| Old experiment still writes to a local path | Artifact location was fixed at creation time | Create a new experiment with the correct location |
| Run stays in "RUNNING" state after a crash | The process was killed before `end_run` ran | End it manually with `mlflow.end_run()` or the client API |
Why this architecture matters for choosing a tracker
The separation into client, backend store, and artifact store means you control where data lives. You can keep everything inside your own network, use storage you already pay for, and inspect the database directly. The price is operational work: you provision, secure, back up, and upgrade the server. A hosted tracker moves that work to a vendor. The later chapters on hosting and governance and on evaluation criteria return to this trade-off.
Exercise
A team of six runs MLflow with mlflow server using its defaults. Two weeks in, they see "database is locked" errors when several jobs run in parallel, and training machines fail to upload models because they have no S3 credentials. Which two changes would you make, and which component does each one address?
Show answer
First, switch the backend store to PostgreSQL (or MySQL) with --backend-store-uri. This addresses the backend store, since SQLite locks the whole file on writes. Second, configure the server for proxied artifact access (--artifacts-destination s3://... --default-artifact-root mlflow-artifacts:/) so the server holds the S3 credentials and the training machines only talk to the server. This addresses the artifact store access path. Because the artifact location is fixed per experiment, the team should create new experiments after the change.
Exercise
You run mlflow.log_param("max_depth", 6) and later in the same run mlflow.log_param("max_depth", 8). What happens, and what would you use if the value really changes over time?
Show answer
The second call fails because parameters are write-once per key within a run. A value that changes over time should be logged as a metric with a step, for example mlflow.log_metric("max_depth", 8, step=10).