ai

AI Interview interview questions

Discuss request batching, async processing with queues, horizontal scaling of stateless inference workers, model caching, and back-pressure handling. Mention monitoring latency percentiles and cost trade-offs.

Spring Boot

The usual approach is to expose a plain REST endpoint that accepts the input the model needs and returns its prediction as JSON, the same shape as any other Spring Boot controller. If the model is written in a Java-compatible format, it can be loaded directly into the application and run inference in the same process; otherwise the typical pattern is calling out to a separate model-serving process over the network, keeping the heavy machine learning runtime isolated from the main application.

Beyond the basic endpoint, production-grade serving adds several layers: validate incoming input so malformed requests fail fast with a clear error instead of confusing the model, batch multiple requests together where possible to use the hardware more efficiently, set a timeout with a sensible fallback for calls to an external model service so one slow request does not stall everything behind it, and cache results for repeated identical inputs. Monitoring should track latency percentiles such as the 95th or 99th, not just the average, because a small number of very slow requests is what users actually notice.

Spring Boot

Start by keeping the serving layer stateless, meaning any instance can handle any request without needing data left over from a previous one, since this is what allows scaling horizontally by simply adding more instances behind a load balancer as traffic grows. From there, batching incoming requests together before sending them to the model makes far more efficient use of accelerator hardware such as GPUs than handling requests one at a time.

A queue in front of the inference workers absorbs sudden traffic spikes instead of overwhelming them directly, and applying back-pressure, meaning rejecting or delaying new requests once the queue grows too long, protects the system from collapsing under overload rather than serving everyone slowly. Caching frequent or repeated inputs avoids recomputation entirely for the cases where it applies. Throughout all of this, tail latency, the slowest handful of requests out of every hundred or thousand, matters more than the average, since average latency can look perfectly healthy while a meaningful share of real users experience a slow, frustrating response.

Spring Boot

Training is the process of building a model from historical data, and it is a heavy, resource-intensive job that typically runs occasionally, as a batch process that might take hours or days, often on specialised hardware. Inference is the process of using an already-trained model to answer a new request, and it needs to be fast, predictable and available essentially all the time, since a user or another service is waiting on the response.

Because these two workloads have such different characteristics, one occasional and heavy, the other constant and latency-sensitive, they are usually run on separate infrastructure. Training pipelines can be scheduled and scaled up temporarily without affecting anything else, while the inference path is optimised specifically for low latency and high availability, often with its own scaling rules, caching and monitoring distinct from the training system. Mixing the two on the same infrastructure tends to make both slower and harder to operate reliably.

Spring Boot

The general strategy is to add guardrails around the model rather than trusting its raw output directly. On the way in, validate and clean inputs so obviously malformed or malicious requests never reach the model. On the way out, check the output against a set of rules or a separate safety classifier before it reaches the user, and fall back to a safe, generic response whenever confidence in the result is low or a check fails.

Just as important is what happens after deployment: log both inputs and outputs so problematic cases can be reviewed later, give users an easy way to report a bad result, and monitor output quality continuously rather than assuming a model that tested well stays reliable forever. Real-world inputs drift over time, so a guardrail and monitoring system that catches degradation early is what actually keeps an AI feature safe in production, not just careful testing before launch.

Spring Boot

This situation is most commonly caused by data drift, where the real inputs a model sees in production gradually differ from the data it was trained and tested on, so its learned patterns stop matching reality as well as they once did. The first useful step is comparing the statistical distribution of live inputs against the original training data to confirm drift is actually the cause rather than a bug in the serving code.

Once drift is confirmed, add ongoing monitoring on prediction quality itself, not just system metrics like latency, and build a feedback loop that collects freshly labelled examples from real usage. Retraining or fine-tuning the model on this recent data usually restores performance closer to what was seen in testing. Before fully switching traffic to a retrained version, a shadow deployment, where the new model receives a copy of live traffic and its predictions are logged but not actually used, allows improvement to be validated safely without risking user-facing quality in the meantime.

Spring Boot