Case brief
Understand the scenario, task, and constraints.
Find the hop behind "slow and sometimes wrong"
Users of a customer-facing AI application say it is slow and sometimes wrong. The team has to trace each complaint to the step that caused it: a slow search, a model that ignored good evidence, a failing tool call or a queue that backed up. The difficulty is privacy. The evidence that explains a failure lives in the same requests that carry customer prompts, documents and identifiers, and the telemetry must not become a second copy of that data.
A few terms carry the whole case, so we define them first.
- Telemetry is the operational data a system emits about itself: timings, error codes, counts and outcome labels.
- A span is one timed record of one step, such as "retrieval took 1.2 seconds and returned 3 documents". A trace is the set of spans for one request, linked together.
- A correlation ID is one identifier attached to a request when it arrives and carried through every service, queue and integration it touches. It is what lets us join spans from different systems into one trace.
- A tenant is one customer organisation on a shared platform. Acme and Globex are two tenants; neither may see the other's data.
- p95 and p99 are the response times that 95% and 99% of requests beat. They describe the slow tail that averages hide.
- RAG (retrieval-augmented generation) fetches relevant documents first and has the model answer only from them, so a wrong answer can start in the search step or in the model.
The design gives every request a correlation ID and structured spans through retrieval, model and tools. Spans leave the request path asynchronously, are redacted before storage and are sampled so that errors and slow traces are kept. Authorised support staff see only their own tenant. Diagnosis then runs from the complaint down: the user's outcome first, then the slow or failing span, then the retrieved evidence compared with the answer.
The figure is the whole method in one path. The complaint selects a trace through its correlation ID. The first question is whether retrieval found good evidence; if not, the fault is upstream and changing the model will not help. If the evidence was good but the answer contradicts it, the model or the prompt is at fault. If both look right, the remaining suspects are tool calls and latency.
Follow one request: Acme's German refund flow
The source traces one request end to end. An Acme user asks the assistant about a refund in German.
- The request gets a correlation ID at authentication, together with its tenant, Acme.
- Each hop records its time and outcome: retrieval, model call and tool call. The raw prompt is not recorded by default.
- A classifier redacts sensitive values before anything is stored. "Retrieval 1.2s, 3 docs" is kept; a full social security number (SSN), the United States personal identity number, is not.
- When the user complains, support staff working for Acme can open Acme's traces only. A level-one (L1) support agent cannot open Globex tickets "to help debug".
- The trace distinguishes cases that look identical to the user: a slow first token versus a slow last sentence, and an empty retrieval versus a made-up answer versus a tool returning HTTP 500.
- Errors and outliers are always kept. Most successful, ordinary traffic is sampled, meaning only a fraction of it is stored.
The loop is: trace the path, hide the secrets, find the hop. Throughout, telemetry must not stall the user.
What you need to design
This case covers one slice of a larger product: one correlation ID through the AI path, redacted spans and tenant-scoped debugging. It adds no product feature. Its dangerous constraint is that telemetry must never store raw prompts, documents or secrets, or let support read another tenant's data.
By the end you should be able to explain the system at interview depth, starting from that constraint, and answer follow-up questions on redaction, sampling, root-cause method, failure policy, the two production incidents and rollout. The case is aimed at Forward Deployed, solutions and applied-AI engineering interviews, especially a production operations round that asks you to debug a live large language model (LLM) application or handle a latency or cost incident. It assumes comfort with distributed tracing, percentile latency, RAG pipelines and multi-tenant access control.
The same traces answer several related interview prompts. Each reads the anchor's spans at a different depth.
The anchor design and the related prompts it answers.
| Related case | Shared foundation | What changes |
|---|---|---|
| Latency spike | Correlated stage spans | Diagnose stacked retrieval, reranker, queue and provider delays. |
| Cost spike | Versioned request and token metadata | Find prompt expansion, model-route change and unsafe cache-key regression. |
| Latency questions | Per-hop timing | Separate application queueing from inference prefill and decode. |
| Poor RAG quality | Retrieval and answer evidence | Separate retrieval, synthesis, prompt, output and user-experience faults. |
| Cost/latency pivots | Tenant/workflow attribution | Apply measure → route → bound → cache safely. |
Work through the Design walkthrough first: it is the answer you would give in the room. The Technical deep dives hold the mechanisms, both incidents in full and the neighbouring prompts. Practice asks you to rebuild the design from a blank page and rehearse every source question and pivot card. Quick review is the one-page recall sheet for the night before.
Next: build the answer in interview order.
Start the walkthroughDesign walkthrough
Follow the reasoning from discovery to delivery.
1. Split the complaint into three problems
The customer wants to connect a user-visible failure to a technical cause, quickly, safely and without drowning operators in noise. More logging does not achieve that. A vague complaint cannot be instrumented, so the first job is to make it measurable.
"The AI is slow and sometimes wrong, and nobody knows why" is three problems in one sentence:
- Latency asks whether the request is slow, and where in the pipeline the time goes.
- Correctness asks whether the answer is wrong, and whether the fault is upstream in retrieval or downstream in the model or a tool.
- Diagnosability asks whether support and engineering can explain a failure without exposing sensitive content.
Each stakeholder wants a different signal. Support wants to triage a complaint without waiting on engineering. Engineering wants to know whether the fault is retrieval, the model or a tool integration. Security wants assurance that telemetry does not become a new exposure surface. The executive sponsor wants proof that quality improves from release to release, which a wall of green dashboards does not provide.
Open the round with one sentence: connect user-visible failures to technical causes without violating privacy or drowning operators in telemetry. Then ask the first two questions below, state your assumptions aloud and invite the interviewer to redirect you.
Six questions to ask the interviewer, in plain words, and what each answer decides.
| Question to ask | What it's really asking | What you then decide |
|---|---|---|
| What is slow: first token, full response or a specific workflow percentile? | Is the user staring at a blank box, or waiting for the last sentence? | SLO and which spans to time. |
| What is wrong: empty retrieval, unsupported answer, tool failure or partial response? | Empty search, made-up answer, tool 500, or a truncated reply? | Outcome labels and quality checks. |
| Which tenants and workflows are affected? | Is only Acme's German refund flow slow, or everyone? | Sampling and blast radius. |
| What content is forbidden in telemetry by default? | Can we store the full prompt, or only "retrieval 1.2s, 3 docs"? | No-capture list and redaction. |
| Who must diagnose incidents, and what may support see? | Can L1 support open another tenant's raw tickets while debugging? | Tenant-scoped views and access roles. |
| What overhead, retention and sampling budget are acceptable? | Can we afford 100% traces for 90 days, or 5% for 14? | Collector and store size. |
An SLO (service level objective) is the internal target the team commits to, such as "95% of answers in under 3 seconds". The full discovery set adds two questions to those six and states why each changes the design.
The complete discovery set from the full design.
| Question | Why it changes the design |
|---|---|
| What counts as slow: which percentile, on which path, for which workflow? | Sets the SLO the whole trace model is built to explain |
| What counts as wrong: incorrect, empty, hallucinated, or a surfaced tool failure? | Decides which outcome tags every request carries |
| Which users and tenants are most affected? | Decides where instrumentation starts |
| What may be captured by default, and what is contractually off limits? | Writes the no-capture list before anything else |
| Who must diagnose a failure: support alone, or engineering every time? | Decides whether a trace-linked support workflow is a requirement |
| What telemetry overhead is acceptable? | Makes instrumentation a budgeted constraint |
| What retention window applies, and who may read traces under which role? | Sets the store's retention and the access gateway |
| What must the sponsor see to believe quality is improving? | Decides the top panel of the dashboard |
Notice that every answer lands on a concrete artefact: an SLO, an outcome tag, a no-capture list, a store size, the top dashboard panel. If an answer would not change anything you build, the question can wait.
2. Decide what not to collect first
The unusual first design decision is the no-capture list. Full capture maximises forensic power, but it raises privacy exposure, access-control burden and storage cost at the same time. Data that is never collected cannot leak through the trace store, cannot overload a metrics backend and costs nothing to store.
What must be observable by default, and what must not be captured by default.
| Must be observable by default | Must not be captured by default |
|---|---|
| Request identity: a stable request ID and tenant context | Full prompts |
| Retrieval evidence: what was retrieved, and whether it was relevant | Raw customer documents |
| Model invocation metadata: model version, prompt template version, generation settings | Secrets |
| Tool call outcomes: status, latency, error class | High-cardinality free-form labels: arbitrary user text, unbounded metadata keys |
| Timing at each hop of the pipeline | |
| User-visible outcome tags: success, partial answer, escalation |
Cardinality is the number of distinct values a label can take. A label such as region has a handful; a label holding free user text has as many values as there are requests, and every distinct value becomes a new series a metrics backend must index. That is why free-form labels sit in the right-hand column with secrets.
The left-hand column becomes a fixed span schema: correlation ID, tenant, span name, timing, model and prompt-template versions, retrieval references, tool outcome, error class and user-visible outcome. Retrieval references are document identifiers and query fingerprints, not document text.
"Never capture anything" goes too far the other way. Capture enough structure to diagnose most incidents, redact by default, and record hashes or stable references instead of content. Then keep a narrow break-glass path for approved deep debugging: it can capture deeper evidence only with approval, strict access, a short timer on retention and an audit record of every use.
Interviewers usually inject this as a hidden constraint mid-round: the customer will not allow raw prompts to be broadly retained. A design that started from "capture everything" has to restart. A design that started from the no-capture list only has to name its break-glass path.
3. State requirements as testable constraints
A requirement that cannot fail a test is a preference. "Observable" is a preference. "Support moves from a complaint to the request family without seeing raw content" is a constraint, and it shapes the architecture. A request family is the group of related requests behind one complaint: the same user, workflow and time window, found through correlation IDs and outcome tags rather than by reading prompts.
Functional requirements say what the system does. Non-functional requirements say how well it does it and under which constraints. The functional core is the support workflow: a support agent moves from a user complaint to the exact request family and explains the failure without seeing raw sensitive content. Five more functional requirements make that possible.
- Attach a stable correlation ID to every request and propagate trace context through authentication, tenant resolution, retrieval, model, tools, post-processing and queues, including across services and customer integrations.
- Capture per-hop timing across authentication, tenant resolution, retrieval, model call, tool use, post-processing and delivery, with outcome tags.
- Record retrieval evidence, model version, prompt template version, generation settings and tool outcomes as structured attributes.
- Keep an aggregate global dashboard for platform health separate from tenant-scoped views for customer debugging.
- Tag every request with a user-visible outcome, so complaints map to telemetry. Keep an access audit that does not depend on sampled debug traces.
Each non-functional constraint is phrased so a test can fail it.
Non-functional constraints stated so they can be tested.
| Constraint | Stated so it can be tested |
|---|---|
| Latency | Instrumentation must not become the outage; telemetry overhead is a budgeted constraint, measured with and without export |
| Availability | Telemetry export failure degrades diagnostics but never blocks the user request |
| Security | Full prompts, raw documents and secrets are never captured by default; sensitive fields are classified and hashed before storage; redaction pass rate is zero raw prompts in any sink |
| Compliance | Audit logs (who accessed what) stay separate from debugging traces (what failed where) |
| Reliability | No single global sampling rule governs all error paths |
| Cost | Volume scales with request rate, trace rate, retention window and sampling rate, so the first decision is what not to collect |
| Diagnosability | Trace coverage high enough that complaints map to traces; mean time to diagnose falling after the support workflow lands |
The main guide states the same constraints more compactly, and adds two that are easy to forget: tenant isolation with bounded retention, and a stricter failure policy for protected-action evidence than for ordinary traces.
Compact non-functional requirements, with the illustrative volume target.
| Requirement | Example target / constraint |
|---|---|
| Non-blocking | Telemetry cannot stall the user request. |
| Overhead | Stay within an agreed budget. |
| Privacy | No full prompts, raw documents, secrets, or unbounded free-form labels by default; redact before storage. |
| Isolation | Tenant isolation; bounded retention. |
| Audit | Protected-action evidence has a stricter failure policy than ordinary traces. |
| Volume (illustrative) | 500 rps × ~6 spans ≈ 3,000 raw spans/s. Keep all errors/outliers (~2–5%) plus ~5% of normal traffic. ~200 B/redacted span × 30 days ⇒ ~110–155 GB (~270–390 GB at a more typical ~500 B/span). Classifier/export capacity matters more than disk. |
Every requirement then needs an owner in the architecture. If you cannot point to the component that satisfies a requirement, the design has a gap.
Each requirement and the component that owns it.
| Requirement | Primary component(s) |
|---|---|
| Complaint to request family, unaided | Support and access gateway, tenant-scoped views, outcome tags |
| Correlation across services and queues | Trace collector, queue serialisation contract |
| Per-hop timing | Spans emitted at every hop into the collector |
| Structured evidence without raw content | Sensitivity classifier, keyed hash (HMAC) |
| Global versus tenant views | Two consumers of one store, with a permission boundary |
| Overhead within budget | Sampling policy, attribute caps, bounded retention |
| Audit separate from debug | Audit and redaction pipeline with its own write path |
If the interviewer asks "What are the requirements?", the short spoken version from the source is:
"Functionally, one ID through every hop, timings and outcomes, tenant-scoped debug. Non-functionally, don't block the user, don't store the prompt, and still find why it was slow or wrong."
4. Size the telemetry by collection policy
Estimation here starts from collection policy, not from raw QPS (queries per second). Telemetry volume, storage and query load all scale with the sampling rate, the cardinality bounds and the retention window. Observability data is not free, and instrumentation that is not budgeted becomes the outage.
The source chapter itself gives no numbers. A supplementary "gap note" from the V2 tutorial supplies a worked version. Say it aloud in the interview, because its conclusion surprises people.
Worked sizing from the V2 gap note (supplementary, illustrative).
| Step | Figure (V2 gap note, supplementary) |
|---|---|
| Peak traffic | 500 requests/second |
| Spans per request | ~6: auth, retrieval, model, tool, post-processing, plus the root request span |
| Raw span rate | ~3,000 spans/second before sampling |
| Tail-biased retention | 100% for error and latency-outlier traces, roughly 2-5% of volume |
| Probabilistic sampling for the rest, decided in the tail sampler | 5% |
| Effect | Raw trace volume cut by roughly 90%, failure population preserved |
| Stored size | ~200 bytes/span after redaction, 30-day retention, about 110–155 GB (roughly 270–390 GB at a more typical ~500 bytes/span) |
Here is the arithmetic behind the last two rows. If 2% of traffic is errors or outliers, we keep that 2% plus 5% of the remaining 98%, about 7% of spans. At 5% anomalies we keep about 10%. Seven to ten percent of 3,000 spans a second is roughly 210 to 300 spans a second, which is the "cut by roughly 90%". At 200 bytes a span, 210 spans a second for the 2,592,000 seconds in 30 days is about 109 GB, and 300 a second is about 156 GB. At 500 bytes a span the same range becomes about 270 to 390 GB. The typical 500-byte figure comes from Grafana Tempo's trace-ingestion documentation.
The note's conclusion is that storage is not the constraint at this scale. Classifier CPU and the correctness of the redaction policy are. Every span passes through the classifier before storage, so the classifier sits on the observability path's critical line. Volume still depends on span size, the overlap between sampling classes and traffic shape, so treat these figures as an order of magnitude.
Sampling is a deliberate control, and the two basic kinds behave differently.
- Head sampling decides at the start of a request whether to keep its trace. It is simple and cheap, but it is blind to how the request ends: a 5% head sample drops 95% of the failures along with 95% of the successes.
- Tail sampling decides after the request completes, so it can keep slow and failed traces. It needs more buffering, more infrastructure and careful policy, because every trace must be held until its outcome is known. All spans of one trace must also reach the same sampler instance, so a scaled deployment puts a trace-ID-aware load balancer in front of the tail-sampling collectors.
The interview-safe position is to retain latency-heavy, error-heavy and anomalous traces first, then keep a small random share of the ordinary remainder. Both decisions belong to the tail sampler after the trace completes. A head sampler that dropped a request at the start could not keep it later when it failed.
Follow the two branches. Down the head-sampling branch, a rare and expensive-to-reproduce failure is dropped with the same probability as a healthy request, so the only bad trace can be lost. Down the tail-sampling branch, the decision sees the outcome, so latency-heavy, error-heavy and suspicious traces are retained. The sampling deep dive adds the overrides that protect rare failures and the drill for when a trace is lost anyway.
5. Draw the architecture end to end
The design is tracing-first: structured spans, selective redaction and a stable correlation ID on every request from the edge inward. Two paths run side by side. The request path serves the user: it may use retrieval, an LLM and tools. The observability path describes those steps, but it cannot authorise, alter or stall them. A bounded asynchronous export separates the two, and nothing raw crosses the classifier boundary into the trace store.
Trace one request through the figure, step by step.
- Give each authorised request a correlation ID and tenant scope at the edge, and propagate both across services, queues and integrations.
- Time retrieval, model, tool and post-processing steps, attaching structured version, error and outcome metadata, while the request continues to the user.
- Export spans asynchronously through a bounded buffer. If export fails, serve the user anyway and alert on the diagnostic gap.
- Classify and redact sensitive fields before storage. Where correlation is needed, replace the value with an HMAC fingerprint made with a secret key, and cap attribute cardinality. HMAC (hash-based message authentication code) is explained in the redaction deep dive.
- Bias retention towards error and slow traces, with exemplars and incident overrides so rare failures stay diagnosable. An exemplar is a metric data point that carries the trace ID of one request it measured, so a latency chart links to a concrete trace. The link is only useful if the sampler also keeps that trace, so exemplar traces are exempt from sampling.
- Store only bounded, retention-limited traces. Send platform-wide aggregates to the global dashboard, and enforce tenant and role access for support views.
- Write support access events to a separate, durable audit path, so trace sampling cannot erase the record of who viewed evidence.
On a whiteboard the same design fits in four lines. Request: auth/tenant → retrieval → LLM → tools → response. Spans: async collector → classify/redact/HMAC → error-and-slow-biased sampling → bounded store → global aggregate and tenant-scoped support views. Access audit is separate. Telemetry export never blocks the user.
The full design draws the same system twice more, once per path, with the trust boundaries visible.
Two properties hold across both drawings. Serving never waits for telemetry export, so buffer or export failure degrades observability without blocking the user. And no raw content crosses the classification boundary.
The source's original diagram, kept verbatim, shows the same split with the two paths labelled.
The component table names each part's job and, in the added right-hand column, how it fails. Reading the failure column is the quickest way to see why each boundary exists.
Components, responsibilities and failure modes.
| Component | Primary responsibility | Notes | Fails how |
|---|---|---|---|
| Trace collector | Attach correlation ID, propagate context, capture spans per hop | Structured, not raw text by default | Context lost at a queue; orphan spans |
| Sensitivity classifier | Classify and hash sensitive fields before they reach telemetry | Runs before storage, not after | A missed pattern writes PII into every downstream sink |
| Trace store | Durable, retention-bounded storage of exported traces | Retention window is a cost and privacy control | Unbounded retention turns it into a data lake of customer content |
| Global dashboard | Platform-wide health, release regressions | Cross-tenant, aggregate only | A tenant label on a global chart explodes cardinality |
| Tenant-scoped views | Customer-specific debugging, support triage | Access scoped by role and tenant | One misconfigured view spans every tenant |
| Support and access gateway | Role-based, tenant-scoped access to evidence | Enforces least privilege | "Can read all traces" becomes the default |
| Audit and redaction pipeline | Enforces retention and redaction on export | Defence in depth: code, collector, review | Combined with debug traces, it inherits their sampling and short retention |
PII (personally identifiable information) is anything that identifies a person: name, email, phone or account number. Four questions organise the walk-through, and you should answer each one against the diagram:
- How does each request get a correlation ID? At authentication, before anything else runs.
- How does trace context flow across services and customer integrations? In headers between services, and in an explicit serialisation contract across queues.
- How does a support operator jump from an alert to the request family without seeing raw content? Through outcome tags, fingerprints and document references in a tenant-scoped view.
- How are global and tenant visibility separated? Two consumers of one store, with a permission boundary: aggregates only on the global side, tenant and role checks on the support side.
6. Name the failure policy for every layer
Every dependency needs an explicit answer to one question: what happens when it is gone? Five terms cover the possible answers.
- Fail open continues with reduced visibility.
- Fail closed refuses the action when integrity, privacy or authorisation would be compromised.
- Degrade serves a reduced but safe experience.
- Queue buffers the work with explicit bounds and retention.
- Human intervention escalates when risk or ambiguity is too high for automation.
The failure policy for each layer.
| Failure | Policy |
|---|---|
| Auth token missing | Fail closed; do not infer identity; ask the caller to re-authenticate |
| Telemetry export unavailable | Degrade; continue serving, buffer a bounded summary, alert |
| Retriever timeout | Retry once with jitter; if still failing, degrade to a reduced-answer path or ask for refinement |
| Model gateway rate limit | Queue briefly if the SLA allows; otherwise fail gracefully with a specific retry message |
| Audit sink unavailable | Usually fail closed for the audited action, or require a human; silent loss of audit evidence is unacceptable |
| Support lookup outside tenant scope | Fail closed; no cross-tenant fallback |
| Repeated downstream timeouts | Trip a circuit breaker; serve a safe degraded response or queue if the workflow permits |
| Evidence buffer full | Dead-letter the overflow into a restricted quarantine queue with an incident marker, then alert a human |
An SLA (service level agreement) is the promise made to the customer, usually with penalties, and is looser than the internal SLO. A circuit breaker stops calling a dependency after repeated failures so the system stops waiting on timeouts. A dead-letter queue holds messages that could not be processed so they are not silently lost.
Say aloud why the rows differ. A user-facing answer can sometimes degrade; an audit trail usually cannot. A retriever timeout can be retried; a permission check cannot be guessed. In short: telemetry export may degrade, while missing auth, cross-tenant support lookup, raw-content redaction failure and required audit evidence fail closed.
Then name the blast radius, the set of users a failure can reach, along four axes: tenant, region, workflow and dependency. The axes behave differently for different failures. A raw-prompt leak is usually tenant-scoped but workflow-wide. A trace break at a queue boundary can hit one integration path across many tenants. A model outage may be regional. A misconfigured support tool can span every tenant. Limiting blast radius along those axes is what lets one failure stay one incident. The failure drills deep dive works through four more named failures and the abuse case.
7. Diagnose from the complaint down
A dashboard built from component metrics shows rates without telling anyone whether the user's experience improved. So build it from one incident story, top down. The complaint is "the AI is slow and sometimes wrong."
- The top panel shows the user outcome: latency percentile, first-token time, failure and partial-answer rate, incident volume and the affected tenant.
- The middle panel shows likely causes: retrieval success, tool success, model error class and token cost. This is where request time is split into retrieval, rerank, model queue, provider, tools and delivery.
- The bottom panel shows support mechanics: trace coverage, redaction rate, queue age for incidents and mean time to diagnose.
Track completion, abandonment and support contacts alongside these technical signals. A system can get faster and still fail its users.
For latency, compare first-token time with total time. A slow first token points at prompt size, prefill, retrieval or queueing before generation. A fast start that drags points at a long decode, the token-by-token generation phase. The neighbouring prompts deep dive explains why.
For a wrong answer, compare the retrieved evidence with the final answer.
- If retrieval is empty, stale or off-topic, the fault is upstream. A better model cannot answer from evidence it never received.
- If retrieval looked good but the answer contradicts it, suspect the model or the prompt construction (synthesis).
- If the bad answer appears for only one tenant, suspect that tenant's configuration, access control or integration state before blaming the shared model.
This only works because of the signals kept in step 2: request and tenant correlation IDs; retrieval query fingerprints and document identifiers, not raw text; model version, prompt template version and generation settings; tool call status, latency and error class; and outcome tags.
Alert on customer harm or likely impending harm, not on telemetry volume. Good triggers are sustained latency above the SLO, elevated error rates, repeated empty retrievals, a spike in fallback responses and critical tool failures. A sudden rise in "wrong answer" feedback for one tenant or cohort is another.
The design has to survive one more case: sampling dropped the only bad trace. Compare complaints with trace coverage, temporarily raise fidelity for the affected slice, reconstruct from gateway and dependency evidence, mark the gap, then add error-class overrides and always-on exemplars. A missing trace does not mean no failure. The sampling deep dive gives the full four-step drill.
Two source incidents show the method at work, and each is told in full in the deep dives.
- Latency incident. p95 reached 22.18 s against a 7 s target. Retrieval at 4.2 s, the reranker at 3.1 s, the gateway queue at 2.8 s and the provider at 9.36 s stacked up after a larger reranker and a model-route change. The response is to roll back the route, cap candidates, enable a light-reranker fallback and keep EU traffic near an EU endpoint, then load-test peak queue depth before repeating the experiment. See the latency spike.
- Cost incident. Requests rose only 7% while input tokens rose 351%, cache hit rate fell from 67% to 4%, and a larger prompt crossed an expensive model-routing threshold. The response is to roll back the template, restore compression and context caps, invalidate the flawed cache entries and version cost gates. The cache key also lost
role_scope, so this was a permission incident as well as a budget incident. See the cost spike.
8. Roll out in four phases with named owners
Observability fails socially before it fails technically. If no one owns a signal, no one owns the decision. So the rollout has names, gates and exit criteria, not only components.
Four rollout phases, owners and exit criteria.
| Phase | Owner | Exit criterion |
|---|---|---|
| 1. Define user-facing SLOs first | Product and engineering, with the customer signing off | Agreed latency targets, acceptable failures, support boundary, definition of a customer-visible incident. No agreement, no wider release |
| 2. Instrument one critical path | The primary service team, with platform support | One representative request traced end to end through auth, retrieval, model, tool and response assembly |
| 3. Add the trace-linked support workflow | Support engineering or customer success, with on-call defined | A support agent moves from a complaint to a trace without asking the user for raw prompts |
| 4. Add quality and cost signals with sampling | The observability platform owner, with model and product owners setting thresholds | Enough signal to detect regressions, sampling only what is needed |
The answer key gives a weekly version. SLOs come in weeks 0-1 and a measurable "slow" and "wrong" in weeks 1-2. One instrumented path follows in weeks 2-3 and redaction scanning in weeks 3-4. The support workflow lands in week 5, then quality and cost signals in weeks 6-8.
Eight metrics make up the scorecard. Each has a calculation, an owner and an alert condition, so nobody argues about what a number means during an incident.
The eight-metric scorecard.
| Metric | Calculation | Owner | Alert when |
|---|---|---|---|
| Availability SLO | Successful requests / total, excluding agreed out-of-scope failures | Application engineering with platform | The burn rate threatens the SLO |
| Latency SLO | Latency at the agreed percentile, usually p95 or p99 | Application engineering | Sustained breach, or a breach after a release or canary |
| Retrieval and tool success | Successes / attempts, by dependency and tenant | The owning service team | Below baseline, or a sudden shift in failure class |
| Token cost | Tokens per successful request, or cost per tenant per day | Product operations or finance partner | Consumption rises faster than traffic, or exceeds budget |
| Quality-event rate | Visible failures, escalations, reviewed bad outputs / sessions | Product and ML engineering | A meaningful rise after any release or config change |
| Trace coverage | Traced requests / expected requests on the critical path | Observability platform | Below the minimum needed for the top failure path |
| Telemetry overhead | Added latency, compute, storage, network versus baseline | Platform and SRE | Overhead materially raises latency or cost |
| Mean time to diagnose | First report or alert to a credible root-cause hypothesis | On-call engineering and support operations | Stops improving, or exceeds the response target |
SRE (site reliability engineering) is the team and practice that keeps production running; ML is machine learning. The go/no-go gate is concrete: if trace coverage falls below the minimum or overhead moves latency, the release pauses. Rollback triggers are equally concrete: loss of trace propagation, a spike in quality-event rate, or an unsustainable cost slope.
Decide what is core product, shared service, adapter or configuration. Per-customer sampling rates, retention windows and alert thresholds are configuration. Ticketing and alerting integrations are adapters. Collection, redaction, correlation propagation and the access gateway are a shared service. The request lifecycle, outcome tags and the minimal schema are core product. That split keeps customer edge cases out of the core.
Launch readiness needs a canary on one tenant or slice and a fast rollback switch. Keep old and new trace schemas interoperable during migration. Train support on what a healthy trace looks like, and publish an operations guide with metric definitions, access rules and rollback steps. Have three artefacts ready before launch: an evidence policy, a response runbook and an access review.
Risk register.
| Risk | Owner | Mitigation | Trigger |
|---|---|---|---|
| Sampling drops the only bad trace | Observability platform | Bias sampling toward error paths and reported incidents | Support cannot find evidence for an acknowledged failure |
| Telemetry becomes the bottleneck | Platform and SRE | Cap attributes, bound storage, monitor overhead | Latency or cost rises after instrumentation changes |
| Support sees too much or too little | Security and support engineering | Role-based access, redaction, audit logging | Sensitive content in support artefacts, or triage stalls |
| Quality signals are noisy | Product and ML engineering | Separate objective service metrics from subjective labels | Alerts fire on expected experimentation |
| Adoption mistaken for success | Product | Track task completion and business outcome | Usage rises while escalations and manual work stay flat |
The measures that prove the rollout worked are mean time to diagnose, the privacy invariant (zero raw content in any sink), trace coverage, telemetry overhead, latency, retrieval and tool success, quality-event rate and token cost by workflow. Gate wider release on adequate trace coverage and tolerable overhead.
Technical deep dives
Examine mechanisms, alternatives, and operational consequences.
Redaction, keyed hashing and data boundaries
A classifier that runs after storage protects nothing, because the raw value has already been written and every system that reads the store has it. So classification happens before a value can reach a trace. A keyed hash then preserves correlation without retaining content.
The data model
The data model is small. A Request carries tenant ID, prompt and an optional user ID. An ExportedTrace carries only a bounded, structured attribute dictionary: correlation ID, tenant ID, prompt classification, query hash, spans and result status. It never carries raw prompt text by default. The prompt enters the system on the request side and stops at the classifier; only its classification and fingerprint cross.
Why the hash must be keyed
HMAC-SHA256 combines the value with a secret key before hashing. The same prompt with the same key always produces the same fingerprint, so the fingerprint can deduplicate and correlate repeated queries across the store. A plain unkeyed hash would do that too, but anyone could hash a list of common prompts and match the results, which is a dictionary attack. Without the secret key, nobody can brute-force common prompts back out of an HMAC. RFC 2104, section 3, requires HMAC keys to be random, or drawn from a cryptographically strong generator, and periodically refreshed to limit the damage of an exposed key.
If the key leaks, attackers can run that dictionary attack, so the key lives in a vault and is rotated. A missing key raises an error. The code must never fall back silently to a plain unkeyed hash, because that fallback looks like success while removing the protection. Rotation has a cost: a fingerprint made under the old key never matches one made under the new key. Store a key version beside each fingerprint, and expect correlation across the rotation boundary to break unless lookups try both keys during an overlap window.
Three executable contracts
Three tests turn the design into contracts that fail when the code drifts.
Three tests and what each proves.
| Test | What it proves |
|---|---|
| Idempotent trace ingestion: post the same trace twice | The second post returns "deduplicated", so a retry never double-counts |
| Privacy invariant: a request containing person@example.com | The address never appears in the exported JSON; the query hash is present; the classification is "sensitive" |
| Failure injection: the retriever raises a timeout after acceptance | The failure is still observable; the trace summary is written in a finally block with an outcome="partial_failure" field |
The last test guards the case's central failure drill: sampling and redaction must never hide a failure. Writing the summary in a finally block means it is emitted whether the request succeeds or throws.
Schema, cardinality and queue boundaries
Telemetry attributes are schema-validated at ingestion. Unknown high-cardinality fields are rejected or collapsed into a bounded "other" bucket. Ingestion is idempotent, so retries do not double-count.
Queue serialisation contracts carry trace context, idempotency key and tenant scope explicitly. Instrumented HTTP clients and servers carry trace context between services in the W3C traceparent header, but a message placed on a queue carries only what its schema includes. If correlation and tenant scope are not serialised into the message, the consumer starts a fresh trace and the spans after the handoff become orphan spans with no parent.
Two paths: debug traces and access audit
Debug traces and access audit have separate paths. The trace store is sampled and short-lived. The audit store records who viewed which trace, when and why, and has stricter durability. If audit lived in the trace store, it would inherit trace sampling and short retention, and an access event could be sampled away. Global dashboards aggregate across tenants; support views are tenant-scoped by role. Test the access gateway for leakage and audit every break-glass use.
Sampling toward failures and the missing-evidence drill
The case's signature phrase is "sampling drops the only bad trace." Uniform sampling keeps a fixed fraction of everything. When failures are rare, a fixed fraction of a rare thing is often zero. For example, at a 5% uniform rate a failure that happens three times in an hour has about an 86% chance of leaving no trace at all (0.95 cubed), an illustrative calculation rather than a source figure. Expect the interviewer to inject this mid-round and have the answer ready.
Head sampling is cheap but cannot know a request's final outcome. Tail-biased retention costs more buffering but preserves slow and failed traces. A policy that survives rare failures combines four mechanisms:
- normal low-rate sampling for ordinary traffic;
- error-class overrides, so every request with a given error class is kept;
- always-on exemplars, whose linked traces are always kept, plus a low-rate stream of kept traces for each path even when nothing looks wrong;
- temporary tenant or route escalation during an incident, raising fidelity for just the affected slice.
Monitor trace coverage against complaints and request errors. Never read a missing trace as proof of health.
When a bad trace is lost anyway, walk the four-step drill.
The "sampling drops the only bad trace" drill.
| Step | Sampling drops the only bad trace |
|---|---|
| Detection | Compare complaint intake, request errors and anomaly signals against sampled trace volume. Complaints rising while traces for that workflow fall is a blind spot, not a healthy system |
| Containment | Switch the affected tenant, route or error class to higher-fidelity sampling temporarily; preserve the raw event envelope in a protected quarantine store if policy allows |
| Recovery | Reconstruct from neighbouring evidence: API gateway logs, model gateway errors, dependency spans, support tickets. Mark the missing trace explicitly in the incident record |
| Prevention | Never let one global sampling rule govern all error paths. Use error-class overrides, low-rate always-on exemplars and per-tenant incident escalation hooks |
The first move under this injection is to contain impact, preserve evidence and make the failure legible, recording the uncertainty that reconstruction leaves. Defending the sampler or arguing about probability is the weak move.
Failure drills, the abuse case and chaos practice
The failure policy says what each layer does when a dependency disappears. Four more named failures get the full drill: how you detect it, contain it, recover and prevent a repeat.
Four named failures through detection, containment, recovery and prevention.
| Failure | Detection | Containment | Recovery | Prevention |
|---|---|---|---|---|
| Tenant ID has a high-cardinality bug | Cardinality budgets and exporter rejections; a spike in unique tenant labels is itself an incident | Strip or normalise untrusted attributes at ingestion; collapse unknowns into "other" | Fix the mapper; backfill only the minimal aggregates for the review | Schema-validate attributes; reject unknown high-cardinality fields before export |
| Logs store a raw prompt | Scanners and red-team tests search logs, traces and support transcripts for PII and secret formats | Revoke sink access, rotate exposed credentials, quarantine the log set | Delete or redact per retention policy and contract; notify owners | Enforce redaction in code, in the collector and in review |
| Trace context breaks at a queue | A trace starts, then vanishes after async handoff; orphan spans; a spike in "unknown root" events | Propagate a minimal correlation envelope through the queue | Stitch spans by correlation ID and timestamp; mark the join as reconstructed | Queue contracts carry trace context, idempotency key and tenant scope, and are tested |
| Quality metric improves while adoption falls | Pair technical metrics with completion rate, retries, abandonment, support contacts | Treat it as a product problem, not a hotfix | Product review, metric reset, possibly roll back the latest change | Track task completion and business outcome, not usage volume alone |
A raw-prompt export is a privacy incident, not a logging bug. Contain access to the sink, rotate exposed credentials if necessary, delete or redact according to the contract, and fix the exporter guardrail.
The abuse case shows how that happens. A developer adds a raw prompt field to a debug span to speed up triage. It works once, then becomes the easiest way to move PII into every downstream system that reads traces. The fix has three layers: a redaction policy, an exporter guardrail that strips the field, and a test that fails whenever exported telemetry contains raw sensitive strings.
The remaining operational rules are short. Breakers stop repeated downstream timeouts. A buffer overflow enters restricted quarantine with an incident marker. An audit sink failure blocks the audited action or requires a human. Retrieval may retry once, then return a clearly reduced answer; model limits may queue briefly or return a retry instruction.
Inject sampler loss, queue-boundary breakage, redaction regressions and dependency timeouts in staging. Chaos practice proves the failure policy works before production forces the discovery.
The latency spike after a reranker and model-routing change
A slow pipeline is rarely one slow component. This incident is the proof: no single span explains it, and every small change looked safe on its own.
Setting and symptom
A B2B (business-to-business) SaaS support copilot runs inside a live support console. Agents expect answers in under 5 seconds because the customer is waiting in chat. The path is Support Console → RAG API → query rewrite → hybrid retriever → cross-encoder reranker → context compressor → LLM gateway → model provider → response evaluator → UI stream. A cross-encoder reranker reads the query and each candidate document together to re-score them; it is more accurate than the first-stage retriever and much slower per candidate. The target is a 7-second p95 with a 12-second hard timeout.
On 2026-07-08, during peak European hours, agents saw the spinner for 18 to 35 seconds. Some answers arrived after the human agent had already replied. Handle time rose 21%. It was not an outage: success rate stayed acceptable, but p95 and p99 broke the SLO.
Telemetry
Latency incident telemetry.
| Signal | Value |
|---|---|
| p50 / p95 / p99 (eu-central-1, 5-minute window) | 5310 ms / 22180 ms / 34890 ms |
| Timeout rate | 12.8% against a 1.1% baseline, over 1842 requests |
| Retrieval p95 | 4200 ms |
| Reranker | 3100 ms; cross_encoder_large_v4; 80 candidates in, 12 out; batch size 1; GPU queue depth 29; light-reranker fallback off |
| LLM gateway queue | 2800 ms; primary provider degraded; 1 retry, retry-after 750 ms |
| Provider latency | 9360 ms, routed to us-east-1 from eu-central-1 |
| Context compression | 740 ms |
| Tokens | 18500 in, 610 out |
| First token / total | 14120 ms / 23840 ms against a 12000 ms timeout budget |
Read the table from the top. The p50 of 5.3 s is close to normal, while p95 and p99 are far above it: the tail broke, not the median, which already hints at queueing. Adding the listed stage figures (4,200 + 3,100 + 2,800 + 9,360 + 740 ms) gives about 20.2 s before query rewrite, evaluation and streaming. Stage percentiles do not add exactly, so treat that as a budget check, but it shows the 22.18 s p95 is several moderate delays stacked rather than one broken service. The first token at 14.1 s is already past the 12 s budget, which settles one tempting fix in advance. A 12-second hard timeout and a 22.18 s p95 hold together only because they sit at different boundaries, with the timeout firing at the gateway while the console keeps waiting and measuring. Confirm where each timeout is enforced and measured before using either number in an alert.
What changed and why
Two changes landed within 24 hours. The reranker moved from cross_encoder_small_v2 to cross_encoder_large_v4. The router moved standard answers from a faster mid-tier model to a larger one after a quality experiment. The canary ran only in low-traffic hours and never tested peak GPU queue depth.
The root cause is compounded latency. A larger candidate set, a slower reranker, a bigger context, gateway queueing and cross-region routing stacked up. The pipeline broke its budget because several "small" changes landed together.
Debugging path
Decompose the trace into spans and compare each stage's p95 with its baseline. Check candidate count, context tokens, queue time, provider latency and regional routing. Compare canary with control and peak with off-peak. Check whether timeouts land before or after the first token. A 14-second first token means streaming cannot rescue the experience, because the user sees nothing until then.
Fix
Now: roll back the model route, cap reranker candidates at 30, and enable the light reranker when GPU queue depth exceeds 10. Also reduce max context tokens and route EU traffic to an EU-capable endpoint.
Later: add a latency budget per stage and load-test gates for reranker queue depth. Enforce context caps per workflow and add circuit breakers for provider degradation. Quality experiments must pass latency and cost SLOs, not only answer quality.
Abuse angle
Latency becomes a safety risk when users abandon the assistant or bypass review. Broad queries that trigger large candidate sets and expensive reranking are a cheap denial-of-wallet or denial-of-service vector: an attacker spends little to make the system spend a lot.
The answer to give
Spoken answer example (source):
"I would start with span-level latency decomposition. The trace shows retrieval at 4.2s, reranker at 3.1s, LLM queue at 2.8s, and provider latency at 9.3s, with 18.5k input tokens. That means this is a pipeline-budget failure, not just one slow API. I would roll back the model route, cap reranker candidates, enforce context compression, add queue-depth fallback, and make future quality experiments pass p95 latency and timeout-rate gates."
The weak answer is "increase the timeout and maybe use a faster model." It never reads a span.
The cost spike from a prompt-template and cache-key regression
Production generative AI systems fail economically as well as technically. This incident produced no quality complaint at all. The only symptom was a budget alert.
Setting and symptom
An executive dashboard copilot summarises revenue, pipeline, customer-risk notes and operational metrics. The path is UI → metrics API → CRM-note retrieval → prompt assembler → semantic cache → LLM gateway → cost attribution. CRM (customer relationship management) is the sales system of record. The cache key should include tenant, dashboard type, date range, normalised query and data snapshot ID. The router picks a mid-tier or a larger model by context size and sensitivity.
On 2026-07-08 the daily budget alert fired at 14:20. The CFO (chief financial officer) asked why the assistant had consumed almost four days of budget before lunch: $912 against a $240 daily budget is 3.8 days.
Telemetry
Cost incident telemetry.
| Signal | Value |
|---|---|
| Spend | $240 daily budget; $912 actual; $1680 projected by end of day |
| Deltas | Cost +280% (3.8×); requests +7%; input tokens +351% |
| Prompt template | exec_summary_v6; average context 4200 → 19000 tokens |
| Context contents | all_notes_90d instead of top_20_notes_30d; 500 table rows instead of a cap of 80; compression disabled |
| Cache | Hit rate 4% against a 67% baseline; key v5 = [tenant_id, query_text]; missing date range, snapshot ID, role scope |
| Routing | GPT-4-class because context_tokens>12000; 21384 tokens in, 1288 out; about 4.6× the per-request cost of before ($1.44 against $0.31) |
The first two rows rule out the obvious story. Requests grew 7%, so users did not cause a 3.8× bill. Input tokens grew 351%, so the cost is in the shape of each request. The template row shows the context grew from 4,200 to 19,000 tokens; the routing row shows that growth pushed requests over the 12,000-token threshold into an expensive model; the cache row shows the system stopped reusing answers.
What changed and why
The exec_summary_v6 upgrade added "more supporting context" after executives asked for richer explanations. The same release changed cache-key normalisation and dropped the date-range and snapshot fields. It also disabled compression while debugging a formatting issue.
The root cause is three effects multiplying. The template expanded context. The larger context crossed the routing threshold into the expensive model. The cache-key regression collapsed the hit rate, so the system paid full price for every large prompt. The two key changes pulled in opposite directions. Keying on raw query_text instead of a normalised query fragmented the keys, and the new template started from a cold cache, which together explain the fall from 67% to 4%. Dropping date range, snapshot and role scope made each key match more requests, which on its own would raise the hit rate and created the over-sharing risk described below. Each effect alone would have been a moderate increase; together they compound.
Debugging path
Start with cost per workflow, not global provider spend. Compare request count, input and output tokens, model route, cache hit rate and prompt version before and after the deploy. Sample traces to see what was assembled. Check whether the added context improved answers enough to justify its cost.
The hidden correctness bug
The key also lost role_scope. One user's executive summary could be served to another role whenever the query text matched. A cost incident turned out to be a permission incident too. This is why cache changes need a security review as well as a cost review: a cache key defines who may receive a stored answer.
Fix
Now: roll back exec_summary_v6, restore compression, cap CRM notes and table rows, and force the mid-tier model for routine summaries. Invalidate every cache entry written under cache_key_version=v5, because any of them might have been served across roles.
Later: add cost regression tests to CI and enforce per-workflow token budgets. Require cost and latency approval for template upgrades, track hit rate by version, and route with budget awareness and graceful degradation.
The answer to give
Spoken answer example (source):
"The telemetry shows usage grew only 7%, but input tokens grew 351%, cache hit rate dropped to 4%, and requests started routing to a GPT-4-class model. I would roll back the prompt template, restore compression, cap context, fix the cache key, and add CI gates for token and cost regression. I would also audit cache safety because missing role_scope can create data exposure."
The weak answer is "ask users to make shorter queries or switch to a cheaper model." It blames usage that grew only 7%.
Neighbouring prompts read from the same traces
The full design combines a group of interview prompts into one read. The anchor design comes first, then the two incidents, then three neighbouring prompts, then a card for every cost and latency pivot in the group.
Which part of this casebook each prompt in the group draws on.
| Case in the group | What it contributes here |
|---|---|
| Observability for a Customer-Facing AI Application (anchor) | Discovery, the no-capture list, requirements, sizing, architecture, redaction, sampling, failure policy, triage, rollout and delivery (walkthrough steps 1 to 8, the redaction and sampling deep dives, and the fifty-minute plan in Practice) |
| Incident: latency spike after a reranker and model-routing change | The latency spike deep dive |
| Incident: cost spike from a prompt-template and cache-key regression | The cost spike deep dive |
| OpenAI practice prompt: Latency Regression in an LLM Application | This deep dive, and pivot card 15.3 |
| OpenAI practice prompt: RAG System with Poor Answer Quality | Walkthrough step 7 and this deep dive |
| Reported OpenAI prompt: diagnose high latency in an LLM inference pipeline | This deep dive |
| Playbook drill: LLM costs exploded after launch | Pivot card 15.1 |
| Scenarios 1, 2, 6, 7, 10, 11, 12 | Pivot cards 15.2 to 15.8 |
| Rate limits throttling at peak, users abandon mid-stream | Pivot cards 15.9 and 15.10 |
The sizing numbers in step 4 come from the V2 tutorial's "My Perspective on the Gaps" note, which is supplementary and not chapter content.
Latency regression in an LLM application
"An enterprise customer reports that responses have become slow." First clarify which latency: time to first token, time between tokens, total completion time or user-perceived latency. Then decompose across ten stages: client and network, authentication, middleware, retrieval, prompt construction, model prefill, token generation, tool calls, post-processing and streaming. Check input and output token counts and retrieval p95 and p99. Then check retry rates, rate-limit throttling and traffic patterns. Finish with model version, prompt changes, cache hit rates and regional routing. The latency incident is this prompt with real numbers.
The follow-up is "it only happens at peak traffic." Peak-only latency points at queueing, not a slower model. Separate queue wait from service time. Queueing delay climbs steeply as utilisation nears 100%: for a simple single queue, the wait is about ρ/(1−ρ) times the service time at utilisation ρ, which is 4× at 80% and 9× at 90%. A rising p99 with a flat p50 usually means queueing. Add admission control and shed non-interactive work to batch. (The utilisation point comes from the source's additions file, section D; the multiples are simple single-queue arithmetic.) A synchronous evaluator or logger left on the hot path is a related trap: it can cancel the benefit of streaming.
RAG with poor answer quality
Separate seven failure classes: retrieval, context assembly, reasoning or synthesis, prompt or instruction, output format, evaluation and user experience. Measure each separately.
- Retrieval: recall@k (the fraction of all relevant documents that appear in the top k), precision@k (the fraction of the top k that are relevant), and ranking metrics such as MRR (mean reciprocal rank) or nDCG (normalised discounted cumulative gain). MRR averages one divided by the rank of the first relevant result.
- Context assembly: citation correctness and context sufficiency.
- Generation: answer faithfulness, answer relevance and abstention quality.
- The whole application: end-to-end task success.
The triage flowchart in step 7 is the first cut; these metrics are the second.
The follow-up is "would you fine-tune the model?" Classify the problem first. A knowledge problem is usually retrieval or data access. A behaviour problem is prompting, fine-tuning or structured output. A freshness problem is indexing and the data pipeline. A permission problem is access-control-aware retrieval. Fine-tuning mainly helps the behaviour problem; it is a poor fix for missing knowledge, stale indexing or unauthorised retrieval. Ovadia et al. (2023) found unsupervised fine-tuning a weaker way to add knowledge than retrieval on their benchmarks.
High latency in an LLM inference pipeline
This is the layer below the application. Walk the full stack: tokenisation, network, batch size, KV cache and post-processing. Two facts carry the answer (from the source's additions file, section B).
- Prefill processes the whole prompt in parallel and sets time to first token, so it scales with input tokens.
- Decode generates one token at a time and sets tokens per second, so it scales with output tokens.
A frozen UI points at prompt size, retrieval and queueing. An answer that starts fast then drags points at output length. In the latency incident, most of the 14.1 s first-token time accrued before the provider started: retrieval, reranking, compression and gateway queueing account for about 10.8 s, and 18,500 input tokens add prefill on top. The 9.7 s from first token to completion for 610 output tokens is slow decode, cross-region round trips and streaming, so both halves need attention.
- Batch size trades throughput for per-request latency. With continuous batching nothing waits for a batch to fill, but each decode step gets slower as more sequences share it.
- The KV (key–value) cache holds attention state for tokens already processed, so the model does not recompute the prompt for every new token. Its memory caps how many sequences fit on a GPU at once, and a full cache forces queueing or preemption. Kwon et al. (2023) and the vLLM tuning guide describe these limits.
- Post-processing is usually small, but a synchronous evaluator or logger on the hot path is not.
The same stack walk anchors the LLM Inference Serving case, so prepare it once.
The cost and latency pivot pattern
Ten members of this prompt group are the same system asked a cost or latency question. Every strong answer runs through four verbs in order.
- Measure. Attribute cost and latency per stage, tenant, workflow, model and prompt version first. Segregate batch and evaluation spend from interactive traffic so they cannot hide inside it.
- Route. Match model and path to risk: send simple tasks to smaller models.
- Bound. Cap output length, context, top-k, retries, agent steps, timeouts and budgets.
- Cache safely. Cache only with tenant, permission scope and version in the key.
Three recurring situations show the pattern applied. For peak HTTP 429 (rate-limit) errors, separate the provider's limits from your own gateway's, and shed non-interactive work. For abandoned streams, cancel generation and in-flight tools; this saves spend where the provider stops generating on cancel. Some hosted providers keep billing after a client cancels, while self-hosted engines such as vLLM's OpenAI-compatible server abort generation on disconnect. For a sudden cache miss, inspect normalisation, prompt prefix bytes, TTL (time to live, how long a cached item stays valid) and version before adding capacity.
Prompt caching is a byte-exact prefix match, so one changed byte invalidates everything after it. A timestamp in the system prompt, unsorted JSON keys, a reordered tool list or a model swap each cause a silent miss. The Claude and OpenAI prompt-caching documentation both describe this exact-prefix behaviour. Keep it separate from an application response cache such as the one in the cost incident. A provider prompt cache reuses the processed prefix, so the model still generates and the saving is on input cost and first-token time. A response cache skips the model call, which is why its key must carry tenant, permission scope and data version.
Each pivot gets a card: the dominant driver, the cheapest lever, the metric that proves it, the move to refuse and the line to say. Every card shares the playbook's customer-communication sentence: "Acknowledge impact, show measured cause, provide immediate mitigation, then explain long-term prevention and success metric." The ten cards are in Practice, so you can attempt each before revealing it.
References
Primary references: OpenTelemetry sampling concepts, the tail sampling processor README, the OpenTelemetry metrics data model on exemplars and W3C Trace Context.
Fact-check sources from the original case, checked 27 September 2026. Each supports the claim noted beside it.
- Grafana Tempo docs: Manage trace ingestion: typical span size (~500 bytes) behind the storage sizing.
- RFC 2104: HMAC, section 3 Keys: HMAC keys must be random and periodically refreshed.
- OpenAI API docs: Deprecations: GPT-4-class list prices. A 21,384-token prompt exceeds the 8K GPT-4 context, so the 32K model's list prices of $60 per million input and $120 per million output tokens apply: 21,384 in and 1,288 out cost about $1.44.
- Ovadia et al. 2023, Fine-Tuning or Retrieval? (arXiv 2312.05934): fine-tuning is a weak way to add knowledge compared with retrieval.
- Kwon et al. 2023, Efficient Memory Management for LLM Serving with PagedAttention: continuous batching and KV-cache limits.
- vLLM docs: Optimization and Tuning: batch size, preemption and chunked prefill trade-offs.
- GDPR (Regulation 2016/679), Recital 26: pseudonymised data is still personal data.
- EDPB Guidelines 01/2025 on Pseudonymisation: keyed hashes as pseudonymisation, not anonymisation.
- GDPR Article 17: Right to erasure: deletion requests reach linked fingerprints.
- Claude docs: Prompt caching: exact prefix match; timestamps, unsorted JSON, tool changes and model swaps break the cache.
- OpenAI API docs: Prompt caching: exact prefix match and minimum cacheable length.
- OpenRouter help: Which providers stop billing when a stream is cancelled: cancelling a stream stops billing only on some providers.
- vLLM docs: OpenAI-compatible server: self-hosted engines abort generation on client disconnect.
Practice
Attempt the case before revealing the worked reasoning.
Attempt the design from a blank page
Close the walkthrough and design observability for a customer-facing AI application whose users say it is "slow and sometimes wrong". Telemetry must never store raw prompts, documents or secrets, and support may see only its own tenant. Start from the questions you would ask, write the no-capture list, draw both paths, and explain how a support agent gets from a complaint to the failing hop. Write your answer in the worksheet fields below before opening any worked answer in the next sections.
The original site links a separate "Observability for a Customer-Facing AI Application" worksheet at forwarddeployedprep.com. That worksheet was not captured or imported here; the local fields below are this casebook's own.
Work through your answer
This local worksheet is a prototype addition. Notes save in this browser. Nothing is submitted or scored.
Check your reasoning
Reveal the self-assessment rubric
This checklist is an authored addition. Assess what you can explain without reopening the walkthrough.
0 of 8 reasoning checks covered.
Check yourself
These twelve questions are the source's own self-check. Answer each aloud before opening it.
What are the three problems inside "slow and sometimes wrong"?
Latency (where in the pipeline the time goes), correctness (whether the fault is in retrieval or generation), and diagnosability (whether support can explain it without exposing content or drowning in telemetry).
Name the four things never captured by default.
Full prompts, raw customer documents, secrets, and high-cardinality free-form labels such as arbitrary user text or unbounded metadata keys.
Why must the sensitivity classifier run before storage?
Once a raw value is written, every system that reads the store has it. Classification after storage protects nothing.
Why use a keyed hash (HMAC) rather than a plain hash?
It keeps correlation and deduplication while resisting brute-force reversal of common prompts, as long as the secret key stays secret. A missing key must raise an error rather than fall back to an unkeyed hash.
Walk the "sampling drops the only bad trace" drill.
Detect by comparing complaints with sampled trace volume. Contain by raising fidelity for the affected slice. Recover from neighbouring evidence (gateway logs, model gateway errors, dependency spans, tickets) and mark the gap. Prevent with error-class overrides, exemplars and escalation hooks.
When does a failure fail closed rather than degrade?
When integrity, privacy or authorisation would be compromised: a missing auth token, an unavailable audit sink, a lookup outside tenant scope.
How do you tell a retrieval fault from a model fault?
Compare retrieved evidence with the answer. Empty, stale or off-topic evidence points upstream. Good evidence contradicted by the answer points at the model or prompt. A one-tenant failure points at configuration, access or integration state.
In the latency incident, which spans stacked up, and what was the process failure?
Retrieval 4200 ms, reranker 3100 ms, gateway queue 2800 ms and provider 9360 ms. The process failure was a canary that ran only off-peak and never tested peak GPU queue depth.
In the cost incident, why was the cost spike also a security incident?
The v5 cache key dropped role_scope, so one role's summary could be served to another whenever the query text matched.
For the inference-latency prompt, why do input and output tokens hurt in different places?
Prefill processes the prompt in parallel and sets time to first token, so input tokens hurt the first token. Decode generates one token at a time and sets total time, so output tokens hurt the tail.
What does the go/no-go gate check?
Trace coverage above the minimum for the top failure path, and telemetry overhead not moving latency.
Give the four verbs and the line for the costs-exploded drill.
Measure, route, bound, cache safely. For the drill: contain, attribute, then diagnose, keeping low-cost safe paths online; budget guardrails must exist before launch.
A changed constraint (authored addition)
The customer asks for 100% of traces kept for 90 days. How do you respond?
This question is an authored addition, not from the source. Start with the arithmetic using the case's illustrative figures: 3,000 spans a second × 500 bytes × 7,776,000 seconds in 90 days is about 11.7 TB, roughly thirty to forty times the 270 to 390 GB that 30 days of tail-biased retention needs at the same span size. Storage may still be affordable, but every span passes through the classifier, so classifier CPU and the privacy exposure of a long-lived store grow with it. Ask what the 90 days is for. If it is audit, the separate audit log already keeps access events durably. If it is incident forensics, tail-biased retention with error overrides keeps the failure population, and a longer window can apply to those traces only. Retention should follow the customer's data-processing agreement in any case.
Deliver it in fifty minutes
Spend time in proportion to risk, not diagram size. The pacing below is the source chapter's own.
A fifty-minute plan.
| Minutes | Move |
|---|---|
| 0–5 | Frame the outcome; ask what counts as slow and wrong, and who is most affected |
| 5–12 | Walk the critical path; show that "slow and sometimes wrong" is a set of failure modes |
| 12–18 | State the capture and no-capture lists: the first trade-off |
| 18–26 | Propose the tracing-first architecture and the two views |
| 26–32 | Size by collection policy; say why "what will we not collect?" comes first |
| 32–38 | Security and failure modes, each tied to a mitigation |
| 38–44 | Staged rollout, alert triggers, owners, the support workflow |
| 44–50 | Executive summary; name the riskiest assumption and the first rollout gate |
Most of the fifty minutes go to the no-capture list, the dropped-trace drill and the support test. Defend four trade-offs.
- Full capture against privacy and cost: capture structure, and keep a break-glass path.
- Head against tail sampling: prefer tail retention for slow and failed traces.
- Raw prompts against hashed metadata: store template ID, field presence, sanitised entity markers and fingerprints.
- Global dashboard against tenant views: build both, with a permission boundary.
Repair the common weak answers on the spot.
- "Log everything and sort it out later" becomes a tiered capture strategy with named privacy and cost consequences.
- "Use tracing" becomes what is traced, how context propagates and which layer each span isolates.
- "Sample 10 percent" becomes a question about the failure distribution.
- "Put it on one dashboard" becomes global health plus tenant-scoped debugging.
- "If the answer is wrong, the model is wrong" becomes a walk through auth, retrieval, prompt construction, tools and integrations.
Spoken answers to rehearse
Executive summary for the last six minutes, spoken answer example (source):
"My design goal is to connect user-visible failures to technical causes without collecting more sensitive data than we need. I would instrument the full request path with correlation IDs, structured spans, and bounded metadata across authentication, retrieval, model calls, and tools. I would store raw prompts and customer content only through a narrow, audited escalation path, because the default should be privacy-preserving and cost-aware. For debugging, I would rely on template IDs, document references, timing, error classes, and outcome labels so support can separate auth, retrieval, model, and integration problems. I'd use a global operational view plus tenant-scoped views for authorised support, and I'd prefer selective retention for slow or anomalous traces over blind random sampling so we do not lose the one bad trace. The riskiest trade-off is observability depth versus privacy and cost, and my first production rollout gate would be proving that the system can consistently identify the root cause of real customer incidents without exposing unnecessary content or overwhelming the team."
Two-minute answer, spoken answer example (source):
"I would first define what slow and wrong mean for this customer and write the no-capture list. Every request gets a correlation ID and structured spans through retrieval, model and tools, but full prompts and raw documents stay out of telemetry by default. Spans export asynchronously through redaction and bounded sampling into a retention-limited store. Global dashboards show aggregate health; authorised support gets tenant-scoped evidence, with a separate audit trail. I diagnose from the complaint down: user outcome, then the slow or failing span, then retrieval evidence versus final answer. I retain error and slow traces preferentially so the rare incident is still visible, and I prove the instrumentation itself does not hurt latency or privacy before expanding."
Sixty-second close, spoken answer example (source):
"Correlate every request, collect structured evidence without raw content, retain anomalies preferentially, and let support trace a complaint to a cause within its tenant. Prove both privacy and low overhead before widening rollout."
Gap follow-ups (V2 gap note, supplementary)
Would you build or buy the tracing stack?
Buy the span plumbing and build the redaction and classification boundary. What counts as sensitive for this tenant is business logic that no vendor can own.
A user files a deletion request under GDPR. Do hashed prompts make that trivial?
No. Hashed prompts make a deletion request smaller, not trivial. A keyed hash tied to a user is still personal data under GDPR (the EU's General Data Protection Regulation): Recital 26 treats pseudonymised data as personal data, and the EDPB's 2025 guidelines treat keyed hashes as pseudonymisation rather than anonymisation. So delete or unlink those fingerprints too, along with quarantine and break-glass records, as Article 17 requires. The retention window should follow the customer's data-processing agreement.
Level calibration
Every level traces the request; the level shows in what the answer refuses to collect and who may read what is left.
How the same answer sounds at senior, staff and principal level.
| Level | Sounds like | Missing |
|---|---|---|
| Senior | One correlation ID through auth, retrieval, model and tools, spans exported asynchronously so telemetry never blocks the user, and a classifier that redacts before storage. Diagnoses from the complaint down, splitting the latency incident into retrieval, reranker, queue and provider time. | Who may see which tenant's traces, and what happens when sampling drops the only bad trace. |
| Staff | Adds access and ownership: tenant-scoped support views, a separate durable audit log, error-class overrides and exemplars, and a four-phase rollout with named owners and a go/no-go on trace coverage and overhead. Reads the missing role_scope in the cost incident as a permission incident, not only a cost one. |
What is shared service versus per-customer configuration, and how retention and deletion requests follow each customer's agreement. |
| Principal | Splits the system into core product, shared service, adapters and configuration, so per-customer sampling, retention and thresholds stay out of the core. Buys the span plumbing but builds the redaction boundary, because what counts as sensitive is business logic, and makes cost and latency gates on prompt and route changes a rule for every team. | The real failure distribution, overhead budget and retention window, which need the customer's traffic and data-processing agreement to set. |
Answer every cost and latency pivot with a card
Each card below is a source pivot. Before revealing it, name the dominant driver, the cheapest lever, the metric that proves it, the move you would refuse and your sixty-second line, using the measure, route, bound, cache safely pattern. Every answer ends with the shared communication sentence: acknowledge impact, show measured cause, provide immediate mitigation, then explain long-term prevention and success metric.
Card 15.1: LLM costs exploded after launch.
| Card field | Answer |
|---|---|
| Dominant driver | Unknown until attributed: usually retries, agent loops, batch or eval jobs, or an integration loop |
| Cheapest lever first | Spend circuit breaker first; attribute by tenant and feature; cap output; pause batch and eval; downgrade premium routing; tenant quotas; then root cause |
| Metric that proves it | Cost per minute; tokens per request; model distribution; retry count; agent steps; tenant usage |
| Do not | Kill the whole feature without diagnosis |
| 60-second line | Contain, attribute, then diagnose. Keep low-cost safe paths online while disabling runaway paths. Budget guardrails must exist before launch. |
Card 15.2: LLM cost increased 5× after rollout.
| Card field | Answer |
|---|---|
| Dominant driver | Request shape: longer prompts, new RAG context, agent loops, eval jobs, retries, output verbosity, a provider price-tier change |
| Cheapest lever first | Cap max output length, pause expensive batch and eval jobs, route simple tasks to a smaller model, cap agent steps |
| Metric that proves it | Cost and tokens per request; requests by feature; retry count; model distribution; output tokens; eval and batch spend |
| Do not | Swap the model before breaking spend down by tenant, feature, model and prompt version |
| 60-second line | The increase likely comes from request shape rather than user count alone. I would isolate token growth, retries, agent steps, and batch jobs before changing the model. |
Card 15.3: Latency jumped from 2 seconds to 20 seconds.
| Card field | Answer |
|---|---|
| Dominant driver | A new reranker, larger context, a provider incident, cold starts, a tool timeout, or synchronous logging |
| Cheapest lever first | Roll back the prompt or reranker change, disable the optional tool, reduce top-k, activate the fallback provider |
| Metric that proves it | P95 and P99; first-token; retrieval, rerank, model and tool latency; timeout and retry rate |
| Do not | Guess, or raise the timeout |
| 60-second line | I would not guess. I would use traces to see whether the 18-second increase is retrieval, model, tool calls, or infrastructure. |
Card 15.4: Executive demo is too slow.
| Card field | Answer |
|---|---|
| Dominant driver | Unwarmed services, live external dependencies, an over-large prompt, no streaming, a poor network |
| Cheapest lever first | Warm services, pre-index documents, stream output, use a stable demo dataset, shorten the answer |
| Metric that proves it | First-token latency; retrieval and model latency; tool calls; cold-start count |
| Do not | Present demo numbers as production claims |
| 60-second line | For an executive demo, I would reduce live uncertainty while staying honest about production architecture and limitations. |
Card 15.5: Customer complains the AI is too expensive.
| Card field | Answer |
|---|---|
| Dominant driver | Premium-model overuse, verbose answers, no quotas, heavy batch jobs, low-value workflows |
| Cheapest lever first | Route simple tasks to a cheaper model, add quotas, trim prompts, cache safe repeated results |
| Metric that proves it | Cost by feature; active users; cost per outcome; model distribution; tokens per request |
| Do not | Defend the bill generically |
| 60-second line | I would not defend the bill generically. I would show cost by workflow and propose concrete reductions that preserve value. |
Card 15.6: Prompt update increased token usage.
| Card field | Answer |
|---|---|
| Dominant driver | Verbose instructions, duplicated rules, added few-shot examples, longer default output |
| Cheapest lever first | Roll back or trim the prompt; reduce examples; enforce an output max |
| Metric that proves it | Input and output tokens by prompt version; parse errors; retry count |
| Do not | Ship a prompt change without a cost-impact report |
| 60-second line | Prompt changes are production changes. I would version them and compare token usage and latency before rollout. |
Card 15.7: Model provider latency became unstable.
| Card field | Answer |
|---|---|
| Dominant driver | A provider incident, regional queueing, rate limiting, a network issue, with no deploy of ours |
| Cheapest lever first | Activate the fallback model or provider, reduce concurrency, degrade optional features |
| Metric that proves it | Provider latency by model and region; fallback rate; error codes; queue time |
| Do not | Wait blindly for the provider to recover |
| 60-second line | I would isolate provider latency from our own pipeline and use routing/fallback rules rather than waiting blindly. |
Card 15.8: Cache hit rate dropped suddenly.
| Card field | Answer |
|---|---|
| Dominant driver | A new prompt version invalidated the cache, a short TTL, changed normalisation, document churn |
| Cheapest lever first | Roll back the key change, adjust TTL, normalise queries, pre-warm a safe cache |
| Metric that proves it | Hit rate by cache type; invalidations; TTL; key cardinality; traffic mix |
| Do not | Scale capacity before inspecting the key |
| 60-second line | A cache hit drop is usually a keying, versioning, traffic, or invalidation issue; I would inspect those before scaling. |
Two facts sharpen this card (source additions file, section A1). Prompt caching is a byte-exact prefix match, so one changed byte invalidates everything after it. A timestamp in the system prompt, unsorted JSON keys, a reordered tool list or a model swap each cause a silent miss. The cost incident adds the other half: cache changes need a security review too, because a key missing role_scope serves one role's answer to another.
Card 15.9: Rate limits are throttling us at peak.
| Card field | Answer |
|---|---|
| Dominant driver | Provider 429s mixed with limits from the team's own gateway |
| Cheapest lever first | Separate the two sources; retry with jitter plus a fallback model or region; shed non-interactive traffic to batch |
| Metric that proves it | 429s by source; fallback rate; queue depth; goodput at peak |
| Do not | Retry into the same wall |
| 60-second line | Separate provider 429s from our own limits first. Short term, jitter, fall back and shed batch traffic. Long term, capacity commitments, tenant-aware quotas, and queue non-urgent work. |
Card 15.10: Streaming works but users abandon mid-answer.
| Card field | Answer |
|---|---|
| Dominant driver | Tokens generated after the user has left, plus in-flight tool calls nobody will read |
| Cheapest lever first | Cancel the stream and any in-flight tool calls on abandon |
| Metric that proves it | Abandonment against first-token time and answer length; tokens generated after abandon |
| Do not | Treat cancellation as a UX nicety only |
| 60-second line | Measure abandonment against first-token time and answer length, and cancel the stream and in-flight tool calls on abandon. Where the provider stops generating on cancel, that stops us paying for tokens nobody read. |
Return to the decisions you could not explain.
Review the essentialsQuick review
Recall the decisions, failure responses, and closing answer.
Recall the path, the rules and the incidents
Ask first. What is slow? What is wrong? Which tenants? What content is forbidden to collect? Who may diagnose? What overhead and retention are acceptable?
Whiteboard path. Request: auth/tenant → retrieval → LLM → tools → response. Spans: async collector → classify/redact/HMAC → error-and-slow-biased sampling → bounded store → global aggregate and tenant-scoped support views. Access audit is separate. Telemetry export never blocks the user.
Four rules.
- No full prompts, raw documents, secrets or unbounded labels by default.
- Redact before storage; a missing HMAC key is an error.
- Keep rare failures with error overrides, exemplars and incident sampling.
- Missing auth, cross-tenant lookup and required audit evidence fail closed.
Numbers and incidents. Illustrative sizing: 500 requests/s × six spans ≈ 3,000 raw spans/s; keep errors and slow traces plus about 5% of normal traffic; about 110–155 GB for 30 days at 200 bytes a span. The classifier, not disk, is the constraint. Latency incident: p95 22.18 s against 7 s from stacked retrieval (4.2 s), reranker (3.1 s), queue (2.8 s) and provider (9.36 s) delays; canary never tested peak. Cost incident: traffic +7%, input tokens +351%, cache 67% → 4%, routing threshold crossed; missing role_scope also risked leakage.
Diagnosis. Start at the user outcome, then stage spans. Empty or stale retrieval → upstream. Good evidence contradicted by the answer → model or prompt. One tenant → configuration, access or integration. First-token versus total time separates prompt and prefill from a long decode. A missing trace is not proof of health.
Rollout. SLOs, one critical path, the support workflow, then quality and cost signals with sampling. Go/no-go on trace coverage and overhead; roll back on lost propagation, a quality-event spike or an unsustainable cost slope.
Pivots. Measure, route, bound, cache safely. Contain, attribute, then diagnose.
Key takeaways.
- "Slow and sometimes wrong" is three problems (latency, correctness and diagnosability), each made measurable before any design.
- The first design decision is the no-capture list: full prompts, raw documents, secrets and unbounded labels stay out by default.
- Requirements are stated so a test can fail them, with the support workflow as the functional core and overhead as a budget.
- Telemetry cost is set by collection policy; the worked sizing shows storage is small and the classifier is the real constraint.
- The architecture is tracing-first, with the observability path unable to block the request path and nothing raw crossing the trust boundary.
- Classification and keyed hashing happen before storage, and three tests pin idempotency, privacy and failure visibility.
- Sampling is tail-biased with error overrides and exemplars, because uniform sampling drops the only bad trace.
- Every layer has a named failure policy, and audit evidence fails closed where user answers can degrade.
- The dashboard is built top down from the complaint, and wrong answers are triaged by comparing evidence with output.
- The latency incident was compounded latency from several small changes, found only by comparing each span with its baseline.
- The cost incident was prompt growth, a routing threshold and a broken cache key multiplying, and it hid a permission leak.
- Three practice prompts are the same traces read at different depths: the stage decomposition, the seven RAG failure classes and the inference stack.
- Rollout runs in four phases with named owners, an eight-metric scorecard, explicit go/no-go gates and a risk register.
- The fifty minutes go to the no-capture list, the dropped-trace drill and the support test.
- Every cost and latency pivot is answered with a card built from measure, route, bound and cache safely.
Sixty-second close. "Correlate every request, collect structured evidence without raw content, retain anomalies preferentially, and let support trace a complaint to a cause within its tenant. Prove both privacy and low overhead before widening rollout."