Monitoring models in production

Watch the service, the inputs and, when true labels arrive, the accuracy of a deployed model.

Lesson 60 of 6610 minBeginner

You will learn to

  • List what to monitor in a deployed model and why
  • Separate service health from model health
  • Set alert thresholds that avoid noise

Before this lesson

Intuition

A car has a dashboard, but the dashboard only shows part of the story. The speedometer tells you the engine runs. It does not tell you that the road has changed from highway to gravel and your tyres are wrong for it.

A deployed model is the same. Monitoring has three layers, and each answers a different question.

  1. Service health: is the system running? Requests per minute, error rate and latency. These arrive in seconds and are the same as for any web service.
  2. Data health: do the inputs still look like the training data? If customers now behave differently, the model sees rows it was never trained on. This is called drift and the next lesson explains it. You can check it as soon as requests arrive, without knowing the right answers.
  3. Model health: are the predictions still right? This needs the true outcomes (labels): whether the customer really left, whether the loan really defaulted. Labels often arrive weeks later, so this layer is the slowest but the most honest.

Because the layers differ in speed, a good setup uses fast ones as early warnings and slow ones as the final verdict.

Picture it

Signal arrives inService healthRequests, errors, p50 and p95 latencySecondsData healthAre the inputs still like the training data? (drift)Hours to daysModel healthAre the predictions still right? Needs true labelsDays to months
Three layers of monitoring. The faster the signal arrives, the less it tells you about whether predictions are correct.

The math

Error rate is the share of requests that failed:

error rate=failed requestsall requests\text{error rate} = \frac{\text{failed requests}}{\text{all requests}}

Percentiles summarise latency. With latencies sorted from smallest to largest, x(1)≤⋯≤x(n)x_{(1)} \le \dots \le x_{(n)}, the p95 is a value that 95% of requests are faster than. It matters because a few very slow requests can ruin the experience of real users while the mean still looks fine.

Alert thresholds and noise. An alert that checks a metric once and fires when it crosses a limit will fire by chance whenever the metric is noisy. Averaging over a window of nn observations reduces random scatter roughly by a factor of n\sqrt{n}. A 10-minute window therefore reacts to real changes and ignores single spikes. The price is a delay of up to the window length.

Worked example

An endpoint handled 1,000 requests in the last hour and 12 of them failed.

error rate=121000=1.2%\text{error rate} = \frac{12}{1000} = 1.2\%

Take the latencies, in milliseconds, of the last 20 requests (illustrative values), already sorted:

42, 45, 47, 48, 50, 51, 52, 53, 55, 56, 58, 60, 61, 63, 66, 70, 78, 95, 140, 420

  • The mean is 80.5 ms. It looks acceptable, but it hides the tail.
  • The p50 is the value at position 10 (counting from 0): 58 ms.
  • The p95 is the value at position 19, the last one: 420 ms.

The typical request is fast, but 1 in 20 is more than seven times slower. A rule "notify when p95 is above 300 ms over 10 minutes" would catch this. A rule "notify if any request exceeds 100 ms" would fire twice in these 20 requests alone, and people would soon mute it.

Now the data layer. Suppose the model was trained on customers whose average age was 41 and today's requests average 29. Nothing failed, latency is flat, yet the inputs have moved. Only a data check shows it. That is the job of the next lesson.

How mlflow does it

  • Live metrics. Each endpoint's Overview tab shows Predictions, Errors, p50 latency and p95 latency. Latency is measured over the last 100 predictions.
  • Deployments list. The columns Endpoint, Access, Predictions, Errors, p50, p95 and Last prediction give a fleet view.
  • Monitor tab. Holds drift thresholds, drift alerts, drift reports and scheduled retraining for the endpoint.
  • Alert rules. The Health tab of the Deployments page lets you create rules on p95 latency, p50 latency, requests per minute, error rate or drift score, over a window, and notify by Slack, email or webhook.
  • Models served elsewhere. A model you run outside mlflow can send its predictions and true outcomes to mlflow over HTTP with an ingestion key and be monitored in the same way.

Common mistakes

  • Watching only uptime. A healthy service can serve a decayed model. Add a data check and, when you can, outcome checks.
  • Averaging latency. The mean hides the slow tail that users feel. Use p50 and p95.
  • Alerting on single events. Every spike pages someone and trust in alerts falls. Use a window and a sustained threshold.
  • Setting thresholds once and never reviewing them. Traffic changes. Review limits when volume or the model changes.
  • No owner for alerts. An alert nobody is responsible for is decoration. Decide who looks at it and what they do first.

Try it in mlflow

Read the live metrics of an endpoint

  1. Open Deployments and click an endpoint.
  2. On the Overview tab, read Predictions, Errors, p50 latency and p95 latency.
  3. Open the Monitor tab to see drift alerts and thresholds for the same endpoint.
  4. Go back to the Deployments list and open the Health tab to see Alert rules and Deployment metrics.
Open in mlflow

Read in the docs

Check your understanding

  1. 1. An endpoint answers every request with no errors and fast. Does that prove the model is still good?
  2. 2. Why can accuracy usually not be monitored in real time?
  3. 3. Which alert rule is least likely to cause alert fatigue?