Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

Leadership asks for monthly reporting of AI cost, quality and incidents across 20 services using Spring AI. Design the telemetry and the reporting pipeline.

A shared starter gives all 20 services the same tags (service, feature, tenant, model, provider, prompt version) on Spring AI's metrics and traces, and enforces them so every token can be attributed. Metrics cover tokens and cost, latency, errors and fallbacks; traces allow drill-down; sampled, redacted payloads go to a restricted store for quality review; quality signals come from user feedback, evaluation scores and escalation rates. Metrics flow to the observability backend, aggregated cost goes to a warehouse and is reconciled with provider invoices, and alerts fire on cost anomalies and on quality drops after prompt or model changes.

Why this question is asked

Once AI features are in production across many services, leadership asks three questions every month: what did it cost, is it any good, and what went wrong. If each service reports differently, answering takes a week of spreadsheet work and the numbers still do not add up to the invoice. Interviewers ask this question to see whether we can design telemetry as a product, with consistent data from the source to the report. In this answer, we will standardise the tags, choose the metrics, traces and payload samples, define the quality signals, build the reporting pipeline with reconciliation, and add alerts.

1Start With Common Tags From a Shared Starter

Spring AI already emits Micrometer observations for chat, embedding, tool and vector store calls, tagged with provider, model and token type. What it cannot know is our business context. So a shared Spring Boot starter, used by all 20 services, adds the same tags to every AI observation: service, feature, tenant, model, provider and prompt version. The prompt version matters as much as the model, because many quality changes come from prompt edits.

Java
@Bean
ObservationFilter aiBusinessTags(AiCallContext ctx) { // ctx is filled per request by the starter
return context -> {
if (context.getName().startsWith("gen_ai")) { // observation names: check your version
context.addLowCardinalityKeyValue(KeyValue.of("service", ctx.service()));
context.addLowCardinalityKeyValue(KeyValue.of("feature", ctx.feature()));
context.addLowCardinalityKeyValue(KeyValue.of("tenant", ctx.tenant()));
context.addLowCardinalityKeyValue(KeyValue.of("prompt_version", ctx.promptVersion()));
}
return context;
};
}
// gen_ai_client_token_usage_total{service="claims",feature="summary",tenant="acme",
// gen_ai_request_model="...",prompt_version="v7",gen_ai_token_type="input"} 1.2E7

Enforcement is what makes the tags reliable. The starter fails the call, or at least counts it as untagged, if feature or prompt version is missing, and the monthly report shows the share of untagged spend per service. Without enforcement, untagged calls quietly become a large unexplained line in the report.

2Metrics, Traces and Sampled Payloads

Three kinds of telemetry serve three purposes. Metrics are cheap aggregates for dashboards and reports: tokens and estimated cost per feature, latency percentiles, error rates by type, fallback rates. Traces let an engineer drill into one slow or failing request and see retrieval, model calls and tool calls in order. Payloads, the actual prompts and answers, are what quality reviewers need, but they contain personal data, so we never log them all.

Instead, the starter samples a small share of calls, say 1 percent, redacts personal data, and writes them to a restricted store with access limited to the quality team and retention of 30 to 90 days. That gives reviewers real examples without copying every conversation into general logs.

Step throughTelemetry from service to report
  1. 20 services with the shared startercommon tags on every AI call
  2. Metrics and traces backenddashboards, drill-down, alerts
  3. Restricted payload store1 percent sample, redacted
  4. Cost warehousedaily aggregates per feature and tenant
  5. Invoice reconciliationestimated cost vs provider invoices
  6. Monthly reportcost, quality, incidents

6 layers, from the top down. Step through them one at a time.

3Quality Signals

Cost and latency are easy to measure; quality is the hard part, and leadership needs it most. We combine three kinds of signals. User feedback: thumbs up or down and comments, recorded with the same tags so we can see feedback per feature and prompt version. Evaluation scores: offline evaluations run against a fixed test set whenever a prompt or model changes, and online evaluations that grade a sample of real answers automatically, for example checking that answers cite the retrieved documents. Escalation rates: how often a conversation ends with a handover to a human or a repeat contact, which is often the most honest quality signal for support features.

None of these is perfect alone. Feedback is sparse and biased towards unhappy users, and automatic grading has its own errors. Together, tracked as trends per feature, they show whether quality is holding.

4The Reporting Pipeline and Reconciliation

Metrics backends are good for recent data and dashboards but awkward for monthly finance reports. So a daily job reads token metrics aggregated by feature, tenant, model and provider, multiplies by a price table, and writes the result to the data warehouse. The monthly report is built there.

Estimated cost will never exactly match the invoice: providers count tokens in their own way, some calls bypass the starter, prompt caching discounts or batch prices apply, and prices change mid-month. So we load the provider invoices, or their usage exports, into the same warehouse and reconcile per provider and model. A difference of 2 percent is normal; a difference of 15 percent means untagged calls or a wrong price table, and we investigate before publishing.

SQL
-- Monthly reconciliation per provider and model (warehouse)
SELECT e.provider, e.model,
round(sum(e.estimated_cost), 2) AS estimated,
i.invoiced,
round(100 * (i.invoiced - sum(e.estimated_cost)) / i.invoiced, 1) AS gap_pct
FROM ai_cost_daily e
JOIN provider_invoice i USING (provider, model, month)
WHERE e.month = '2026-10'
GROUP BY e.provider, e.model, i.invoiced;
-- provider_a large-model 41210.55 42010.00 1.9
-- provider_a small-model 3120.40 3690.00 15.4 <- investigate: untagged calls?

5Alerts on Cost Anomalies and Quality Regressions

Monthly reports are too slow to catch problems, so alerts run continuously. Cost alerts compare each feature's hourly or daily spend with its recent baseline and fire on large deviations, for example spend above three times the same hour last week, which catches loops and runaway jobs. Quality alerts are tied to change events: when a new prompt version or model goes live, we compare its feedback, evaluation scores and escalation rate with the previous version over the next day, and alert if it is clearly worse. Because every metric carries the prompt version tag, this comparison is a query rather than an investigation.

Step throughAfter a prompt or model change
  1. Deploy prompt v8 to 10 percenttagged prompt_version=v8
  2. Compare v8 with v7 for 24 hoursfeedback, eval score, escalations, cost
  3. Clearly worse on any signal?
    YesAlert and roll back to v7NoRoll out to 100 percent

3 steps in order. Play them, or step through them one at a time.

6What the Monthly Report Shows

The report has three parts. Cost: total by provider, by service and by feature, trend over the last six months, cost per unit of value where features have one (cost per resolved ticket), and the reconciliation gap. Quality: feedback, evaluation and escalation trends per feature, and the changes made that month with their measured effect. Incidents: outages, degraded periods and fallbacks, with user impact and follow-up actions. Because the data is consistent across all 20 services, the report can be produced automatically, and the human time goes into explaining the changes rather than collecting numbers.

7Follow-up questions

How would you attribute cost for shared retrieval infrastructure?

Measure usage per consumer and allocate the shared cost in proportion. The vector database and embedding pipeline serve many features, so we tag queries and ingestion jobs with feature and tenant, then split the monthly infrastructure cost by share of queries, or of stored vectors for storage-heavy costs. Embedding calls are attributed directly like chat calls. The allocation rule is published so teams understand and accept their share.

Why not take cost straight from the provider invoice?

Invoices show totals per account and model, not per feature or tenant. They are the truth for totals, so we reconcile against them, but attribution must come from our own tagged telemetry.

How do you keep tag cardinality under control?

Use bounded values: feature names from a registry, tenant ids for a moderate number of tenants, and versions. User and conversation ids go into traces and payload samples, not metric tags.

8Conclusion

In this answer, we designed telemetry for 20 services around a shared starter that adds and enforces common tags on Spring AI's observations. Metrics give cost, latency, errors and fallbacks, traces give drill-down, and sampled redacted payloads in a restricted store support quality review alongside feedback, evaluation scores and escalation rates. A daily pipeline moves aggregated cost to a warehouse and reconciles it with provider invoices, and alerts catch cost anomalies and quality regressions after changes, so the monthly report is consistent and largely automatic.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start with consistency: a shared starter used by all 20 services that adds the same tags to Spring AI's Micrometer observations, service, feature, tenant, model, provider and prompt version, and enforces them, with untagged spend reported as its own line.

Then, if they want more

From that I get metrics for tokens and estimated cost per feature, latency, error and fallback rates, and traces for drill-down. For quality review I sample about 1 percent of payloads, redact them and store them in a restricted store with short retention, never in general logs.

Quality signals are user feedback, offline evaluation scores on every prompt or model change, online grading of sampled answers, and escalation rates to humans.

For reporting, a daily job aggregates token metrics, applies a price table and writes cost to the warehouse, where I reconcile it with provider invoices; a small gap is normal, a large one means untagged calls or wrong prices. Continuous alerts catch cost anomalies against a baseline and quality regressions after prompt or model changes, compared by prompt version.

Then the monthly report on cost, quality and incidents is generated from consistent data instead of assembled by hand.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring AI reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Leadership asks for monthly reporting of AI cost, quality and incidents across 20...": https://scrivio-interview-library.netlify.app/spring-boot/spring-ai/6ebfce7888/