Quick revision
The short answer
We give the 40 services one paved road: a shared Spring Boot starter that talks to a central AI gateway. The gateway handles authentication, provider routing, retries, timeouts, rate limits and fallbacks; a model registry lists the approved models per data classification, region and use case; every call is logged with personal data redacted and traced with token counts through OpenTelemetry; budgets, quotas, caching and spend dashboards control cost; and provider contracts, PII scrubbing and private deployments protect data.
What to remember
In this answer, we designed an LLM platform for 40 Java services: a shared Spring Boot starter in each service and a central gateway that handles authentication, routing to logical model names, retries, timeouts, rate limits and fallbacks. A model registry approves models per data classification, region and use case. Every call is traced with token counts and latency through OpenTelemetry, and prompts and outputs are stored only with redaction and retention rules. Budgets, quotas, caching and spend dashboards control cost, and provider contracts, PII scrubbing and private deployments protect data.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We give the 40 services one paved road: a shared Spring Boot starter that talks to a central AI gateway. The gateway handles authentication, provider routing, retries, timeouts, rate limits and fallbacks; a model registry lists the approved models per data classification, region and use case; every call is logged with personal data redacted and traced with token counts through OpenTelemetry; budgets, quotas, caching and spend dashboards control cost; and provider contracts, PII scrubbing and private deployments protect data.
Why this question is asked
When the first two teams in a company use an LLM, each writes its own client, stores its own API key and picks a model it likes. By the time forty services do the same, nobody knows what the company spends, which customer data went to which provider, or what happens when a provider has an outage. Interviewers ask this design question at the senior level to see whether we can build a shared platform that makes the safe way the easy way, without slowing teams down. In this answer, we will lay out the architecture, then go through the gateway, the model registry, logging and tracing, cost control and data protection, with the reason for each part.
1The Shape of the Platform
There are two common ways to centralise LLM access: a shared client library inside each service, or a network gateway that all calls pass through. A library is simple and adds no network hop, but every change needs forty redeployments and the company cannot enforce anything centrally. A gateway can enforce policy, hold the provider keys and see all traffic, but it is one more service to run. For forty services the usual answer is both: a thin shared starter that makes calling the gateway trivial, and the gateway that does the real work.
The starter is a Spring Boot auto-configuration module that configures Spring AI's ChatClient to point at the gateway, adds the service's identity and a feature name to every call, and sets timeouts and tracing. Teams add one dependency and get the whole platform.
- Service codeuses
ChatClientor an internal interface, names its feature - Shared startergateway URL, service identity, timeouts, tracing, redaction hooks
- AI gatewayauth, routing, retries, rate limits, fallbacks, budgets, logging
- Model registryapproved models per data class, region and use case
- Providershosted APIs, private cloud deployments, self-hosted models
5 layers, from the top down. Step through them one at a time.
Teams depend on the starter; policy lives in the gateway and the registry.
2The Gateway: One Place for Routing and Resilience
Every call goes to the gateway with the calling service's identity, for example a workload token from the service mesh or an OAuth client credential. The gateway, not the service, holds the provider API keys, so keys are never copied into forty configurations. It maps a logical model name such as summary-standard to a real provider and model version, which means we can switch providers without touching services.
The gateway also owns resilience. It applies timeouts suited to LLM calls (a first-token timeout of around 10 seconds and a longer total timeout for streams), retries only on safe errors such as rate limits and server errors with exponential backoff, and falls back to a second approved model when the primary provider is down or saturated. It enforces per-team rate limits so one batch job cannot use up the company's quota at the provider. Open-source and commercial LLM gateways exist, and some teams build a small Spring Cloud Gateway or plain Spring service for this; the design matters more than the product.
3The Model Registry: No Ad Hoc Model Choices
Teams should not pick models from a provider's website. The registry is a small, versioned catalogue that says which models are approved, for which data classification (public, internal, confidential, personal data), in which regions, for which use cases, and at what cost tier. The gateway reads it on every request: if a service tagged as handling personal data asks for a model only approved for public data, the gateway refuses.
This turns model choice into a reviewed decision. When a new model appears, the platform team evaluates it on shared benchmark tasks, checks the provider's terms, and adds it to the registry with its approvals. Teams then choose among approved options by logical name.
| Logical name | Provider and version | Max data class | Region | Use |
|---|---|---|---|---|
| chat-standard | provider A, dated version | confidential | EU, US | general chat, summaries |
| chat-small | provider B, dated version | internal | US | classification, extraction |
| chat-private | self-hosted open-weight model | personal data | own data centre | sensitive documents |
| embed-standard | provider A embeddings | confidential | EU, US | RAG indexing |
4Logging and Tracing Every Call
We need two kinds of records. Traces and metrics, which every call produces, carry the service, feature, logical and real model, input and output token counts, latency to first token, total latency and outcome. We emit them with OpenTelemetry, which has semantic conventions for generative AI calls (attributes such as the token usage counts; check the current version of the conventions), and Spring AI's Micrometer observations can feed the same pipeline. Dashboards then show latency and errors per feature.
Prompts and outputs are the second kind, and they are sensitive. Storing them is valuable for debugging and evaluation, but they often contain customer data. So the gateway redacts personal data (emails, phone numbers, account numbers) before storing, keeps the content in a separate store with access limited to the owning team, and applies retention rules, for example 30 days for full content and longer for metadata only. Some features, such as HR, may store no content at all.
5Controlling Cost
Without controls, LLM spend grows quietly until the monthly invoice arrives. Because every call passes through the gateway with a service and feature name, we can show spend per team and per feature on a dashboard updated hourly, which is often enough to change behaviour. On top of that we give each team a monthly budget with alerts at 50, 80 and 100 percent, and hard quotas in tokens per minute so a runaway loop is stopped in minutes, not days.
The gateway can also reduce spend directly. It can cache responses for identical requests where that is safe, such as embeddings of the same text, and route simple tasks to a cheaper model tier. Provider prompt caching and batch APIs are enabled centrally where available, so every team benefits without learning each provider's details.
6Protecting Data
Data protection starts with contracts. Before a provider enters the registry, legal and security confirm that our data is not used for training, how long the provider retains it, where it is processed and how incidents are reported. The registry then encodes those terms as data classes and regions. In the request path, the gateway scrubs or masks personal data the use case does not need, for example replacing names with placeholders before summarisation and restoring them afterwards when necessary.
For data that must not leave our control at all, such as health or regulated financial data, the registry offers private deployments: a model hosted in our own cloud account or data centre. Services use the same starter and the same logical names, so moving a feature from a public provider to a private model is a registry change, not a code change.
7Follow-up questions
Should the gateway also do prompt-injection filtering?
It can run shared input and output filters, for example detecting obvious injection patterns or blocking secrets in outputs, and that is a useful baseline. But filtering cannot be the main defence, because the gateway does not know what each feature's tools are allowed to do. Authorization of actions has to stay in the service that owns them.
What about latency added by the gateway?
A well-placed gateway adds a few milliseconds per call, which is negligible next to LLM latencies of hundreds of milliseconds to seconds. Streaming must be passed through without buffering, or users lose the benefit of seeing tokens early.
How do you get forty teams to adopt it?
Make it the easiest path: one dependency, working examples, keys they no longer have to manage, dashboards they get for free. Then make direct provider access the hard path by not issuing provider keys to teams and blocking provider endpoints at the network egress.
8Conclusion
In this answer, we designed an LLM platform for 40 Java services: a shared Spring Boot starter in each service and a central gateway that handles authentication, routing to logical model names, retries, timeouts, rate limits and fallbacks. A model registry approves models per data classification, region and use case. Every call is traced with token counts and latency through OpenTelemetry, and prompts and outputs are stored only with redaction and retention rules. Budgets, quotas, caching and spend dashboards control cost, and provider contracts, PII scrubbing and private deployments protect data.
Open with
I would build a paved road with two parts. Each service gets a shared Spring Boot starter that configures Spring AI to call our AI gateway, adds the service identity and a feature name to every call, and sets timeouts and tracing.
Then, if they want more
The gateway holds the provider keys and does authentication, routing from logical model names to real providers and versions, retries with backoff on rate limits and server errors, per-team rate limits and fallback to a second approved model during outages.
Next to it is a model registry that lists approved models per data classification, region and use case, and the gateway refuses a request when the service's data class is higher than the model's approval.
Every call produces an OpenTelemetry trace with service, feature, model, input and output tokens and latency, so we have dashboards per feature; prompt and output content is stored separately, with personal data redacted, access limited to the owning team, and a retention period.
For cost, spend per team and feature is visible daily, teams have budgets with alerts and hard token quotas, and the gateway enables caching and batch APIs centrally.
For data protection, providers enter the registry only after contracts confirm no training on our data and acceptable retention and regions; the gateway scrubs PII where it is not needed, and sensitive use cases go to private deployments behind the same logical names.
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 "Your company wants a standard way for 40 Java services to use LLMs. Design the platform...": https://scrivio-interview-library.netlify.app/spring-boot/llm-fundamentals/09de25bb29/