Pidoku

Archive

This learning material is in the archive. It is not currently maintained and has not been updated with the latest information, so tool versions, prices and dates may be out of date.

User Journeys and SLIs

Module 2 Lesson 2.a 45 min Difficulty 2/5

Prerequisites 1.b

The idea in one minute#

Start from what users are trying to do — a critical user journey (CUJ) such as “log in”, “search”, “pay”. For each one, define a service level indicator (SLI): the ratio of good events to valid events, measured as close to the user as you can. “Good” is precise: status not 5xx, finished within 400 ms, response complete.

An SLI has two halves. The specification says what you mean in plain words (“checkout requests that succeed within 1 s”). The implementation says how it is measured (“load balancer logs, status < 500 and request_time < 1.0, excluding health checks”). Different implementations of the same specification can give very different numbers.

An analogy#

A restaurant does not measure “the oven is on”. It measures whether diners got the dish they ordered, hot, within twenty minutes. The oven matters only because of that. CPU, memory and queue depth are ovens; the SLI is the diner’s plate.

A picture#

flowchart LR
  U[":i-user: <b>User</b>"] --> CL[":i-smartphone: <b>Client</b><br/><small>RUM: truest, noisiest</small>"]
  CL --> CDN[":cloudflare: <b>CDN / edge</b>"]
  CDN --> LB[":envoyproxy: <b>Load balancer</b><br/><small>best default for SLIs</small>"]
  LB --> APP[":go: <b>Service</b><br/><small>app metrics: easy, misses LB failures</small>"]
  APP --> DB[(":postgresql: <b>DB</b>")]
  PR[":i-radar: <b>Prober</b><br/><small>synthetic: works with zero traffic</small>"] -.-> CDN
  class U neutral
  class CL,CDN,LB io
  class APP compute
  class DB memory
  class PR queue

The closer to the user, the more failures the SLI sees — and the more noise it picks up from things you do not control (bad mobile networks). The load balancer is usually the best compromise: it sees requests that your service never received because it was crashed.

How it really works#

Finding critical user journeys#

List what users do, then rank by how much they care. For a web shop:

JourneyWhy it mattersTypical SLI kinds
Browse and search productsFirst impression, volumeavailability, latency
Add to cartIntent to buyavailability
Checkout and payRevenueavailability, latency, correctness
View order statusSupport load if brokenavailability, freshness
Admin: update pricesInternal, rareavailability (looser)

Pick 3–5 journeys. A dozen SLOs per service is a sign nobody chose.

The SLI menu#

SLI kindGood eventValid eventsGood for
AvailabilityResponse not 5xx (and not a timeout)All requests except health checks and client errorsRequest/response services
LatencyFinished in under a thresholdSuccessful requests (or all)Interactive paths
QualityFull answer, not degradedRequestsServices with fallbacks
FreshnessData younger than a threshold when readReadsPipelines, caches, search indexes
CorrectnessOutput matches an independent checkSampled outputsBilling, data processing
Coverage / throughputRecords processed in timeRecords expectedBatch jobs
DurabilityObject still readableObjects storedStorage

Latency SLIs use a threshold, not an average: “99% of requests under 400 ms” is an SLI, “mean latency 120 ms” is not, because the mean hides the slow tail that users actually feel. It is common to have two latency thresholds: one for typical experience (90% < 200 ms) and one for the tail (99% < 1 s).

What counts as “valid”#

Deciding what to exclude is where SLIs go wrong.

  • Exclude health checks, synthetic load tests, and requests that were the client’s fault (400, 401, 404 for a bad URL).
  • Include 429s you returned because you were out of capacity — that is your failure.
  • Include timeouts and connection resets, even though no status code was logged. A common bug is an SLI that only counts responses, so a crashed service with no responses looks 100% available.
  • Decide explicitly about retries: is a request that failed once and succeeded on retry good? From the user’s point of view, usually yes — so measure at the layer that sees the final result.

Where to measure#

SourceSeesMissesUse
Client (RUM)Everything the user sawNothing, but includes their networkLatency SLIs for web and mobile, as a check
Edge / load balancer logsEvery request that arrived, including when the app was downFailures before the edge (DNS)Default for availability and latency
Service metricsWhat the process handledRequests the process never gotFine when an LB-level view also exists
Synthetic probesA scripted journey, constant rateReal user varietyLow-traffic services; end-to-end checks (3.b)

Request-based versus window-based SLIs#

  • Request-based: good requests / valid requests over the SLO window. Use when traffic is steady.
  • Window-based (time-slice): divide time into 1-minute slices, call a slice good if, say, its p99 was under 400 ms or its error rate under 1%, then good slices / total slices. Use when traffic is very low or very spiky, where a handful of requests would otherwise dominate.

A worked example#

Checkout API. Specification: “Checkout requests succeed within 1 second.” The raw access log has ten requests:

#PathStatusDurationValid?Good?
1/checkout200230 msyesyes
2/healthz2002 msno — health check—
3/checkout40015 msno — malformed request—
4/checkout2001.8 syesno — too slow
5/checkout50330 msyesno
6/checkout200640 msyesyes
7/checkout4295 msyes — we shed loadno
8/checkout200310 msyesyes
9/checkout— (reset)30 syesno — timeout
10/checkout200410 msyesyes

Valid: 8. Good: 4. SLI = 50%. A naive “non-5xx over all lines” would say 9 of 10, 90% — wrong on every count. The program below implements the correct rules.

Code#

Go
// sli.go — compute availability and latency SLIs from access log lines, with exclusions.
package main

import (
	"bufio"
	"fmt"
	"strconv"
	"strings"
	"time"
)

// method path status duration ; status "-" means the connection broke with no response.
const accessLog = `POST /checkout 200 230ms
GET /healthz 200 2ms
POST /checkout 400 15ms
POST /checkout 200 1800ms
POST /checkout 503 30ms
POST /checkout 200 640ms
POST /checkout 429 5ms
POST /checkout 200 310ms
POST /checkout - 30000ms
POST /checkout 200 410ms`

type event struct {
	path     string
	status   int // 0 = no response
	duration time.Duration
}

func parse(line string) (event, error) {
	f := strings.Fields(line)
	if len(f) != 4 {
		return event{}, fmt.Errorf("bad line %q", line)
	}
	d, err := time.ParseDuration(f[3])
	if err != nil {
		return event{}, err
	}
	st := 0
	if f[2] != "-" {
		if st, err = strconv.Atoi(f[2]); err != nil {
			return event{}, err
		}
	}
	return event{f[1], st, d}, nil
}

// valid excludes traffic that is not a user's attempt at the journey, and the user's own mistakes.
func valid(e event) bool {
	if e.path == "/healthz" {
		return false
	}
	if e.status >= 400 && e.status < 500 && e.status != 429 { // 429: our capacity, our fault
		return false
	}
	return true
}

func available(e event) bool { return e.status != 0 && e.status < 500 && e.status != 429 }

func main() {
	const threshold = time.Second
	var validN, availN, fastN, naiveGood, naiveAll int
	sc := bufio.NewScanner(strings.NewReader(accessLog))
	for sc.Scan() {
		e, err := parse(sc.Text())
		if err != nil {
			fmt.Println(err)
			continue
		}
		naiveAll++
		if e.status != 0 && e.status < 500 {
			naiveGood++
		}
		if !valid(e) {
			continue
		}
		validN++
		if available(e) {
			availN++
			if e.duration < threshold {
				fastN++
			}
		}
	}
	fmt.Printf("valid events:              %d\n", validN)
	fmt.Printf("availability SLI:          %.1f%%\n", 100*float64(availN)/float64(validN))
	fmt.Printf("good (available and <%v): %.1f%%   ← the checkout SLI\n", threshold, 100*float64(fastN)/float64(validN))
	fmt.Printf("naive non-5xx / all lines: %.1f%%   ← what a careless SLI reports\n", 100*float64(naiveGood)/float64(naiveAll))
}

Remember this#

  • Start from critical user journeys; pick 3–5.
  • SLI = good events ÷ valid events. Write the specification in words and the implementation in detail.
  • Measure close to the user — the load balancer is the usual default.
  • Count timeouts and resets; count your own 429s; exclude health checks and client errors.
  • Use thresholds for latency, never averages. Use time-slice SLIs for low-traffic services.

Try it#

  1. Run sli.go. Decide that request 7 (429) should be excluded instead. How much does the SLI change, and why would that be the wrong decision for checkout?
  2. List the critical user journeys for a product you use daily. Write one SLI specification for each.
  3. For one of them, write the implementation: which log or metric, which fields, which filters.

Check yourself#

  1. Why does a service-level metric miss the worst outages?
  2. Is a 429 a good or bad event? Does it depend on who caused it?
  3. When would you choose a time-slice SLI over a request-based one?
  4. Give an example of an SLI specification that has two plausible implementations with different results.

Sources#

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in