CertSafari
    Databricks Certified Machine Learning Associate· Lessons

    Domain 1 · Lesson 16/48

    Deploy code vs deploy models: choosing a promotion pattern on Databricks

    Identify scenarios where promoting code is preferred over promoting models and vice versa

    15 min read
    2.11% of exam
    5 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Explain why ML code and model artifacts move to production on different schedules
    • Choose deploy code, deploy models, or the hybrid pattern from a scenario's constraints on data access, training cost, and tooling
    • Promote a validated model version from a staging catalog to a prod catalog with copy_model_version
    • Name the privileges required to copy a model version across Unity Catalog catalogs

    Key concept

    Deploy code vs deploy models — Two ways to move ML work to production. Under deploy code, the training code is promoted and the model is retrained in each environment. Under deploy models, the model artifact is trained once and then promoted.

    1.Why code and models move on different schedules

    A model is the output of code, but the two don't change together. Training code can sit unchanged for months while the model it produces gets rebuilt every week on fresh data. The reverse happens too: a trained model stays fixed while the code that serves and monitors it keeps changing. Because the two change at different times, a team has to decide which one it moves toward production.

    Databricks illustrates this with two cases. A fraud-detection pipeline retrains weekly to pick up new transactions, so its model changes often and its code rarely does. A large deep neural network that classifies documents is expensive and slow to train, so it is retrained rarely, while its deployment, serving, and monitoring code is updated independently. The first case suggests promoting code. The second suggests promoting the trained artifact.

    In both cases, promotion means crossing a boundary between environments. Each stage normally has its own catalog, as covered in Separate dev/staging/prod environments, one Unity Catalog catalog each. So promotion takes one of two forms: the code is re-run inside the next environment's catalog, or a model version is copied into it.

    Checkpoint 1 of 8· Check yourself

    A fraud-detection team retrains its model every week on new transactions. The training code has not changed in months. Following the reasoning in this section, which should the team promote toward production?

    Sources1

    2.Deploy code: the default pattern

    Under deploy code, the training pipeline is what moves. It is written in development, then promoted to staging and on to production. The model is trained again in each environment. In dev, training is part of model development. In staging, it runs on a limited subset of data as part of integration testing. In production, it runs on the full production data and produces the final model. Databricks recommends this pattern in most situations and builds its recommended MLOps workflow around it.

    The strongest reason to use this pattern is data access. Training runs inside production, so only production needs read access to production training data. Dev and staging never need to see it. If a policy forbids any non-production cluster from reading that data, deploy code is the pattern that still works. Giving staging a temporary credential breaks the policy. A bundled artifact still has to be trained somewhere that can read the data.

    The second reason is safe automated retraining. The training code goes through code review, tests, and approval before it reaches production. When it later retrains on a schedule, it is running logic that has already passed those checks. A registered model version carries lineage showing which run produced it, but lineage only records history. It does not put the training logic through review. A checksum on the weights proves the file hasn't changed, which is a different question. The same review and testing also apply to supporting code, such as feature and inference pipelines, which go through integration tests in staging alongside the training code.

    The pattern has a cost on the people side. Data scientists have to hand their code to collaborators in a form that can be deployed, and that learning curve can be steep. Predefined project templates and workflows help. MLOps Stacks is one example: it keeps the whole development process as code in source control, so retraining is just another run of that code. Data scientists also need to be able to review training results from production, because they are the ones who can spot and fix ML-specific problems in a model trained there.

    Checkpoint 2 of 8· Check yourself

    Under deploy code, production retrains the model on a schedule with no one approving each new version. Why does Databricks consider this automated retraining safe?

    Checkpoint 3 of 8· Exam question

    A fraud detection team's compliance policy states that production customer transaction data must never leave the production Unity Catalog workspace, and no development or staging cluster may be granted read access to it. The team retrains its model weekly. Which deployment pattern satisfies this constraint?

    Checkpoint 4 of 8· Exam question

    An ML engineer is designing environment promotion for a new project and wants automated retraining to be safe: any change to the training logic should go through code review, unit tests, and integration tests before it is allowed to touch production. Which promotion pattern most directly delivers this guarantee?

    Sources2314

    3.Deploy models: train once, promote the artifact

    Under deploy models, training runs in development, and the resulting artifact is what moves. It is tested in staging and then deployed to production. Nothing is retrained along the way. The model that passed validation is the same model that serves.

    Databricks suggests considering this pattern when any of the following applies:

    • Model training is very expensive or hard to reproduce.
    • All work happens in a single Databricks workspace.
    • The team isn't working with external repos or a CI/CD process.

    Take a small team that trains a model for many hours on a large GPU cluster, works in one workspace, and has no Git integration or CI/CD. That team matches all three conditions. Rebuilding the model in every environment would multiply an expensive run, and promoting code would mean first building pipeline infrastructure they don't have. Promoting the registered model version means they train once. The handoff for data scientists is also simpler: they hand over a model, not a deployable codebase.

    The drawbacks follow from where training happens. Training runs in dev, so dev must be able to read the training data. If production data is blocked from development for security reasons, this pattern may not be viable. Automated retraining is also awkward. It can be scheduled in dev, but the team that deploys to production may not accept a dev-trained model as production-ready. Finally, only the model moves. Feature engineering, inference, and monitoring pipelines still have to be deployed to production separately.

    How the two patterns respond to the constraints that decide between them
    ConstraintDeploy codeDeploy models
    Production data readable only in prodWorks: training runs in prodMay not be viable: training runs in dev
    Training is very expensive or hard to reproduceModel is retrained in each environmentTrained once, then promoted
    Automated retrainingSafer: training code is reviewed and testedTricky: prod team may reject a dev-trained model
    Single workspace, no external repo or CI/CDSteep handoff without templates and workflowsFits: simpler handoff for data scientists
    Supporting pipelines (features, inference, monitoring)Follow the same path through stagingDeployed to production separately
    Where final unit and integration tests runStagingDevelopment

    Checkpoint 5 of 8· Match them up

    A team has chosen deploy models. Match each situation to what happens under that pattern.

    Tap a term, then the definition that fits it.

    Checkpoint 6 of 8· Exam question

    A small team runs all of its machine learning work inside a single Databricks workspace, does not use an external Git repository, and has no CI/CD pipeline configured. Training a particular model takes many hours on a large GPU cluster and is expensive to repeat. Which approach best fits this team's situation?

    Sources1

    4.The hybrid: deploy code to staging, deploy the model to production

    Some teams need the model trained on the full production dataset but don't want to pay for training again in production. The hybrid pattern covers this. Code is promoted from dev to staging as in deploy code. Staging trains the model on the full production dataset. That trained model is then promoted to production as in deploy models.

    The cost moves rather than disappears. Production skips training entirely, which saves compute there. Staging, though, now runs a full training job on production-scale data, which adds operating cost in staging. Staging also needs read access to the full production dataset. So the hybrid isn't an option when policy restricts that data to production alone. In that case only pure deploy code works.

    Checkpoint 7 of 8· Check yourself

    Compared with pure deploy code, how does the hybrid pattern change where training cost falls?

    Sources1

    5.Promoting a model version across catalogs with copy_model_version

    When a team promotes a model, either through deploy models or through the second half of the hybrid, the move is a copy between registered models in different catalogs. A version registered in staging.ml_team.fraud_detection becomes a new version of prod.ml_team.fraud_detection. It is not retrained. Databricks still recommends deploying ML pipelines as code, so that production models come from automated training in production. Copying is the alternative for cases where retraining in every environment is too expensive.

    Copying version 1 of the staging model into the prod catalog's registered model (MLflow 2.8.0 and above)python
    import mlflow
    mlflow.set_registry_uri("databricks-uc")
    
    client = mlflow.tracking.MlflowClient()
    src_model_name = "staging.ml_team.fraud_detection"
    src_model_version = "1"
    src_model_uri = f"models:/{src_model_name}/{src_model_version}"
    dst_model_name = "prod.ml_team.fraud_detection"
    copied_model_version = client.copy_model_version(src_model_uri, dst_model_name)

    The source model is identified by a models:/ URI that includes a version number. The destination is just the three-level name of the target registered model. copy_model_version is a method on MlflowClient and needs MLflow 2.8.0 or later. It returns the new version object, and its version field is the number assigned in the prod model.

    Unity Catalog privileges control who can perform the copy. The caller needs:

    • USE CATALOG on both the staging and prod catalogs.
    • USE SCHEMA on staging.ml_team and prod.ml_team.
    • EXECUTE on the source model staging.ml_team.fraud_detection.
    • Ownership of prod.ml_team.fraud_detection, or the CREATE MODEL VERSION privilege on it.

    Those grants are the whole promotion policy. Only someone who can read the staging model and write to the prod model can promote. No separate approval rules have to be configured. The same chain can be extended to other environments, such as dev, qa, and prod, and each catalog enforces its own access control. After the copy, the version is validated in production and then marked for deployment with an alias. That step is taught in promoting a challenger to champion with aliases.

    Checkpoint 8 of 8· Fill the gap

    Which MlflowClient method completes this sample, which promotes version 1 of the staging model into the prod catalog's registered model without retraining it?

    import mlflow
    mlflow.set_registry_uri("databricks-uc")
    
    client = mlflow.tracking.MlflowClient()
    src_model_name = "staging.ml_team.fraud_detection"
    src_model_version = "1"
    src_model_uri = f"models:/{src_model_name}/{src_model_version}"
    dst_model_name = "prod.ml_team.fraud_detection"
    copied_model_version = client. ? (src_model_uri, dst_model_name)

    Sources5

    Sources

    (5)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Models are created by code, but the resulting model artifacts and the code that created them can operate asynchronously.”
      ↩︎ Why code and models move on different schedules
      “Typically an environment (development, staging, or production) corresponds to a catalog in Unity Catalog.”
      ↩︎ Why code and models move on different schedules
      “The learning curve for data scientists to hand off code to collaborators can be steep.”
      ↩︎ Deploy code: the default pattern
      “Model training is very expensive or hard to reproduce.”
      ↩︎ Deploy models: train once, promote the artifact
      “You are not working with external repos or a CI/CD process.”
      ↩︎ Deploy models: train once, promote the artifact
      “the team responsible for deploying the model in production might not accept the resulting model as production-ready.”
      ↩︎ Deploy models: train once, promote the artifact
      “in the deploy models pattern, final unit and integration testing is performed in the development environment.”
      ↩︎ Deploy models: train once, promote the artifact
      “you can use a hybrid approach by deploying code to staging, training the model, and then deploying the model to production.”
      ↩︎ The hybrid: deploy code to staging, deploy the model to production
      “The two patterns differ in whether the model artifact or the training code that produces the model artifact is promoted towards production.”
      ↩︎ Key concept
      “Automated model retraining is safer, since the training code is reviewed, tested, and approved for production.”
      ↩︎ Exam trap 1
      “If production data is not accessible from the development environment (which may be true for security reasons), this architecture may not be viable.”
      ↩︎ Exam trap 2
      “Supporting code, such as pipelines used for feature engineering, inference, and monitoring, needs to be deployed to production separately.”
      ↩︎ Exam trap 3
      “This approach saves training costs in production but adds an extra operation cost in staging.”
      ↩︎ Exam trap 4
      “The code may not change very often, but the model might be retrained every week to incorporate new data.”
      ↩︎ Checkpoint
      “In organizations where access to production data is restricted, this pattern allows the model to be trained on production data in the production environment.”
      ↩︎ Prediction
      “Automated model retraining is safer, since the training code is reviewed, tested, and approved for production.”
      ↩︎ Checkpoint
      “Supporting code, such as pipelines used for feature engineering, inference, and monitoring, needs to be deployed to production separately.”
      ↩︎ Checkpoint
      “This approach saves training costs in production but adds an extra operation cost in staging.”
      ↩︎ Checkpoint
    2. 2.
      “In most situations, Databricks recommends that during the ML development process, you promote code, rather than models, from one environment to the next.”
      ↩︎ Deploy code: the default pattern
    3. 3.
      “It requires only the production environment to have read access to prod training data.”
      ↩︎ Deploy code: the default pattern
    4. 4.
      “Deploying the code automates the ability to build the model, making it much easier to retrain the model when necessary.”
      ↩︎ Deploy code: the default pattern
    5. 5.
      “Instead, you can copy model versions across registered models in Unity Catalog to promote them across environments.”
      ↩︎ Promoting a model version across catalogs with copy_model_version
      “The following code snippet uses the copy_model_version MLflow Client API, available in MLflow version 2.8.0 and above.”
      ↩︎ Promoting a model version across catalogs with copy_model_version
      “In addition, you need either ownership of the destination model prod.ml_team.fraud_detection or the CREATE MODEL VERSION privilege on it.”
      ↩︎ Promoting a model version across catalogs with copy_model_version
      “Access control is enforced as configured in each environment.”
      ↩︎ Promoting a model version across catalogs with copy_model_version

    Spotted a mistake, or was something unclear? Tell us.