Sub topic 4
Measuring availability: time-based versus request-based
This chapter assumes you know what availability and the nines mean, and that you can turn a target such as 99.9% into a downtime budget. You should be comfortable with percentages and short Python snippets. Here you will learn the two main ways to measure availability, how each can mislead you, and how to pick one.
Two questions, two measurements
Availability is the fraction of the time or the requests for which a service works correctly. That sentence hides a choice. You can count minutes, or you can count requests.
- Time-based availability asks: during what fraction of the period was the service up?
- Request-based availability asks: what fraction of the requests were handled successfully?
The two usually give similar numbers for a service with steady traffic and clean, total outages. They diverge when traffic is uneven, when failures are partial, or when "up" is hard to define. Those are the normal conditions of production systems, so the choice matters.
Time-based availability
Time-based measurement divides the period into slots and labels each slot as up or down. The availability is the share of up slots.
availability = up_time / total_timeIn practice you rarely watch a service continuously. A probe (a synthetic check, often called a health check or black-box monitor) hits an endpoint at a fixed interval, for example every 60 seconds. Each probe result marks that interval as good or bad.
def time_based_availability(probe_results):
"""probe_results: list of booleans, one per probe interval."""
if not probe_results:
raise ValueError("no probes recorded")
return sum(probe_results) / len(probe_results)
# 30 days of one-minute probes, with 50 failed probes in a row
minutes = 30 * 24 * 60
results = [True] * (minutes - 50) + [False] * 50
print(f"{time_based_availability(results):.4%}") # 99.8843%Strengths
- It is easy to explain. "We were down for 50 minutes" needs no statistics.
- It maps directly onto downtime budgets. A 99.9% target means about 43.2 minutes of downtime per 30 days.
- It works when you have no request logs, or when the service has no natural request unit, such as a database that clients hold connections to.
Weaknesses
- Probe resolution limits accuracy. With a 60-second interval, an outage of 20 seconds may be missed entirely, and an outage of 61 seconds is recorded as 1 or 2 minutes. Shorter intervals reduce the error and increase probe load.
- Probes are not users. A probe may call a simple endpoint such as
/healththat stays green while the checkout flow is broken. It may also run from one location and miss a regional network problem. - Every minute counts equally. Three minutes of outage at 03:00 local time count the same as three minutes at the peak of the business day, though far fewer users noticed the first.
- It needs a rule for partial failure. If 5% of requests fail during a minute, was that minute up or down? Time-based measurement forces a binary label, and you must pick a threshold.
Request-based availability
Request-based measurement counts the outcomes of real (or representative) requests.
availability = successful_requests / valid_requestsdef request_based_availability(successful, total_valid):
if total_valid == 0:
raise ValueError("no valid requests in the window")
return successful / total_valid
print(f"{request_based_availability(9_996_000, 10_000_000):.3%}") # 99.960%Strengths
- It weights by traffic. An outage during a busy hour hurts the number more than the same outage at night, which matches user impact better.
- It handles partial failure naturally. If 5% of requests fail, availability for that period is 95%. No threshold is needed.
- It needs no probes. The data comes from load balancer logs, server metrics, or client telemetry.
- It fits error budgets. The budget is a count of failures the SLO permits, as the budget formula later in this chapter shows.
Weaknesses
- Low traffic makes it noisy. If a service gets 200 requests a day, one failed request changes availability by 0.5%. Over short windows the number swings widely.
- It can hide a total outage. If a service is down for three hours at night with almost no traffic, the request-based number barely moves. The few users affected may still be important.
- Retries distort it. If clients retry failed requests and the retry succeeds, the failure may not appear in the success ratio, though users saw latency. Conversely, retry storms during an outage can inflate the failure count far beyond the number of users affected.
- A failed service may log nothing. If the load balancer or the whole server is down, requests never reach the component that does the counting. Those requests are invisible to server-side metrics, so server-side request-based availability can read 100% during a real outage.
The last point is the most common trap. Measure as close to the user as you can afford, for example at the load balancer, a CDN edge, or in the client.
The same incident, two numbers
Consider a service that handles 1,000 requests per minute during the day (14 hours) and 50 per minute at night (10 hours). Over a 24-hour day, a 30-minute outage occurs. Compare the two measurements for an outage at midday and for one at night.
DAY_MINUTES, NIGHT_MINUTES = 14 * 60, 10 * 60
DAY_RATE, NIGHT_RATE = 1000, 50
total_minutes = DAY_MINUTES + NIGHT_MINUTES
total_requests = DAY_MINUTES * DAY_RATE + NIGHT_MINUTES * NIGHT_RATE
def compare(outage_minutes, rate):
failed = outage_minutes * rate
time_based = 1 - outage_minutes / total_minutes
request_based = 1 - failed / total_requests
return time_based, request_based
for label, rate in (("midday", DAY_RATE), ("night", NIGHT_RATE)):
t, r = compare(30, rate)
print(f"{label}: time={t:.4%} request={r:.4%}")
# midday: time=97.9167% request=96.4286%
# night: time=97.9167% request=99.8214%The time-based number is identical in both cases. The request-based number is 96.43% for the midday outage and 99.82% for the night outage, reflecting how many requests actually failed. Neither is wrong. They answer different questions.
What counts as a valid request
A request-based measure needs a clear definition of the numerator (successes) and the denominator (valid requests). Decide these before an incident, not during one.
| Question | Typical decision |
|---|---|
| Does an HTTP 500 count as a failure? | Yes. Server errors are the standard failures. |
| Does an HTTP 404 count as a failure? | Usually no. The server answered correctly. |
| Does an HTTP 429 (rate limited) count? | Depends. Exclude it if the client exceeded an agreed quota. |
| Does a very slow success count as good? | Often no. Define a latency threshold, such as 1 second at the 99th percentile. |
| Do requests from health checks or load tests count? | Usually excluded from the denominator. |
| Do client errors such as HTTP 400 count? | Usually excluded, since the caller sent a bad request. |
A response that is correct in format but wrong in content, such as an empty search result caused by a broken index, is a failure that status codes cannot see. If it matters, add a check that validates the content, or measure it through a separate quality metric.
def is_good(status_code, latency_ms, latency_limit_ms=1000):
"""Classify one request for an availability SLI."""
if 400 <= status_code < 500:
return None # excluded from the denominator
return status_code < 500 and latency_ms <= latency_limit_ms
def sli(events):
classified = [is_good(s, l) for s, l in events]
valid = [c for c in classified if c is not None]
return sum(valid) / len(valid)
events = [(200, 120), (200, 90), (500, 30), (404, 15), (200, 2500), (200, 300)]
print(f"{sli(events):.2%}") # 60.00%Here the 404 is excluded. Of the remaining five requests, three are good, one is a 500, and one succeeded but exceeded the latency limit, which gives 60%.
Choosing a window
The measurement window changes what the number means.
- Rolling windows (for example, the last 30 days) are updated continuously and have no cliff at the month boundary. They suit operational dashboards and error budgets.
- Calendar windows (for example, each month) match how contracts and invoices work. They reset to a clean slate, which can let a team spend a whole budget in the last days of a month with no consequence.
- Short windows (5 minutes or 1 hour) detect problems quickly but are noisy for low-traffic services.
Many teams use both. They track a rolling 28- or 30-day window for the SLO and also alert on short windows to catch fast burns early.
Aggregating across components and regions
Averaging can hide a localized outage. Suppose a service runs in four regions. Region C fails for an hour while the others are healthy. A global request-based number may remain high because region C carries 10% of traffic, but every user in region C had a full outage.
Options:
- Measure each region or customer segment separately and report the worst, or all of them.
- Define the SLI per user journey (login, checkout, search) instead of per server.
- Measure from the client side, which sees what users see regardless of which server failed.
Which should you use?
Neither method is universally better. Use the following as a guide.
| Situation | Better fit |
|---|---|
| Steady, high-volume API with real traffic logs | Request-based |
| Traffic varies sharply by hour or season | Request-based, possibly plus a time-based check |
| Very low traffic, or long idle periods | Time-based, using synthetic probes |
| Contract written in terms of uptime minutes | Time-based, to match the contract |
| Partial failures are common | Request-based |
| Service has no request unit, such as a batch system or connection-oriented database | Time-based |
| You need to catch outages that block all traffic | Client-side or probe-based, not server-side counting |
A practical combination is request-based measurement for the SLO and error budget, plus synthetic probes that run continuously. The probes cover the cases where real traffic is too sparse or where server-side counters cannot see the failure.
Common errors
- Reporting a monthly number from probes with large gaps. If the probe system itself was down, missing data is not "up". Treat gaps as unknown, and decide in advance whether unknown counts as down.
- Counting only requests that reached the application. Failures at the DNS, network, TLS, or load balancer layers never appear in application logs.
- Mixing numerators and denominators from different sources. Successes from one log and totals from another will not reconcile.
- Comparing numbers measured differently. A 99.95% time-based figure and a 99.95% request-based figure are not equivalent. State the method with the number.
- Treating the average as the experience. Global averages hide per-region and per-customer outages.
Diagram: where measurement can happen
The further left the measurement point, the more failure types it can see. The further right, the easier the data is to collect.
Exercises
Exercise
A service receives 8,000,000 valid requests in a 30-day window, of which 6,000 fail. What is its request-based availability, and what would a time-based measurement say if the failures all occurred in one continuous 15-minute outage?
Show answer
Request-based: 1 - 6,000 / 8,000,000 = 0.99925, or 99.925%. Time-based: a 30-day window has 43,200 minutes, so 1 - 15 / 43,200 = about 0.99965, or 99.965%. The two differ because the outage hit a stretch of high traffic: 15 minutes carried 6,000 failed requests, which is 400 per minute, while the average over the window is about 185 requests per minute.
Exercise
Your service's application metrics show 100% availability for a night during which users reported they could not connect. Give two possible causes and one way to detect each.
Show answer
Possible causes: (1) The load balancer or network path failed, so requests never reached the application and were never counted. Detect it with load balancer logs or an external synthetic probe. (2) A DNS or TLS failure stopped clients before they sent a request. Detect it with a probe from outside your network or with client-side telemetry. In both cases the measurement point was past the failure.
Exercise
A service handles about 100 requests per day. Why is a daily request-based availability figure a poor basis for alerting, and what would you add?
Show answer
With so few requests, a single failure moves the daily figure by 1%, so the number is noisy and a normal blip can look like a breach. Use a longer window, such as 30 days, for the SLO, and add synthetic probes at a regular interval so that outages are detected even when real traffic is sparse.