SysDesignAtlas

Observability for AI Systems

Token metrics, tracing across model calls, cost attribution, and the hard part — monitoring output quality when there is no ground truth and no exception to catch.

HLDMedium10 min readaiobservabilitymonitoringtracing
Confidence

#The gap ordinary monitoring leaves

Standard observability answers: is it up, is it fast, is it erroring. All three can be perfectly green while an AI system is failing badly.

   TRADITIONAL SIGNALS         WHAT THEY MISS

   error rate 0.01%   ✓        the model is confidently wrong
   p99 latency 800ms  ✓        answers got shorter and less useful
   CPU 40%            ✓        GPU KV cache is at 98%
   200 OK             ✓        every response says "I cannot help"

   → An AI system degrades along a dimension that
     conventional monitoring has no view of at all.

You need three layers:

  • the serving layer — the same kinds of latency and throughput metrics you already know, but counted in tokens rather than requests;
  • the request layer — tracing one user action across the many model calls it triggers;
  • the quality layer — whether the answers are actually any good, the genuinely hard one.

#Layer 1 — serving metrics

The unit is tokens, not requests. Everything else follows from that.

MetricDefinitionWhy it's the right one
TTFTQueue wait + prefillWhat users perceive as responsiveness
TPOTTime per output tokenStreaming smoothness; under ~30 ms feels fluid
End-to-end latencyTTFT + TPOT × output lengthDominated by output length, so it's mostly not about your system
ThroughputTokens/second, in and out separatelyYour cost denominator
GoodputTokens/second meeting SLAThe honest number
KV cache utilisationFraction of cache allocatedThe real capacity signal — watch this, not GPU%
Batch sizeConcurrent sequences per stepDirectly proportional to efficiency
Preemption rateEvictions per minuteNon-zero means admission control is too loose
Queue waitTime from arrival to first forward passThe controllable part of TTFT

GPU utilisation is nearly useless. nvidia-smi reports ~100% whenever any kernel is resident, including one stalled on memory. Use KV cache utilisation for capacity and MFU for efficiency instead.

#Layer 2 — tracing

One user action can be twenty model calls, several retrievals, and a handful of tool executions. A trace records that whole tree — every step, nested, with its own timing — so you can see where the 40 seconds actually went. Each individual step in it is a span. Without one, you have a total and no way to attribute it.

   TRACE: "summarise this repo and fix the failing test"   47.2 s

   ├─ classify intent                     0.3 s   (small model)
   ├─ retrieve repo context               1.1 s
   │   ├─ embed query                     0.08 s
   │   └─ vector search (top 40)          0.9 s
   ├─ agent loop                         44.8 s   ← here
   │   ├─ turn 1  model call              2.1 s   4.2K in / 180 out
   │   │   └─ tool: read_file             0.2 s
   │   ├─ turn 2  model call              3.4 s   6.8K in / 310 out
   │   │   └─ tool: run_tests            18.3 s   ← and here
   │   ├─ turn 3  model call              4.9 s   11K in / 520 out
   │   └─ ... 6 more turns
   └─ format response                     1.0 s

   Two findings visible immediately:
     · run_tests dominates — not a model problem at all
     · input tokens grow every turn (4.2K → 11K), so
       later turns cost multiples of earlier ones

Every span should carry: model and version, input tokens split into cached and uncached, output tokens, computed cost, temperature and sampling params, the prompt template version, and whether it was a retry.

Sampling strategy matters. Full traces are expensive at volume. Sample 1–5% uniformly for baselines, plus 100% of anything anomalous — errors, latency outliers, high cost, low confidence, negative user feedback. The anomalous traces are the ones you'll actually read.

Prompt versioning is part of tracing. When quality shifts, "which prompt version was this?" is the first question, and it's unanswerable unless you record it. Prompts should be versioned artifacts, not string literals in the codebase.

#Layer 3 — quality

The hard part. There is no exception when a model gives a bad answer, and usually no ground truth — a known correct answer to compare it against. So you watch indirect signals instead.

Proxy signals — cheap, fast, high volume:

SignalWhat it catches
Output length distributionTruncation, runaway generation, format collapse
Refusal rateAlignment drift in either direction
Tool-call validityStructured-output degradation — the most sensitive signal available
Retry / regeneration rateUsers silently saying the answer was bad
Conversation lengthRising turns-to-resolution means answers aren't landing
Fallback / escalation rateThe explicit failure path
Empty or near-empty responsesPrompt or template breakage

Direct signals — slower, more meaningful:

  • Explicit feedback (thumbs). Sparse — typically 1–5% of users respond — and biased toward extremes, but unambiguous when you get it.
  • Implicit feedback. Did they copy the code? Accept the suggestion? Continue the conversation? Often far more informative than thumbs, and available on every interaction.
  • Task success. Did the ticket get resolved, the test pass, the purchase complete? This is the real metric and it lags by hours or days.
  • LLM-as-judge on a live sample. Score a percentage of production traffic with a model. Fast and scalable, but it needs its own validation against human labels. The judge's score is already only an estimate of quality; if you never check the judge against humans, you can't tell whether a change in its score reflects your model or the judge's own blind spots. Covered in evaluation systems.

#Cost attribution

Covered in the cost model; the observability requirement is that every span carries enough to compute cost, and that you can aggregate by tenant, feature, model, and endpoint.

What you're looking for, specifically:

   · top 1% of users by cost      — usually 30-50% of the bill
   · cost per feature vs its value
   · cached vs uncached input ratio, per endpoint
        → a falling ratio means prompt ordering broke
   · agent loops exceeding expected turn counts
   · retry storms — invisible in request counts, obvious in tokens

That third one is worth alerting on. Prefix caching only reuses work when the start of a prompt is identical to one seen before, so the stable parts (system prompt, tool definitions) must come first. If someone puts a timestamp at the front of a prompt, every request now starts differently, nothing matches the cache, and the hit rate silently collapses. That can double your bill with no other symptom.

#Alerting

Not everything above deserves a page. A workable split:

Page immediately: TTFT p99 above SLA for 5 minutes; error rate above baseline; KV cache above 95% with preemptions occurring; cost rate above 2× the 7-day average; tool-call validity dropping more than 5 points.

Ticket, don't page: gradual quality drift; cost per request trending up; cache hit rate declining; MFU below target.

Dashboard only: length distributions, per-feature breakdowns, model mix.

#Exercise

#Check yourself

Why isn't traditional monitoring enough for AI systems?Show answer
Error rate, latency and status codes can all be green while the model is confidently wrong, answers got shorter, the KV cache is full, or every reply is a refusal.
Which serving metrics matter?Show answer
TTFT and TPOT separately, input and output throughput, goodput, KV-cache utilisation (the real capacity signal), batch size, preemption rate and queue wait.
Why is end-to-end p99 latency misleading?Show answer
It mostly measures how long the longest responses were — a change in user behaviour, not system performance. Alert on TTFT and TPOT; use latency per output token if you want one number.
What should every trace span carry?Show answer
Model and version, cached and uncached input tokens, output tokens, cost, sampling parameters, prompt template version and retry flag. Keep 1–5% of traces plus 100% of anomalies.
Name five quality proxies that need no ground truth.Show answer
Output-length distribution, tool-call or JSON validity, refusal rate, retry/regeneration rate and cost per request — build their baselines from day one.
What direct quality signals exist?Show answer
Explicit thumbs (sparse, biased), implicit feedback (copied, accepted, continued), task success (lags hours or days) and an LLM judge on a live sample, itself validated against humans.
Why alert on the cached-input ratio?Show answer
A collapsing cache hit rate — say, a timestamp moved to the front of a prompt — can double the bill with no other symptom.
How should AI alerts be written?Show answer
On rates and distribution shifts against a rolling baseline, never absolute counts. Page on SLA breaches, KV pressure, cost spikes and validity drops; ticket gradual drift.

#What to carry forward

  • Traditional monitoring can be entirely green while quality collapses.
  • Alert on TTFT and TPOT separately. End-to-end p99 mostly measures output length.
  • KV cache utilisation is the capacity signal; GPU utilisation is close to meaningless.
  • Trace every model call with tokens, cost, model version, and prompt version.
  • Five quality proxies cost nothing and need no ground truth: length, validity, refusal, retry, cost.
  • Build the quality baseline before the incident. Without history, no number is interpretable.
  • Alert on rates and distribution shifts, never absolute counts.
00:00
/ 10m