Filter concepts by levelShowing all levels.

Python · Monitoring and Production Operations

Monitoring and Production Operations

Alerts and dashboards, the SLO/SLI/error-budget vocabulary, the incident-response lifecycle, and the two ways to back out of a bad deploy

  • SLO / SLI / error budgetthe target, the measurement, and the spend allowed against it
  • Alert on symptomspage for user-facing impact, not every internal metric wobble
  • Blameless postmortemthe goal is the timeline and the fix, not who to blame
  • Graceful degradationserve a reduced experience rather than fail outright

1.Metrics, logs, and traces (the ops layer)

Metrics, logs, and traces are the three raw signals every other tool in this section is built on — alerts fire on metrics, dashboards chart metrics, and an incident responder reads logs and traces to find the broken component.

Key features

  • Metrics, structured/JSON logs, and distributed tracing (OpenTelemetry) are taught in depth in Logging and Observability — this section assumes that ground
  • An alert is a threshold rule evaluated against a metric — no metric, no alert
  • A dashboard visualizes metrics over time — it has nothing to chart without them
  • An incident responder reads logs for what happened and traces for where time went — the diagnostic raw material
  • SLIs (next concept) are just metrics chosen specifically to represent user-facing reliability

Signature

metrics / logs / traces → alerts, dashboards, SLOs, incident response

This section builds alerts, dashboards, SLOs, and incident response ON TOP of metrics/logs/traces — see Logging and Observability for how to actually produce them in Python.

2.Health checks (in the ops loop)

A health check is usually the first thing an on-call engineer opens when a dashboard turns red — GET /healthz or /readyz answering "is it up" before anyone reads a log line.

Key features

  • Liveness vs. readiness, the Kubernetes probe vocabulary, and the Python check functions are taught in full in Logging and Observability
  • A readiness check is often the fastest signal that an SLI (next concept) is about to be breached — traffic is already being turned away
  • Health-check endpoints are what an uptime/synthetic monitor polls to feed an alert or dashboard
  • Incident response usually starts by hitting the health-check endpoint before reading logs or traces

Signature

GET /healthz, GET /readyz

Health checks are the fastest first signal in this section's workflow — see Logging and Observability for the liveness/readiness mechanics.

3.Alerts and dashboards

An alert is a rule that pages a human when a metric crosses a threshold for long enough; a dashboard is the same metrics charted continuously so a human can look without waiting to be paged.

Key features

  • An alert fires on a condition over a time window (e.g. error rate > 5% for 5 minutes) — not a single bad data point, which pages on noise
  • A good alert is actionable: the SRE book's standard is that every page should require a human response, or it should not page at all
  • A dashboard answers "what is the current state" at a glance; it does not wake anyone up on its own
  • Alerting on symptoms users feel (latency, error rate) is preferred over alerting on every possible internal cause — fewer, higher-signal alerts
  • Alert fatigue — too many low-value pages — is a named failure mode; it trains responders to ignore alerts, including real ones

Command

text
# The shape shared by Prometheus Alertmanager, CloudWatch Alarms,
# Grafana alerting, and similar tools:
IF <metric> <comparison> <threshold> FOR <duration>
  THEN notify(<channel>)  # page, Slack, email — by severity

# Example rule, in words:
IF rate(http_requests_failed) / rate(http_requests_total) > 0.05
   FOR 5m
   THEN page(on-call)

Alert on symptoms over a time window, not single data points; a dashboard is for looking, an alert is for being interrupted — a healthy setup needs both, and too many low-value alerts trains people to ignore all of them.

4.SLOs, SLIs, and error budgets

An SLI is a measured number (like the fraction of requests that succeeded); an SLO is the target you set for that number (like 99.9%); the error budget is the allowed amount of failure left before the SLO is breached.

Key features

  • SLI (Service Level Indicator): a measured metric — e.g. the proportion of successful, fast-enough requests
  • SLO (Service Level Objective): the target for an SLI over a window — e.g. "99.9% of requests succeed, over 30 days"
  • Error budget: 100% minus the SLO — the amount of unreliability allowed before the SLO is breached (99.9% SLO leaves a 0.1% budget)
  • An SLA (Service Level Agreement) is an SLO with a consequence attached (a refund, a penalty) — not covered by the roadmap here, but the term a reader will see next to these
  • Google's SRE book treats the error budget as a shared decision tool: budget remaining favors shipping features, budget exhausted favors a change freeze

SLI vs. SLO vs. error budget

SLI vs. SLO vs. error budget
TermWhat it isWorked example
SLIa measured number, right now99.95% of requests succeeded, last 30 days
SLOthe target you committed to for that SLI99.9% of requests succeed, over 30 days
Error budget100% − SLO — allowed failure before breach0.1% of requests may fail — roughly 43 minutes of full downtime/month
How the three terms relate

SLI

Measured now

99.95% success, last 30 days

SLO

Target committed to

99.9% success, 30-day window

Error budget

100% − SLO

0.1% allowed to fail before breach

  • SLI
    • Measured now — 99.95% success, last 30 days
  • SLO
    • Target committed to — 99.9% success, 30-day window
  • Error budget
    • 100% − SLO — 0.1% allowed to fail before breach

Command

python
# SLI: measure it
success_rate = successful_requests / total_requests

# SLO: the target you set for that SLI, over a window
slo_target = 0.999   # 99.9% over 30 days

# Error budget: what's left before the SLO is breached
error_budget = 1 - slo_target
budget_remaining = error_budget - (1 - success_rate)

SLI = what you measured; SLO = the target you promised; error budget = 100% − SLO, and a negative budget is the objective definition of an SLO breach.

5.Incident response and root cause analysis

Incident response is the structured process a team follows while a service is broken right now — declare, mitigate, resolve; root cause analysis happens after, asking why it broke so it does not happen the same way twice.

Key features

  • Incident response prioritizes mitigation over diagnosis — restoring service now beats understanding the full cause immediately
  • A named Incident Commander owns coordination during a major incident, separate from whoever is actually fixing it — one person decides, many can investigate
  • Root cause analysis is rarely one root cause — the SRE book favors "contributing factors" over a single cause, since most outages need several things to go wrong together
  • The "Five Whys" technique repeatedly asks why until reaching a systemic, fixable condition — not a single person's mistake
  • A rollback (next concept) is very often the fastest mitigation during incident response, even before the root cause is known

Incident lifecycle

Incident lifecycle
PhaseGoalTypical action
DetectNotice something is wrongAlert fires, or a user/engineer reports it
DeclareName it an incident, assign an Incident CommanderOpen an incident channel, page responders
MitigateStop user impact — not yet full understandingRollback, feature flag off, traffic shed
ResolveConfirm the service is actually healthy againMetrics/SLI back inside the SLO
AnalyzeFind contributing factors, not blameRoot cause analysis, feeds the postmortem
Incident response, in order

Detect

Alert fires or someone reports impact

Declare

Named an incident; Incident Commander assigned

Mitigate

Stop user impact — rollback, flag off, shed load

Resolve

Confirm SLIs are back inside the SLO

Analyze

Root cause analysis feeds the postmortem

  1. Detect — Alert fires or someone reports impact
  2. Declare — Named an incident; Incident Commander assigned
  3. Mitigate — Stop user impact — rollback, flag off, shed load
  4. Resolve — Confirm SLIs are back inside the SLO
  5. Analyze — Root cause analysis feeds the postmortem

Command

text
Incident lifecycle:  detect -> declare -> mitigate -> resolve -> analyze
Root cause analysis: "Five Whys" — ask why repeatedly past the first answer
                      until you reach a systemic, fixable condition

Mitigate first, understand second — root cause analysis is a chain of contributing factors ("Five Whys"), not one person's mistake, and it happens after impact has already stopped.

6.Postmortems

A postmortem is a written document produced after an incident is resolved — what happened, its impact, the contributing factors, and the concrete follow-up actions that reduce the chance it repeats.

Key features

  • Blameless: the document names contributing factors and broken systems, never "who caused it" — a named practice from Google's SRE book, not just a courtesy
  • A postmortem is written after root cause analysis (the previous concept) — it is where that analysis is recorded, not where it happens
  • Standard sections: summary, impact (duration, users affected), timeline, root cause / contributing factors, what went well, action items with owners
  • Action items need an owner and often a deadline — a postmortem with no follow-through just repeats the same incident later
  • A postmortem criterion is often written down in advance (e.g. "any incident that breaches the SLO gets one") so writing one is not a political decision made after the fact

Command

text
Postmortem sections (SRE book shape):
  Summary        — one paragraph, what happened
  Impact         — duration, users/requests affected, SLO/error-budget impact
  Timeline       — detect -> declare -> mitigate -> resolve, with timestamps
  Root cause     — contributing factors (see Incident response / RCA)
  What went well — genuinely, not just criticism
  Action items   — each with an owner and a status

Blameless: name the contributing factors, never the person; a postmortem without owned, tracked action items is a summary, not a fix.

7.Graceful degradation

Graceful degradation means a service keeps working with reduced functionality when a dependency fails, instead of failing the whole request — a try/except around the dependency call, returning a fallback value.

Key features

  • The core pattern is try/except around a dependency call, with a fallback return value in the except branch
  • Catch the SPECIFIC exception the dependency raises — a bare except Exception also swallows real bugs in your own code, not just the outage
  • A circuit breaker stops CALLING a failing dependency after N consecutive failures, instead of retrying (and timing out) on every request
  • A circuit breaker has to reset (close) eventually, or a temporary outage becomes a permanent one for that dependency
  • Graceful degradation trades completeness for availability — a recommendations widget can go blank; checkout usually cannot

Degradation strategies

Degradation strategies
StrategyWhat happens on failureWhen to use
Static fallbackReturn a fixed, cached, or default valueNon-critical, cacheable data (recommendations, "related items")
Circuit breakerStop calling the dependency after N failures; fail fastA slow/timing-out dependency, to avoid piling up retries
Feature flag offDisable the feature entirely for all usersA whole feature is unsafe, not just one call
Retry with backoffRetry the SAME call after a delay, not a fallbackTransient failures expected to self-resolve quickly
Fallback path vs. failure path
succeedsfailsexcept

Call dependency

Response used

Dependency raises

Fallback returned

  • Call dependency
    • leads to Response used (succeeds)
    • on error, leads to Dependency raises (fails)
  • Response used
  • Dependency raises
    • on error, leads to Fallback returned (except)
  • Fallback returned

Command

python
def get_data():
    try:
        return call_dependency()
    except SpecificDependencyError:   # not a bare except
        return fallback_value

Catch the specific dependency exception, not Exception — a broad catch degrades gracefully on real outages but also hides real bugs behind the same fallback.

8.Rollbacks

A rollback reverts a service to the last known-good version — usually the fastest way to stop user impact during an incident, since it does not require knowing why the new version broke.

Key features

  • A rollback reverts the deployed version, not the data — a migration that already ran does not automatically un-run on rollback
  • Rolling back is usually faster than a forward fix, because "make it match yesterday" needs no new code review
  • A feature flag can act as a fast, partial rollback — turn the new code path off without redeploying anything
  • An automated rollback trigger (e.g. error rate over a threshold) can revert before a human even finishes declaring the incident
  • Rollback safety depends on backward-compatible database migrations — a rollback that hits a schema the old code cannot read makes things worse

Command

python
def choose_active_version(current: str, previous: str, errors: int, total: int) -> str:
    if error_rate_breached(errors, total):
        return previous   # roll back
    return current

A rollback reverts code, not data — it is usually the fastest mitigation because it needs no understanding of what broke, only that the previous version worked.

Remember

  • An SLI is what you measure, an SLO is the target for it, and the error budget is how much the SLO can be missed before it is a problem.
  • Alert on symptoms a user would notice (elevated error rate, high latency), not on every internal metric crossing a threshold.
  • A blameless postmortem's goal is a corrected timeline and a fix, not identifying who to blame — blame makes the NEXT incident's report less honest.
  • Graceful degradation serves a reduced but working experience when a dependency fails; a rollback reverts a bad deploy rather than fixing forward under pressure.

Pro tip

  • Python's logging/metrics/tracing/health-check mechanics are covered in Python §20 — this section covers the ops layer built on top of them.
  • A rollback is often faster and safer than a fix deployed under incident pressure — decide the rollback threshold before the incident, not during it.

Next up

  • API Reliability

Sources

  • Google SRE book — sre.google/sre-book
  • Illustrative snippets run for real on Python 3.14.3 · checked 2026-08-22

Spotted a mistake on this page? Tell us.