Observability exists to answer questions during an incident
The value of instrumentation is measured at 03:00 when a pager fires. In that moment three questions decide how long the incident runs: is data actually missing, what changed, and who owns it. A monitoring stack that cannot answer the first question in under a minute is decoration, no matter how many panels it has. Observability is not the volume of telemetry you collect; it is whether the telemetry encodes the questions you will ask.
Data pipelines have an unusual failure profile compared with web services. Latency spikes are visible and self-limiting; a silently stale table is neither. Most pipeline incidents are not crashes but absences â a partition that never arrived, a job that succeeded while producing nothing, a downstream mart that kept serving yesterday. Instrumenting for absence means measuring the data itself, not only the compute that moves it.
After this lesson you should be able to define service level indicators a stakeholder would accept, emit metrics that distinguish a slow job from an empty one, and write alerts that page only when a human can actually act.
The four signals, translated for batch work
The classic golden signals â traffic, errors, duration, saturation â map onto pipelines with one addition that matters more than any of them: freshness. Traffic becomes rows processed per unit time. Errors become failed task counts and rejected record counts. Duration becomes end-to-end pipeline latency plus per-stage duration. Saturation becomes queue depth, pool utilisation, and executor memory pressure. Freshness is the gap between the newest data available and the newest data served, and it is the signal consumers actually feel.
| Signal | Metric | Healthy pattern | Failure it exposes |
|---|---|---|---|
| Freshness | Age of newest served record | Flat, below the SLO | Source outage, stuck scheduler |
| Volume | Rows per batch versus trailing median | Band-shaped over time | Silent truncation, partial extract |
| Errors | Failed tasks, rejected records | Near zero | Data bugs, dependency failures |
| Duration | Wall clock per stage and total | Stable under load | Skew, spill, resource contention |
| Saturation | Pool slots busy, queue depth | Headroom retained | Under-provisioned pools |
| Quality | Failed expectation count | Zero or known warnings | Schema drift, bad upstream batch |
Freshness deserves its own panel because it is monotone and unforgiving. A pipeline that failed at 02:00 shows rising freshness age whether or not anything reported an error, so freshness catches the failures your error metrics miss â including the ones where every task returned success with no rows.
Emitting metrics where the work happens
Metrics should be emitted by the code that knows the semantics, not scraped from log lines after the fact. Each task boundary is a natural place: record what went in, what came out, what was rejected, and how long it took, tagged with the logical date so time series can be sliced per run.
import time, logging
from dataclasses import dataclass, field
from prometheus_client import Counter, Histogram, Gauge, start_http_server
log = logging.getLogger("pipeline")
ROWS_IN = Counter("pipeline_rows_in_total", "Rows read", ["pipeline", "stage", "source"])
ROWS_OUT = Counter("pipeline_rows_out_total", "Rows written", ["pipeline", "stage", "sink"])
REJECTED = Counter("pipeline_rows_rejected_total", "Rows failed validation", ["pipeline", "stage", "reason"])
STAGE_SECONDS = Histogram("pipeline_stage_seconds", "Stage duration", ["pipeline", "stage"])
FRESHNESS = Gauge("pipeline_freshness_seconds", "Age of newest served record", ["pipeline"])
RUNS = Counter("pipeline_runs_total", "Pipeline runs", ["pipeline", "status"])
@dataclass
class StageMetrics:
pipeline: str
stage: str
started: float = field(default=0.0)
rows_in: int = 0
rows_out: int = 0
rejected: int = 0
def __enter__(self):
self.started = time.monotonic()
return self
def __exit__(self, exc_type, exc, tb):
status = "failed" if exc else "success"
STAGE_SECONDS.labels(self.pipeline, self.stage).observe(time.monotonic() - self.started)
ROWS_IN.labels(self.pipeline, self.stage, "unknown").inc(self.rows_in)
ROWS_OUT.labels(self.pipeline, self.stage, "warehouse").inc(self.rows_out)
if self.rejected:
REJECTED.labels(self.pipeline, self.stage, "validation").inc(self.rejected)
RUNS.labels(self.pipeline, status).inc()
log.info("stage_complete", extra={
"pipeline": self.pipeline, "stage": self.stage,
"rows_in": self.rows_in, "rows_out": self.rows_out,
"rejected": self.rejected, "status": status,
})
return False # never swallow the exception: the orchestrator must see it
start_http_server(9100)
with StageMetrics("daily_orders", "extract") as m:
rows = extract_orders()
m.rows_in = len(rows)
with StageMetrics("daily_orders", "load") as m:
m.rows_out = write_orders(rows)
m.rejected = count_rejects(rows)
The structure matters as much as the numbers. A context manager guarantees the metric is emitted on failure too, since a counter that only increments on success cannot distinguish "nothing happened" from "nobody instrumented it". Structured logs carry the per-run detail that metrics aggregate away, and the two are joined by the run id: metrics tell you something is wrong, logs tell you what.
Service levels people will actually agree to
A service level indicator is a measurable definition of "the data is there". A service level objective is the target with an error budget attached. The discipline is choosing indicators consumers recognise: "pipeline duration under twenty minutes" means nothing to a finance analyst, while "yesterday's revenue table is queryable by 06:15 on 99 percent of days" is a promise they can plan around.
| Indicator | Definition | Typical objective | Error budget |
|---|---|---|---|
| Data freshness | Now minus newest event time served | 95th percentile under 60 minutes | 3.6 hours per 30 days |
| Load success | Runs completing without a failed task | 99 percent of scheduled runs | 7 runs per 30 days |
| Data completeness | Partitions present for the schedule | 100 percent | Zero tolerance |
| Timeliness | Run finish time versus deadline | 99 percent before 06:15 | 43 minutes per 30 days |
| Quality | Batches passing all blocking expectations | 98 percent | 14 batches per 30 days |
Completeness at zero tolerance is deliberate. Missing a partition is not a degradation with degrees; it is an all-or-nothing gap that breaks every downstream join, so it should page rather than accumulate budget. Error budgets then become the negotiation tool: a team that spends its budget on freshness misses features, which converts reliability work into a shared priority instead of an argument.
Dashboards that explain rather than decorate
A useful dashboard is ordered the way an incident unfolds. The top row answers "is anything broken": freshness age, last successful run, active alerts. The second row answers "what changed": volume versus trailing band, error counts, quality failures. The third row answers "why": stage durations, queue depth, saturation, and the log link for the current run. Anything below that is investigation material, not a health signal.
Panels should show distributions rather than averages wherever possible. Average batch duration hides a single stage taking ten times its peers; the 95th percentile and a per-stage breakdown expose it. Similarly, a sparkline of volume over thirty days beats a big number today, because the anomaly is the shape, not the level.
# Alert rules: page only when a human can act now.
groups:
- name: pipeline-slo
rules:
- alert: DataStale
expr: pipeline_freshness_seconds{pipeline="daily_orders"} > 7200
for: 10m
labels: { severity: page, team: analytics-eng }
annotations:
summary: "daily_orders is {{ $value | humanizeDuration }} behind"
runbook: "https://runbooks.internal/daily-orders-stale"
- alert: VolumeCollapse
expr: |
pipeline_rows_out_total{stage="load"}
/ ignoring(phase) group_left
avg_over_time(pipeline_rows_out_total{stage="load"}[7d]) < 0.4
for: 15m
labels: { severity: ticket, team: analytics-eng }
- alert: NoSuccessfulRun
expr: increase(pipeline_runs_total{pipeline="daily_orders",status="success"}[6h]) == 0
for: 15m
labels: { severity: page, team: analytics-eng }
Notice the severity split. Page means someone must act immediately and the runbook must exist; ticket means someone should look during working hours. An alert routed to page without a runbook entry trains the on-call to ignore it, and an ignored alert is strictly worse than none, because it also hides the fact that nobody is watching.
Routing, ownership, and closing the loop
Every metric carries an owner tag, and every alert resolves to a team before it fires. Alerts without owners end up in a shared channel that nobody reads; the fix is boring and effective â attribute each pipeline to a team at registration time and let the routing derive from that attribute rather than from per-rule configuration.
After every incident, add one thing: a missing metric, a clearer message, or a runbook step. Teams that treat alerts as disposable accumulate pages; teams that treat each alert as a specification of an unanswered question converge on a small, trusted set. The end state you are aiming for is a dashboard where the panels nobody consults get deleted and the ones that drive decisions are on the on-call's phone.
đĄTest your alerts deliberately
Trigger each page-level alert on purpose in staging â freeze a source, inject a stale partition, fail a task. If the alert does not fire, you have found a blind spot cheaply; if it fires with a useless message, you have found it before 03:00.
Common Mistakes
Monitoring only job status and never the data itself
Fix: Add freshness, volume, and completeness indicators measured on the served output
Averaging durations and hiding one pathological stage
Fix: Chart percentiles and per-stage breakdowns so outliers stay visible
Routing every warning to the page channel
Fix: Split severity, require a runbook for every page-level rule, and demote chronic noise to tickets
Metrics with no owner tag
Fix: Attach team and pipeline ownership at emission so routing is automatic
Best Practices
- Put freshness, last success, and active alerts at the top of every dashboard
- Emit counters and histograms at task boundaries with a context manager so failures are recorded too
- Pair each metric with structured logs joined by a run id for drill-down
- Define objectives in language stakeholders use and track the error budget publicly
- Rehearse alerts in staging and keep a runbook link in every page-level annotation
Interview Questions
Q1: Why is freshness the most important pipeline metric?
It rises whether or not anything reported an error, so it catches silent failures where every task returned success with no data.
Q2: Difference between an SLI and an SLO?
The SLI is the measurement definition, such as age of the newest record; the SLO is the target with an error budget attached.
Q3: What makes an alert worth paging for?
A human can act now, the condition is actionable, and a runbook exists; otherwise it belongs in tickets or dashboards.
Q4: Why instrument with a context manager?
It guarantees metrics are emitted on failure paths as well as success, so absence of data does not look like absence of instrumentation.
Key Takeaways
- Instrument the data, not only the compute: freshness, volume, and completeness catch silent failures
- Use metrics for detection, structured logs for explanation, and a shared run id to join them
- Write objectives in stakeholder language and let error budgets set priorities
- Order dashboards by incident workflow: broken, changed, then why
- Page only for actionable conditions with a runbook, and treat every alert as a specification to be refined