Reliability and Cost Engineering › Service Objectives and the Error Budget
Language AI HandbookAll chapters For a single service, model latency in seconds and let equal one on success and zero on failure. The SLI counts successful requests that meet the deadline.
Here ranges over eligible requests in the measurement window. records success, is end-to-end latency in seconds, and is the deadline in seconds. A failure or a late success uses one bad event. The ratio is undefined when there are no eligible requests. With requests and target , the SLI meets the objective when . Equivalently, at most requests may be bad. The fixture stores the target as an exact fraction and takes the integer part of the nonnegative allowance.
The bad-event count lets you compare an incident with the window's allowance. A retry uses the error budget only if the logical request ultimately fails the SLI. A fast fallback counts as good only when it meets both the deadline and the service's success criteria, which may include a quality requirement.
A latency median alone describes the middle request and leaves the slower tail unspecified. Measure the fraction meeting the deadline and use request traces to find which calls and queues contributed to the misses.
The seeded example uses a lognormal latency distribution and independently assigns a failure flag to each request. These are illustrative assumptions.
PythonIn [3]Expand
import numpy as np
rng = np.random.default_rng(7)
# Single service: 20,000 requests, lognormal latency in seconds.
N = 20_000
mu_log, sigma_log = np.log(0.4), 0.6 # median 0.4s
latency = rng.lognormal(mu_log, sigma_log, size=N)
# Independent per-request failure hazard (timeouts, 5xx, parse errors).
P_FAIL = 0.004
success = rng.random(N) >= P_FAIL
TAU = 2.0 # latency threshold in secondsIf the logarithm of latency has mean and standard deviation , the lognormal median is seconds. Its mean is seconds. Increasing at fixed spreads the distribution while leaving its median unchanged.
Now compute the SLI, the error budget, and the percentile structure.
ConsoleOut [4]Expand
Observed SLI (success & <= 2.0s): 0.9932 SLO target: 0.9950 Error budget (fraction): 0.0050 -> 100 reqs / window Bad requests observed: 135 Budget remaining: -35 reqs p50 : 0.397s p90 : 0.854s p95 : 1.064s p99 : 1.591s p99.9 : 2.446s
The histogram shows the deadline against the latency distribution. It does not show which requests failed independently of latency.
PythonIn [5]Expand
lat_mean = float(latency.mean())
lat_p99 = float(np.percentile(latency, 99))
hist_edges = np.geomspace(latency.min(), latency.max(), 50)
hist_counts, _ = np.histogram(latency, bins=hist_edges)
hist_widths = np.diff(hist_edges)VisualizationOut [6]Expand

The 99.5% SLO allows 100 bad requests in this 20,000-request window. Compare that allowance with the bad count. The mean is under half a second, and some requests still miss the two-second deadline. The percentiles show how far the tail extends.
Specify where the clock starts and stops. For this example, success means a complete usable response by the deadline, with errors and timeouts in the eligible request denominator. Time to first token is a separate measure for streaming. Check what any provider timing includes. Your end-to-end clock can include queueing even when you cannot break out its provider-side share.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!