Swaran Soft
Technology

Implementing MLOps: A Practical Step-by-Step Guide

November 9, 20267 min readBy Yogesh Huja, Founder & CEO
Implementing MLOps: A Practical Step-by-Step Guide

Many data science teams can relate to the following scenario. An ML model is perfect in a notebook. Stakeholders are thrilled by its accuracy. Months later the business is still excited by its output. But then the model is deployed and soon starts to malfunction for unclear reasons.

Whilst the model was fine, the process surrounding it was the real issue.

MLOps is essentially applying best-practice processes (such as version control, testing and deployment along with monitoring) developed for software, to ML. This is more complex than for software as both the data and the code continue to evolve.

Below is a practical, step-by-step guide showing how we implement MLOps. We avoid dogma and concentrate on effective solutions.

Challenges of implementing ML

Unlike traditional software, which functions in a static manner (until new code is introduced), ML is influenced by data. And data continues to change in the real world.

Demand modelling built pre-festival will show different consumer behaviour post-festival. Last year’s fraud detection model may struggle to detect this year’s novel fraudulent behaviour. Similarly a factory’s defect detection model will encounter new raw materials supplied by a new supplier which are just slightly different.

As well as having to manage code, therefore, MLOps lets you control both the data and the resulting model.

1. Define ‘production’

Answer key business questions to inform the implementation:

  • What is the predicted data used for? Is it an instant function (for example, authorising a transaction in milliseconds) or batch-based (for example, a daily demand model)?
  • What contingency is in place if the model does not function, or is unavailable? Is there an alternative decision-making rule or human intervention?
  • How frequently is it likely that the model will need re-training? For example, weekly, monthly or annually?
  • Who is ultimately responsible for the model’s production outputs?

All of these considerations directly influence the technical approach adopted. Very different infrastructure will be needed for batch models re-trained monthly versus those provided via an API in real time, handling thousands of calls per minute.

2. Version

Without the ability to re-create something, you cannot trust, test or audit it. There are three elements to versioning:

  • Code – Most teams already use Git for this.
  • Data – For each version of a model, we can record precisely which data was used for training. This can be achieved using a range of options including DVC or simply effectively backed-up data in object storage.
  • Model and experiment details – Parameters, test results and the resulting model output for each training experiment. Again, widely-used open source option for this is MLflow.

In six months’ time, can a team member state definitively which data and code were used to generate the currently live model and subsequently reproduce this? If not, begin here.

3. Create pipelines

Although excellent for analysis, notebooks are ineffective for production due to issues such as non-reproducibility, non-sequential cell execution and human intervention. Models cannot therefore generally be reliably re-created.

Define a pipeline comprising distinct elements – data retrieval, validation, feature engineering, model training, testing and packaging. Each element should be able to function independently as a script or module, accepting specific inputs and producing specific outputs.

These can then be executed sequentially using pipeline orchestration tools such as Airflow, Prefect, Kubeflow Pipelines or well-structured workflow automation. Execution can also be time-based or event based (for example, on receipt of fresh data).

4. Validate data

Poor data can stealthily negatively affect models. Include data validation within your pipeline. For example:

  • Is the correct data in the right format for each column?
  • Are the values in reasonable ranges? (Negative ages and discounts exceeding 400% for example are cause for concern.)
  • Has the percentage of nulls increased since last time?
  • Does the data generally conform to that seen during model training?

On detecting an issue, halt the pipeline and notify someone. It is vastly less costly to identify and address poor data quality pre-training than to subsequently have to justify to the CFO why a model has performed poorly.

5. Test and test for fairness

Whilst a newly developed model must be tested, it also needs to ‘earn’ a production slot. Define testing criteria:

  • Performance – Does it outperform the existing live model on a test data set?
  • Segmentation – Does it provide satisfactory performance for key segments, such as by region, product range and/or customer type, not just generally?
  • Fairness – For models used for people-related decisions, are outputs fair across differing segments?
  • Functionality – Are response times acceptable and is the model memory and compute footprint appropriate?
  • Common sense – Do model predictions for a small sample of known cases seem reasonable?

Only models that successfully complete all tests move forward. All others are recorded so that the team can analyse them.

6. Deploy securely

Whilst many teams nervously await deployment, it need not be so stressful.

Firstly, ‘containerise’ your model (typically using Docker) to ensure it operates consistently. Then, deploy using a method that reduces risk. Options include;

  • Shadow deployment – The new model and existing live model operate in parallel. However, outputs from the new model are not used. Comparison can then occur with no effect on business operations.
  • Canary deployment – Initially, only a percentage (perhaps 5%) of business traffic is sent to the new model. Gradually raise this proportion if model metrics continue to be satisfactory.
  • Blue green deployment – Two identical environments exist. The transition between them can be instant and so too any reversal.

Regardless of the deployment method adopted, define and test a simple, unified rollback procedure. You’ll be thankful for this at some point!

7. Monitor effectively

Beyond ensuring that the model server is operational, there are three areas to monitor:

  • Environmental factors – Response times, error rates and resource consumption – basic elements.
  • Data drift – Is new data beginning to differ from that seen during model training? Often this is the first indicator of an issue.
  • Model performance – Having observed actual business outcomes (for instance, whether a customer left, if a transaction was fraudulent or if an item was faulty), compare these with model predictions.

As with data, the business owner, not just the data team, should define thresholds for when to be notified. Whereas a slight fall in model accuracy may be tolerable for a marketing model, this would not be the case for a credit model for example.

8. Support re-training

Issues can be identified through monitoring and re-training can then resolve them. Depending on the situation, re-training can be:

  • Scheduled – Such as on the first day of each month.
  • Event or metric driven – For example, when data drift or performance breaches defined thresholds.
  • Manually initiated – Where a human analyses the model prior to each re-training. This is appropriate for high risk models.

As pipeline, versioning and testing procedures are already in place, re-training can then easily become a regular, managed activity. This is the true advantage of correctly completing earlier steps.

Selecting your technology

Whilst it is not essential to invest in a costly proprietary solution, a strong open source technology stack will largely meet enterprise requirements. This comprises version control (Git), data and model versioning (DVC), model testing (MLflow) along with pipeline orchestration, containerisation (Docker) and/or a simple container host. Monitoring is supported by Prometheus and Grafana.

For Indian enterprises dealing with sensitive information, this technology stack is also happily implemented on-site or within a private cloud. Training data, models and predictions are all contained within an enterprise’s environment. This facilitates easier compliance with the DPDP Act and relevant industry regulation.

Typical evolution of MLOps maturity

LevelDescription
0: ManualNotebooks with manual workflows. Models are deployed manually.
1: PipelineAutomated model training. Data and models are versioned.
2: Automated deploymentTesting is undertaken. Models are containerised and deployed using secure methods.
3: ContinuousData drift is monitored. Retraining is automatically instigated where necessary. Full auditing is carried out.

Most organisations do not need to immediately adopt level 3 maturity. Achieving level 2 maturity for key models provides the majority of benefit.

Common errors

Across industries, we commonly observe the following errors:

  • Focusing on technology before understanding the challenge. Teams can spend many months investigating MLOps platforms without having yet deployed a model. Focus initially on one key model and develop the process around this.
  • Considering data scientists as a silo. Models often fail in production because data engineers, MLOps and business stakeholders only engage with each other at the point of deployment. From the outset, include these three groups in a shared weekly review process.
  • Only monitoring model accuracy. Often by the time this deteriorates, the business has already been affected. However, data drift notifications can provide notice of an issue several weeks in advance.
  • Failure to appoint a model owner. As with all key applications, somebody must be held accountable for a model’s production performance.

By avoiding these four points, you have already largely avoided the main challenges that impede ML progress.

Key message

Good MLOps implementation is not about adopting a technology platform. Rather it is about enabling consistent model development, secure deployment and effective visibility of a model’s production operation. Ensure that data, models and experiments are all versioned. Create pipelines. Implement testing. Monitor for data drift and routinely undertake model re-training.

Swaran Soft has been delivering enterprise software for over 25 years. We assist teams to transition ML and agentic AI from prototype to production, utilising open source technology to avoid vendor lock-in. Typically this is achieved within an 8 week fixed fee trial.

Want to talk it through with us? We run a free 45-minute AI Pilot Assessment. Drop a line to info@swaransoft.com, or ring +91 9220-313-650 (India) | +971-50-9292-650 (UAE). You'll find more at www.swaransoft.com

Free 45-minute AI Pilot Assessment

Share this article:
Yogesh Huja — Founder & CEO, Swaran Soft
Yogesh HujaFounder & CEO

AI Architect and Entrepreneur building India's Edge AI ecosystem. 25+ years in enterprise technology. Founder of Swaran Soft, Gignaati, and Copilots.in.

Published: ⏱ 7 min read