Sub topic 3
Operational health: latency, errors and throughput
This chapter covers the first monitoring layer: whether the serving system is up and responding. It assumes you can deploy a model as a batch job or an API, and that you know basic Python. Statistical drift comes in later chapters. A model with perfect data can still fail if the service that hosts it is slow or broken.
Why this layer comes first
Operational metrics are the cheapest to collect and the fastest to react to. They tell you that something is wrong within seconds. They do not tell you whether predictions are good. A service can return fast, error-free, completely wrong answers, and a correct model can sit behind a service that times out. You need both views.
The three core signals
| Signal | What it measures | Typical unit |
|---|---|---|
| Latency | Time to answer one request | milliseconds |
| Error rate | Share of requests that fail | percent of requests |
| Throughput | Requests handled per time unit | requests per second |
Latency
Latency is the time between receiving a request and sending the response. Averages hide problems, because a few very slow requests barely move the mean. Track percentiles instead. The p50 is the median experience. The p95 and p99 show the slow tail, which is what users with timeouts actually feel.
For a model, latency has several parts: network, input validation, feature lookup, preprocessing and the model's own inference time. Record them separately when you can. A rise in feature lookup time points to a different fix than a rise in inference time.
Error rate
An error is a request that did not produce a usable prediction. Count at least these cases separately:
- Client errors, such as malformed input (HTTP 4xx).
- Server errors, such as crashes and timeouts (HTTP 5xx).
- Silent failures, such as a fallback value returned when a feature lookup fails.
Silent failures are the dangerous ones. The status code says success, but the model scored a default value. Log every fallback as its own counter.
Throughput
Throughput is the number of requests processed per unit of time. Watch it against your capacity. A sudden drop often means an upstream system stopped sending traffic. A sudden spike can mean a retry storm or a bot, and it usually pushes latency up next.
Computing the signals
Production systems usually export these through a metrics library and a dashboard tool. The sketch below shows the arithmetic on a list of request records so you can see what the dashboard computes.
import numpy as np
# Each record: (latency in ms, HTTP status)
requests = [
(42, 200), (51, 200), (47, 200), (390, 200), (45, 200),
(49, 200), (44, 500), (52, 200), (610, 200), (46, 422),
]
window_seconds = 10
latencies = np.array([r[0] for r in requests])
statuses = np.array([r[1] for r in requests])
p50, p95, p99 = np.percentile(latencies, [50, 95, 99])
server_errors = np.mean(statuses >= 500)
client_errors = np.mean((statuses >= 400) & (statuses < 500))
throughput = len(requests) / window_seconds
print(f"p50={p50:.0f}ms p95={p95:.0f}ms p99={p99:.0f}ms")
print(f"5xx rate={server_errors:.1%}, 4xx rate={client_errors:.1%}")
print(f"throughput={throughput:.1f} req/s")Notice that the median is near 48 ms, while p95 is several hundred. The mean would sit near 100 ms and describe neither group well.
How the pieces fit
Common errors
- Alerting on mean latency. Use p95 or p99.
- Counting only 5xx responses. Fallbacks and 4xx spikes also signal trouble.
- Ignoring low traffic. With few requests, percentiles and error rates are noisy, so set a minimum count before alerting.
- Measuring only at the load balancer. You then cannot tell which stage is slow.
Exercise
A service shows a mean latency of 80 ms and no 5xx errors, yet users report timeouts. Which metric should you check first, and why?
Show answer
Check p99 (or p95) latency. The mean hides a slow tail, so a small share of very slow requests can cause timeouts while the average looks healthy. Also check for silent fallbacks, since they return success codes.