Home / AI Architecture & System Design / AI System Design
What would you log for an LLM request, and what would you avoid logging?
30-second answer
Log model and version, prompt template version, token counts, latency breakdown, retrieved document IDs, tool calls, guardrail decisions, cost, errors and feedback, with a trace ID. Avoid storing raw PII and secrets; redact or tokenize sensitive fields, restrict access, and apply retention limits consistent with privacy commitments.
Try answering out loud before reading on. The walkthrough below is paced for a 40-minute interview round.
New to these terms? 11 terms on this page are explained in the glossary
0–5 min Functional requirements
"What would you log?" turns into a design question once you ask who uses the data and what rules apply to it.
You Is this for one feature or a platform used by many teams?
Interviewer A platform. About ten LLM features across the company: chat, search, summarization, an agent.
You Who needs the data? Engineers debugging, finance tracking cost, safety teams, auditors?
Interviewer All of those.
You What privacy rules apply? Do user messages contain personal data?
Interviewer Yes, often. We're under GDPR, and some enterprise customers forbid us storing their prompts at all.
You Do you want logs to feed evaluation, turning real failures into test cases?
Interviewer Yes, that's a big reason for doing this.
| # | Functional requirement | Why it matters |
|---|---|---|
| F1 | A trace per request linking every step: retrieval, model calls, tools, guardrails | Debug "why was this answer bad?" end to end |
| F2 | Token, cost and latency attribution by feature, tenant, model and prompt version | Cost control and regression detection |
| F3 | Quality and safety signals on traces: feedback, guardrail decisions, evaluation scores | Connect behaviour to outcomes |
| F4 | Privacy controls: redaction, per-tenant content opt-out, retention tiers, access control, deletion on request | Legal and contractual obligations |
| F5 | Turn selected traces into evaluation cases | Close the loop from production to tests |
| F6 | Dashboards and alerts | Know about problems before users report them |
5–10 min Non-functional requirements and estimates
You One firm rule: observability must never break or slow down the product. Logging is asynchronous, and if the pipeline is down, requests still succeed.
Interviewer Agreed.
| Requirement | Target | What it forces in the design |
|---|---|---|
| Overhead | ≤ 5 ms added per request; never blocks | Async SDK with local buffering; drop on overflow |
| Ingestion | ~20,000 spans/s at peak | Streaming pipeline (collector → queue → stores) |
| Privacy | No raw PII in metadata stores; content only where allowed | Redaction before storage; per-tenant content policy |
| Retention | Metrics 13 months; traces 30 days; content 7–30 days, sampled | Tiered storage |
| Deletion | User data deleted within 30 days of a request | Index content by pseudonymous user ID |
| Query speed | Dashboards < 2 s; single-trace lookup < 1 s | Column store for analytics, key lookup for traces |
Back-of-envelope estimates:
- Traffic: ~50M LLM requests/day (~600/s average, ~2,000/s peak).
- Spans: ~10 spans per request → 500M spans/day, ~20,000/s at peak.
- Metadata: ~500 bytes per span → ~250 GB/day, ~7.5 TB over 30 days before compression (columnar compression typically cuts this several-fold).
- Content: storing full prompts and responses for a 5% sample at ~8 KB each → 2.5M × 8 KB ≈ 20 GB/day. Storing everything would be ~400 GB/day of sensitive data, which is a liability as well as a cost.
- Metrics: pre-aggregated per minute by feature, model and tenant; small.
10–18 min High-level design
You Instrument the apps with a tracing SDK, redact before anything leaves the service boundary, then split data into three stores with different retention and access rules.
Scroll sideways to see the whole diagram.
Components:
- Tracing SDK in every LLM service: creates spans with standard attributes, propagates the trace ID, buffers and sends asynchronously.
- Redaction: PII and secret detectors run in the SDK or a sidecar, so raw values never reach the pipeline. Identifiers are replaced with consistent tokens (the same email always maps to the same token), so debugging still works.
- Collector (OpenTelemetry-compatible): batches, samples and routes data.
- Metrics store: aggregated counters and histograms for dashboards and alerts.
- Trace store: sanitized spans for 30 days, searchable by trace ID, feature, model and prompt version.
- Content store: encrypted, restricted, sampled full prompts and responses with short retention, only for tenants that allow it.
- Evaluation pipeline: turns flagged traces into eval cases after review.
Span attributes (the data model):
common: trace_id, span_id, parent_id, feature, tenant_id, user_pseudo_id,
env, region, start, duration_ms, status
llm.call: provider, model, model_version, prompt_template_id, prompt_version,
input_tokens, cached_input_tokens, output_tokens, cost_usd,
ttft_ms, stop_reason, temperature
retrieval: query_hash, index, k, doc_ids[], scores[]
tool.call: tool_name, args_redacted, result_size, status
guardrail: policy_version, categories[], action
feedback: rating, comment_redacted (linked by trace_id)
How it works: a worked example
A study aid: one request traced from the SDK to the three stores, then used to debug a real complaint.
The request. A user asks the support assistant a question. The service's tracing SDK records spans as the request runs:
trace 4f9a2c… feature=support_assistant tenant=acme user_pseudo_id=u_7f3e (pseudonymous)
├─ request 1,920 ms status=ok
│ ├─ guardrail.input 18 ms policy_version=12 action=allow
│ ├─ retrieval 210 ms index=help_en k=50 doc_ids=[kb-1182#3, kb-1182#1, …]
│ ├─ rerank 110 ms in=50 out=4
│ ├─ llm.call 1,480 ms model=large-v5 prompt_version=support_v14
│ │ input_tokens=4,180 cached=1,500 output_tokens=140
│ │ ttft_ms=820 cost_usd=0.0106 stop_reason=end_turn
│ └─ guardrail.output 60 ms groundedness=pass
└─ feedback (later) rating=thumbs_down comment="wrong price"
On its way to storage:
- Redaction in the SDK: the user's message contained
jane.doe@example.comand an order number; both become stable tokens (<EMAIL_1a2b>,<ORDER_9c8d>) before anything leaves the service. The same email always maps to the same token, so you can still follow one user's journey. - Collector: batches spans, keeps 100% of metadata, and keeps full prompt/response content for a 5% sample plus every trace with an error or negative feedback (tail-based sampling: the decision is made after the trace finishes).
- Three stores:
- Metrics store: increments per-minute counters (requests, tokens, cost, latency histograms) by feature, model and prompt version.
- Trace store: the sanitized span tree above, searchable for 30 days.
- Content store: this trace's full prompt and answer, because it got a thumbs-down; encrypted, access-logged, deleted after 30 days.
Debugging the complaint. Support forwards "the bot told me the wrong price". An engineer searches the trace store for feature=support_assistant rating=thumbs_down last 24h, opens this trace, and sees that the retrieved chunk kb-1182#3 is from an article updated that morning but the answer cites last month's price. Content store shows the price came from conversation history, not the docs. Fix: a prompt change telling the model to prefer documents over earlier turns, plus this trace added to the golden set via the evaluation pipeline.
Where each piece runs:
| Component | Runs as | Example technology | Sizing | If it fails |
|---|---|---|---|---|
| SDK | Library in every service | OpenTelemetry SDK + redaction plugin | < 5 ms overhead; local buffer | Drops spans on overflow; requests unaffected |
| Collector | Horizontally scaled agents | OpenTelemetry Collector | ~20k spans/s peak | Buffer to disk; backpressure drops lowest-priority data first |
| Queue | Durable log | Kafka | ~250 GB/day metadata | Retains days of data for replay |
| Metrics store | Time-series DB | Prometheus/Mimir, Datadog | Small (pre-aggregated) | Dashboards stale; alerts fall back to logs |
| Trace store | Columnar/trace DB | ClickHouse, Tempo, a vendor | ~7.5 TB raw per 30 days, compressed several-fold | Recent traces only |
| Content store | Encrypted object store + index | S3 with KMS, per-tenant keys | ~20 GB/day sampled | Content unavailable; metadata still works |
18–32 min Deep dive
You I'd go into the trace structure, the privacy pipeline, cost attribution and alerting, and closing the loop to evaluations.
Interviewer Show me what a trace looks like for a typical request.
Deep dive 1 · Traces and spans
Scroll sideways to see the whole diagram.
- One trace per user request, with child spans for each step. Agent runs get a span per iteration, so loops are visible.
- Prompt version on every LLM span. Most regressions come from prompt or model changes; without versions, you can't compare before and after.
- Retrieved document IDs and scores, not their text. They're enough to see whether retrieval failed, without copying content into logs.
- Conversation ID links traces across turns; user pseudonym links them to feedback and deletion requests.
- Standard naming (OpenTelemetry's generative-AI conventions where possible) so any backend can read the data.
Interviewer How do you make sure personal data doesn't end up everywhere?
Deep dive 2 · The privacy pipeline
- Redact at the source. Detectors for emails, phone numbers, card numbers, API keys and names run before export. Replace values with consistent tokens such as
<EMAIL_7f3a>so you can still see that two turns mention the same address. - Metadata stores never hold raw text. Prompts and responses go only to the content store, and only when the tenant allows it.
- Per-tenant policy: "no content", "sampled content" or "full content for debugging windows"; enforced in the collector.
- Access control: content access is role-based, time-limited and audited. Engineers request access to a specific trace for a specific incident.
- Deletion: index content and traces by
user_pseudo_id; a deletion request removes them from every store, and from any evaluation dataset derived from them. - Provider settings: use zero-data-retention options with model providers where contracts require it; logs on your side don't help if the provider keeps the prompts.
Deep dive 3 · Cost attribution and alerting
- Cost per request is computed at the span: tokens × the model's price, with cached input tokens priced separately.
- Roll-ups by feature, tenant, model and prompt version, daily and per minute.
- Alerts:
- cost per request up > 30% day over day for a feature (often a prompt change or an agent loop),
- p95 latency per span above budget,
- error and fallback rates per provider,
- guardrail block rate spikes per tenant,
- thumbs-down rate rising for a prompt version.
- Budgets: per-tenant and per-feature token budgets with soft and hard limits.
Deep dive 4 · Closing the loop
Scroll sideways to see the whole diagram.
Thumbs-down, guardrail hits and judge failures flag traces. Someone triages them weekly: is it retrieval, prompt or model? Confirmed failures become redacted evaluation cases, and the evaluation suite runs in CI on every prompt or model change. This is how logging improves the product rather than just filling storage.
32–37 min Trade-offs
| Decision | Chosen | Alternative | Why |
|---|---|---|---|
| Content logging | Sampled, restricted, per-tenant opt-in | Log everything | Privacy risk and cost; metadata answers most questions |
| Redaction point | In the service, before export | In the warehouse | Raw PII never leaves the service boundary |
| Metadata | 100% of requests | Sample everything | Cost and latency analysis need complete data |
| Export | Async with drop-on-overflow | Synchronous | Observability must never break the product |
| Format | OpenTelemetry-compatible | Vendor-specific | Swap backends without re-instrumenting |
| Retrieval logging | Doc IDs and scores | Full chunk text | Enough to debug; avoids copying content |
Build first: the SDK with trace IDs, model and prompt versions, tokens and cost; redaction; dashboards. Then the sampled content store with access controls, then the evaluation feedback loop.
37–40 min Wrap-up and likely follow-ups
Close with: "Every request gets a trace with spans for retrieval, model calls, tools and guardrails, carrying model and prompt versions, tokens, cost and latency. Redaction happens before export. Metadata is kept for all traffic, while content is sampled, restricted and opt-in per tenant. Alerts watch cost, latency and quality per feature, and confirmed failures become evaluation cases."
Likely follow-ups:
- How do you debug a bad answer for a tenant that forbids content logging? Use metadata (retrieved doc IDs, versions, scores) and reproduce with the customer's consent in a time-limited debugging window.
- How do you detect quality regressions without labels? Sample traffic for automated judging, watch feedback and rephrasing rates per prompt version, and compare against the previous version.
- Build or buy? Many LLM observability tools exist; the data model and privacy rules matter more than the tool. Make sure it supports your redaction and retention requirements.
What interviewers listen for
- Trace structure with model and prompt versions, tokens and cost.
- Privacy designed in: redaction at source, tiers, access control, deletion.
- Observability that can't break or slow the product.
- Using logs to create evaluation cases.
Red flags
- Logging raw prompts and responses forever "just in case".
- No prompt or model versions in logs.
- Synchronous logging on the request path.
Discussion
Help us improve our content — give feedback. Spotted an error, have a better explanation, or got asked a follow-up in a real interview? Share it here.