Platform Engineering · Lesson 338

Correlation Versus Causation in Incident Analysis: From "Changed at the Same Time" to Proven Cause

During an incident, many things change at once, and correlation tools will happily rank all of them. Correlation says two signals moved together; causation says one made the other happen, and only causes are worth acting on. Moving from one to the other takes a short, repeatable discipline: check that the candidate sits upstream of the symptom in the dependency graph, that it changed before the symptom, that no common cause explains both, and then intervene (roll back, disable a flag, compare a canary) and watch whether the symptom follows. This lesson follows one checkout latency incident and shows the two classic mistakes: acting on the top correlated change, and missing the common cause behind several correlated signals.

Difficulty: Advanced · Know this first: Lesson 280, Lesson 336

What you will learn

By the end of this lesson you can work at four levels:

This page teaches it with a plain-language analogy, an animated diagram with normal and failure scenarios, a simulator, a quiz, basic, intermediate, advanced, and master checks, the expert detail ("Go deeper"), a production incident, a hands-on lab with commands and their output, and a production design exercise.

Run it as:

When it breaks, I check

One thing to remember

Where the time goes

This bar adds up minutes from the alert to proven cause and restored latency. It is a worked example, not a measurement. The candidates and confounders hops decide how much time goes to the wrong fixes.

Try it: how does the team decide what to act on?

Pick the team's method, and whether a common cause such as a traffic surge is behind the symptom.

0wrong actions
22 minto recovery
interventionevidence

Check yourself

Three questions. No score is saved anywhere — this is just you against the material.

Basic to master

Causal analysis in operations grows in four levels: reading signals honestly, testing candidates, proving causes safely, and measuring the tools that suggest them.

Basic — Read signals honestly

At the basic level you know what correlation can and cannot tell you.

  • Correlation, coincidence, reverse causation, and common causes.
  • Totals versus per-request rates.
  • One UTC timeline for changes and symptoms.

Where it breaks: treating a dashboard where many lines rose together as proof of anything.

Try it: Basic

Retries rose one minute after latency did. Cause or effect?

Now do it: Mark causes and effects on the timeline of a past incident.

Intermediate — Test candidates

At the intermediate level you can test each candidate quickly.

  • Topology from traces and the dependency graph.
  • Time order at fine resolution, including lags.
  • Confounders: traffic, shared dependencies, scheduled jobs, business events.

Try it: Intermediate

A change to a service that checkout never calls correlates at 0.9 with checkout latency. What do you conclude?

Now do it: Check one past incident's top suspect against traces.

Advanced — Prove causes safely

At the advanced level you prove causes with interventions that are safe to make.

  • The most reversible intervention first: flag off, traffic shift, rollback.
  • Canary comparisons: old and new version under the same traffic.
  • One change at a time, with the symptom watched after each.

Try it: Advanced

Why change one thing at a time during mitigation?

Now do it: Write a rule into your incident runbook: one change, then watch.

Master — Measure the tools

At the master level correlation tools are measured against proven causes.

  • Postmortems record evidence and confidence per candidate.
  • Proven causes become labelled evaluation data for AIOps ranking.
  • Precision of the top suggestion reported, and trust adjusted to it.

Trade-off: testing candidates takes minutes; acting on a score is faster until it is wrong, and every wrong action is another change in the middle of an incident.

Try it: Master

How do you know whether an AIOps tool's top suggestion can be trusted?

Now do it: Label the proven cause of your last ten incidents.

Go deeper

A quick check for a common cause: compare per-request latency at matching traffic levels, or compute a partial correlation that removes the effect of traffic (a sketch with pandas; columns are per-minute series):

import pandas as pd
df = pd.read_csv("minutes.csv")                    # columns: rps, gc_ms, latency_ms, deploy (0/1)
print(df[["gc_ms", "latency_ms"]].corr())          # high: they move together
# residuals after removing what traffic explains
for col in ("gc_ms", "latency_ms"):
    slope = df[col].cov(df["rps"]) / df["rps"].var()
    df[col + "_resid"] = df[col] - slope * df["rps"]
print(df[["gc_ms_resid", "latency_ms_resid"]].corr())   # near zero: traffic explained both

Tools that help: distributed traces (which span grew), change-event feeds joined to metrics (Kubernetes events, deploy and flag audit logs), change-point detection on per-request metrics, and canary analysis (Argo Rollouts, Flagger, Kayenta) that compares old and new versions under the same traffic, which is a controlled experiment by design.

Causal reasoning in practice is a checklist, not a statistics degree: in the path, before the symptom, not explained by a common cause, moved by an intervention, explained by a mechanism. Record which of the five a conclusion meets; "likely cause" and "proven cause" are different claims.

One time it broke

This is a composite of a failure pattern that keeps repeating; the details are illustrative. The deploy that took the blame for a marketing email.

Timeline

  • 09:00A marketing email goes to two million customers. Nobody on the operations side knew it was scheduled.
  • 09:01A search service deploy completes. Checkout latency, GC pauses, and autoscaling events all rise.
  • 09:08The correlation tool ranks the search deploy highly. It is rolled back. Latency does not change.
  • 09:49Someone plots requests per second: three times normal since 09:00. Per-request latency at normal traffic was unchanged. Capacity is added; latency recovers by 10:09.

What changed after

Marketing sends are published to the change timeline, incident dashboards show per-request latency next to traffic, the runbook asks the common-cause question before any rollback, and the incident is labelled in the correlation tool's evaluation set.

Try it yourself, from scratch

Everything here runs on any Linux machine: your own laptop, WSL on Windows (run wsl --install in PowerShell once), or a small cloud VM. The Python needs only Python 3 and its standard library; check that you have it with python3 --version.

Before you start: Linux with the standard text tools (sort, awk, uniq) and Python 3.10 or newer.

1. Linux commands

Type each one, read what it prints, and compare it with the note above it.

  1. Put changes and alerts from two sources on one UTC timeline.

    Reversible

    mkdir -p ~/labs/causal && cd ~/labs/causal
    printf '%s\n' '2026-11-27T09:01:10Z change deploy search v212' '2026-11-27T09:00:00Z change marketing email to 2,000,000 customers' > changes.log
    printf '%s\n' '2026-11-27T09:01:40Z alert checkout p99 2.1s' '2026-11-27T09:02:05Z alert gc-pause high' '2026-11-27T09:02:30Z alert autoscaler 12 to 30 pods' > alerts.log
    sort changes.log alerts.log

    Options: ISO 8601 UTC timestamps sort correctly as plain text, so sort merges the sources into one timeline.

    Expect: Five lines in time order: the marketing email first, then the deploy, then the alerts.

    Clean up: rm -rf ~/labs/causal.

  2. Count requests per minute from an access log, to check for a common cause.

    Reversible

    awk 'BEGIN { for (m = 0; m < 6; m++) { n = (m < 1) ? 1000 : 3000; for (i = 0; i < n; i++) printf "2026-11-27T09:%02d:00Z GET /checkout\n", m } }' > access.log
    cut -c1-16 access.log | uniq -c

    Options: cut -c1-16 keeps the timestamp to the minute; uniq -c counts lines per minute.

    Expect: 1000 requests at 09:00, then 3000 a minute from 09:01: traffic tripled when the email landed, the same minute as the deploy. Every alert on the timeline can be explained by traffic.

  3. Topology check: keep only changes and alerts for services in checkout's request path.

    Reversible

    printf '%s\n' checkout payments search postgres > checkout-path.txt
    sort changes.log alerts.log | grep -F -w -f checkout-path.txt

    Options: -f reads the patterns from a file, -F treats them as fixed strings, and -w matches whole words only. In practice the path comes from traces or the service dependency graph.

    Expect: The search deploy and the checkout alert remain. The marketing email is filtered out because it is not a service, which is exactly why topology checks alone miss a common cause: the traffic count in the previous step is what finds it.

2. Python: causation.py

This program builds half an hour of per-minute metrics in which a traffic surge and an unrelated deploy start in the same minute. It shows that GC pauses and the deploy both correlate strongly with latency, that the GC correlation disappears once traffic is accounted for, that retries rose after latency (an effect, not a cause), and that only interventions separate the deploy from the surge. Save it as causation.py, then run it.

# causation.py
from statistics import mean

MIN = range(30)
rps = [1000 if m < 10 else 3000 for m in MIN]            # a marketing email lands at minute 10
deploy = [0 if m < 10 else 1 for m in MIN]               # an unrelated deploy, the same minute
capacity = [1 if m < 25 else 2 for m in MIN]             # capacity doubled at minute 25
n1 = [((m * 7) % 5) - 2 for m in MIN]                    # small fixed wobbles, different per signal
n2 = [((m * 3) % 4) - 1.5 for m in MIN]
gc = [4 + rps[m] / 250 + n2[m] for m in MIN]
lat = [200 + 0.25 * rps[m] / capacity[m] + n1[m] * 6 for m in MIN]
retries = [0] + [max(0, int((lat[m - 1] - 500) / 20)) for m in MIN if m > 0]

def corr(x, y):
    mx, my = mean(x), mean(y)
    sxy = sum((a - mx) * (b - my) for a, b in zip(x, y))
    return sxy / (sum((a - mx) ** 2 for a in x) * sum((b - my) ** 2 for b in y)) ** 0.5
def without(y, x):                                       # what is left of y after removing what x explains
    mx, my = mean(x), mean(y)
    slope = sum((a - mx) * (b - my) for a, b in zip(x, y)) / sum((a - mx) ** 2 for a in x)
    return [b - slope * a for a, b in zip(x, y)]

w = range(20)                                            # before any intervention
pick = lambda s: [s[m] for m in w]
print(f"correlation with latency: GC {corr(pick(gc), pick(lat)):.2f}, deploy {corr(pick(deploy), pick(lat)):.2f}")
print(f"after removing traffic:   GC {corr(without(pick(gc), pick(rps)), without(pick(lat), pick(rps))):.2f}  -> traffic explained both")
print(f"deploy versus traffic:    {corr(pick(deploy), pick(rps)):.2f}  -> the data alone cannot separate them")
print()
first = lambda s, limit: next(m for m in MIN if s[m] > limit)
print(f"latency over 600 ms from minute {first(lat, 600)}, retries from minute {first(retries, 0)}  -> retries are an effect")
print()
for label, lo, hi in (("surge, deploy live", 15, 20), ("surge, deploy rolled back", 20, 25), ("surge, capacity doubled", 25, 30)):
    print(f"  {label:<27} mean latency {mean(lat[lo:hi]):5.0f} ms")
print("the rollback changed nothing; adding capacity did: traffic was the cause")

Run it, and you should see this output:

$ python3 causation.py
correlation with latency: GC 0.96, deploy 1.00
after removing traffic:   GC 0.00  -> traffic explained both
deploy versus traffic:    1.00  -> the data alone cannot separate them

latency over 600 ms from minute 10, retries from minute 11  -> retries are an effect

  surge, deploy live          mean latency   950 ms
  surge, deploy rolled back   mean latency   950 ms
  surge, capacity doubled     mean latency   575 ms
the rollback changed nothing; adding capacity did: traffic was the cause

3. What to notice

4. Advanced: every step as one Bash script

The same Linux steps, made into a real script you can keep and run again. It uses the Bash features a production script needs: functions (one per step), an array of step names, arguments to choose steps, a case for options, exit codes recorded for each step, and a trap that prints a summary even when you stop it with Ctrl+C. Make a folder for this lesson (mkdir -p ~/labs/correlation-versus-causation-in-incident-analysis && cd ~/labs/correlation-versus-causation-in-incident-analysis) and save this as lab.sh.

#!/usr/bin/env bash
# The Linux steps of "Correlation Versus Causation in Incident Analysis: From "Changed at the Same Time" to Proven Cause", as one script (save it as lab.sh).
#
#   ./lab.sh          run every step, in order
#   ./lab.sh 2 4      run only steps 2 and 4
#   ./lab.sh --list   list the steps
#
# The steps share one shell, so a later step can use what an earlier one set up (a folder,
# a variable, a container): run them all in order the first time. Your own scripts should
# start with "set -euo pipefail"; this one runs teaching commands, and some of them fail on
# purpose, so it records each step's exit code instead of stopping at the first failure.

STEPS=(
  'Put changes and alerts from two sources on one UTC timeline.'
  'Count requests per minute from an access log, to check for a common cause.'
  'Topology check: keep only changes and alerts for services in checkout'\''s request path.'
)

step_1() {
mkdir -p ~/labs/causal && cd ~/labs/causal
printf '%s\n' '2026-11-27T09:01:10Z change deploy search v212' '2026-11-27T09:00:00Z change marketing email to 2,000,000 customers' > changes.log
printf '%s\n' '2026-11-27T09:01:40Z alert checkout p99 2.1s' '2026-11-27T09:02:05Z alert gc-pause high' '2026-11-27T09:02:30Z alert autoscaler 12 to 30 pods' > alerts.log
sort changes.log alerts.log
}

step_2() {
awk 'BEGIN { for (m = 0; m < 6; m++) { n = (m < 1) ? 1000 : 3000; for (i = 0; i < n; i++) printf "2026-11-27T09:%02d:00Z GET /checkout\n", m } }' > access.log
cut -c1-16 access.log | uniq -c
}

step_3() {
printf '%s\n' checkout payments search postgres > checkout-path.txt
sort changes.log alerts.log | grep -F -w -f checkout-path.txt
}

# print a step that has to be run by hand, instead of running it
by_hand() {
  echo "  (run this one yourself: $1)"
  sed 's/^/    /'
}

RESULTS=()
run_step() {
  local n=$1 start=$SECONDS code
  printf '\n== step %d of %d: %s\n' "$n" "${#STEPS[@]}" "${STEPS[n-1]}"
  "step_$n"
  code=$?
  RESULTS+=("step $n: exit code $code, $((SECONDS - start)) s")
}

summary() {
  echo
  echo "== summary"
  local r
  for r in "${RESULTS[@]}"; do echo "  $r"; done
}

case "${1:-}" in
  -h|--help) sed -n '2,6p' "$0"; exit 0 ;;
  --list) for i in "${!STEPS[@]}"; do echo "$((i + 1)). ${STEPS[i]}"; done; exit 0 ;;
esac

[ $# -eq 0 ] && set -- $(seq 1 "${#STEPS[@]}")
for n in "$@"; do
  if ! [[ $n =~ ^[0-9]+$ ]] || (( n < 1 || n > ${#STEPS[@]} )); then
    echo "there is no step '$n'; try --list" >&2
    exit 2
  fi
done
trap summary EXIT
trap 'echo; echo "stopped with Ctrl+C"; exit 130' INT
for n in "$@"; do run_step "$n"; done

Then make it executable and run it:

chmod +x lab.sh
./lab.sh --list     # the steps
./lab.sh            # every step, then a summary of exit codes and times
./lab.sh 2 3        # only steps 2 and 3

5. Learn the basics behind it

New to a feature used above? These W3Schools pages explain each one from zero, with examples you can run in the browser.

If you remember nothing else

Design exercise

Your AIOps tool suggests a probable cause for every incident, and on-call engineers act on it about half the time. Design the analysis practice and the measurement of the tool.

Clarifying questions to ask

Which steps must an engineer take before acting on a suggestion? Which data must the incident view show (traces, change feed, traffic, per-request metrics)? Which interventions are preferred, in which order? How are conclusions recorded? How is the tool's precision measured and reported?

Rough sizing

Say 300 incidents a year, a change feed of 2,000 changes a week, and a tool that ranks five candidates per incident.

Shape of the answer

A five-question check (path, order, common cause, intervention, mechanism) in the incident template; an incident view joining traces, the change feed, business events, and per-request metrics; interventions ordered from flag off to traffic shift to rollback, one at a time; a postmortem evidence table with confidence; labelled causes feeding a monthly report of top-1 and top-3 precision for the tool.

Trade-offs to name

The checks take a few minutes per incident and save the much larger cost of wrong actions; labelling causes takes postmortem effort and is the only way to know whether the tool helps.

Failure modes and how to troubleshoot them

Each row is one way this system went wrong in the diagram's scenarios. The hop number is where to look first.

ScenarioWhereEffectWhat goes wrong
Act on top correlationHop 3: CandidatesBreaksThe team acts in score order. It rolls back the CDN rule (no change), shrinks the cache TTL (no change), restarts the checkout pods (worse for a few minutes). 95 minutes pass.
Miss the common causeHop 6: ConfoundersBreaksThe search deploy landed in the same minute as the marketing email, so the team rolls it back. Latency does not improve.

How to troubleshoot

  1. Write down the symptom and when it started: what users see, which number moved, and what changed just before (a deploy, a config change, traffic).
  2. Walk the path in order, from the first hop to the last: Symptom → Timeline → Candidates → Topology → Time order → Confounders → Intervention → Mechanism → Record. The first hop whose evidence is wrong is where to dig.
  3. At that hop, run the read-only check from the diagram or the lab first; change nothing until the evidence points at a cause.
  4. Fix the smallest thing that restores service, or roll back the last change, and confirm the symptom is gone with the same check.
  5. Write down what you found and the check that would have caught it sooner, so the next person starts there.

References and review

The official documentation and standards behind this lesson. Versions and defaults change; when a command or field here differs from them, trust the official page.

Last updated . Next review due by November 2027. Found something out of date? Tell me.

Saved on this device, in this browser.
Next in this series · Lesson 339
Safe Auto-Remediation and LLM-Assisted Incident Response

Once an incident is detected, automation can act: restart a stuck process, roll back a bad deploy, scale out, fail over. A language model can read the evidence and draft a summary and next steps.

Go to Lesson 339 →

Or browse the full course from the Lessons index.