2: MLOps

    Model Lifecycle Management

    Model lifecycle management on Databricks describes how a model artifact is produced, validated, promoted, served, and monitored from a development workspace all the way through to a production workspace, while keeping a single source of truth in Git for code and a single source of truth in Unity Catalog for trained model versions. The lifecycle has to answer four questions at once:

    • where does the code live,
    • where does the model artifact live,
    • who is allowed to push it forward,
    • how does anyone know it still works once it is in production.

    Databricks publishes two reference strategies for this, deploy code and deploy model. The deploy-code strategy moves source code through environments and retrains in each environment against that environment's data, while the deploy-model strategy trains once in development and copies the binary artifact across registries.

    The exam materials and the official end-to-end MLOps reference both treat deploy code as the default recommendation because it allows production retraining against production-grade data without ever giving development workloads access to production secrets, and because the resulting production model is reproducible from a tagged commit plus a production Lakehouse snapshot.

    A correctly built lifecycle pipeline has six architectural pieces.

    How it works

    • Source control holds the bundle definition, notebooks, libraries, and tests.
    • A continuous integration runner (GitHub Actions, Azure DevOps, GitLab CI, or Lakeflow Jobs called from a webhook) runs unit tests on pull requests and runs integration tests against a non-prod workspace before merging to main.
    • A Databricks Asset Bundle declares jobs, experiments, registered models, and serving endpoints per target environment.
    • Each workspace has its own Unity Catalog catalog, typically named dev, staging, and prod, with the same schema layout so that the only difference between targets is the resolved catalog name.
    • A model registry, scoped per catalog, stores the trained models:/<catalog>.<schema>.<name> versions and the alias graph (@champion, @challenger, @archived).
    • Serving endpoints in the prod workspace read from the prod catalog by alias, while monitors and inference tables close the loop by feeding production metrics back into the retraining trigger.

    Environment Architectures

    A scalable Databricks environment for ML splits into three workspaces aligned with the dev, staging, and prod targets in the Asset Bundle.

    Each workspace is in its own metastore or, more commonly, shares one regional metastore but isolates the dev, staging, and prod catalogs with separate IAM and grants.

    Compute is also tiered:

    • development uses Personal Compute or shared all-purpose clusters with permissive library installs,
    • staging uses job clusters created on demand by the integration pipeline,
    • production uses dedicated job clusters with locked-down init scripts and locked DBR versions to keep training reproducible.

    Serving in production uses Mosaic AI Model Serving endpoints in the prod workspace, with the served entity referencing prod.ml.<model>@champion so that promoting a version is a one-line alias update rather than a redeploy.

    The dev workspace can host a smaller mirror of the same endpoint backed by the dev catalog for shakeout testing of the serving wrapper.

    targets:
     dev:
     workspace:
     host: https://adb-dev.databricks.com
     variables:
     catalog: dev
     experiment_path: /Users/data-eng/experiments/churn
     staging:
     workspace:
     host: https://adb-staging.databricks.com
     variables:
     catalog: staging
     experiment_path: /Shared/experiments/churn
     prod:
     mode: production
     workspace:
     host: https://adb-prod.databricks.com
     root_path: /Shared/.bundle/churn
     variables:
     catalog: prod
     experiment_path: /Shared/experiments/churn
     run_as:
     service_principal_name: sp-mlops-prod
    

    Best practice for sizing the environment is to keep dev cluster definitions in the bundle as variable overrides so the same job runs on a small node count in dev (for example a single i3.xlarge driver and two workers) and a larger node count in staging and prod.

    Library pins are locked at the bundle level, ideally as wheel artifacts built in CI and uploaded with the bundle deploy, rather than %pip install cells inside notebooks.

    That way the artifact set is identical across targets and a databricks bundle deploy --target prod is idempotent.

    The same logic applies to init scripts and cluster policies, which should be referenced by ID in the bundle and managed centrally per workspace by the platform team.

    Identifying the Right Table Type and Lakehouse Monitoring Feature

    Lakehouse Monitoring exposes three monitor profile types and you pick the profile by looking at the shape of the data you want to monitor, not by guessing.

    • A Snapshot profile takes a full distribution profile of the current table at every refresh, with no notion of windows; it suits stable reference tables and one-off audits but cannot compute drift between windows because every refresh sees the full table again.
    • A TimeSeries profile partitions the table by a timestamp column and a granularity (5 minutes, 30 minutes, 1 hour, 1 day, 1 week) and computes per-window quality and drift; it suits feature tables, raw event tables, or any temporal data where the question is whether the distribution changed over time.
    • An InferenceLog profile is built on top of a Mosaic AI Model Serving inference table joined to ground truth labels and adds model performance metrics (accuracy, F1, RMSE) plus prediction drift on top of TimeSeries-style windowing; it is the only profile that knows about model output columns and label columns at the same time.

    The decision is mechanical:

    • if the use case is "is my model still accurate in production", the answer is InferenceLog;
    • if it is "did my training data distribution shift between this week and last week", the answer is TimeSeries;
    • if it is "produce a one-time profile for an audit", the answer is Snapshot.

    💡 Exam Trap: A Snapshot profile cannot answer "did the distribution drift" because it has no windowing concept, and it cannot compare two snapshots within the same monitor. If the scenario asks for drift over time, the correct profile is TimeSeries (or InferenceLog when joined to predictions); Snapshot is only correct for a point-in-time audit profile.

    ⚠️ Anti-Pattern: Pointing a TimeSeries monitor at a Mosaic AI Model Serving inference table and trying to compute accuracy from it. TimeSeries profiles do not know which column is the prediction and which is the label, so they cannot compute classification metrics; the inference table case requires an InferenceLog profile with problem_type set to "classification" or "regression", plus the prediction column, label column, and timestamp column declared in the spec.

    Endpoint Health and Infrastructure Metrics

    Mosaic AI Model Serving endpoints expose two layers of telemetry.

    The first is request-level data through the inference table, configured with auto_capture_config so every request and response lands in a Delta table inside Unity Catalog.

    The second is endpoint-level infrastructure metrics exposed through the Serving Endpoint UI and the served-entity logs surface, which capture:

    • latency (p50, p95, p99 of request duration)
    • request rate (requests per second per served entity)
    • error rate (HTTP 4xx and 5xx ratios)
    • CPU usage per replica
    • memory usage per replica
    • GPU utilisation when a GPU workload size is used

    These metrics are what the platform team watches for endpoint health independently of model quality.

    A spike in p99 latency without a drop in accuracy points at a capacity problem (workload size too small, or scale-to-zero with cold starts), while a sustained 5xx rate points at a model loading or schema validation failure rather than a drift problem.

    from databricks.sdk import WorkspaceClient
    from databricks.sdk.service.serving import (
     EndpointCoreConfigInput,
     ServedEntityInput,
     AutoCaptureConfigInput,
    )
    
    w = WorkspaceClient()
    
    w.serving_endpoints.create_and_wait(
     name="churn-endpoint",
     config=EndpointCoreConfigInput(
     served_entities=[
     ServedEntityInput(
     entity_name="prod.ml.churn",
     entity_version="42",
     workload_size="Small",
     scale_to_zero_enabled=False,
     workload_type="CPU",
     )
     ],
     auto_capture_config=AutoCaptureConfigInput(
     catalog_name="prod",
     schema_name="serving",
     table_name_prefix="churn_inference",
     enabled=True,
     ),
     ),
    )
    

    📊 Limit: A Mosaic AI Model Serving endpoint default quota is 200 queries per second per served entity for CPU workload type, and the inference table is written in micro-batches with a typical lag of about one minute from request to Delta visibility; both figures should be confirmed against the live service limits page before sizing a SLA contract.

    🎯 Scenario: The platform team gets a page from the on-call dashboard. Endpoint p99 latency rose from 180 ms to 1400 ms, request rate is flat at 60 RPS, error rate is zero, and CPU per replica is pegged at 95%. The Lakehouse Monitoring drift table shows no Jensen-Shannon drift on input features, and the InferenceLog accuracy metric has not moved. The team correctly concludes that this is an infrastructure capacity problem, not a model problem; the fix is to bump the workload size from Small to Medium and disable scale-to-zero so a cold replica is always warm, then revisit autoscale concurrency.

    The combined view that ML engineers should master is a two-axis grid: model quality (InferenceLog metrics) on one axis and endpoint infrastructure (serving metrics) on the other. The endpoint is healthy only when both are inside their thresholds, and any alert needs to point the on-call at the right axis so that the response is targeted at either the deployment configuration or the upstream data. ---

    Continue with the interactive course

    Track your progress, jump into practice questions and use the Shark AI tutor inside the Databricks - Machine Learning Professional learning hub.