Scrivio Interview library
DesignIntermediate6 min read · updated 12 November 2026

An AI-powered support assistant must stay usable when the model provider has an outage or rate limits during peak hours. Design the error handling and degradation strategy.

We classify errors into transient (timeouts, 429, 5xx), permanent (invalid request, context too long, content policy) and partial (truncated or invalid structured output), and retry only transient ones with backoff inside a total time budget, with a circuit breaker per provider to fail fast. When the primary path fails, we step down a ladder of fallbacks: a secondary provider or smaller model, cached answers for frequent questions, search results without generation, and handover to a human agent. Non-interactive work is queued for later, the UI says clearly when the assistant is degraded, and we measure how many requests each path serves.

Why this question is asked

A support assistant that disappears during a provider outage is worse than no assistant, because customers have learned to rely on it and the human agents were staffed assuming it would take part of the load. Outages and rate limits are not rare events either; they cluster at peak hours, exactly when the assistant matters most. Interviewers ask this question to see whether we design for failure as a normal state. In this answer, we will classify errors, set retries and circuit breakers, build the fallback ladder, move background work to queues, and show and measure the degraded mode.

1Classify the Errors First

Every response to a failure depends on knowing what kind of failure it is. Transient errors are temporary and may succeed on another try: timeouts, HTTP 429 rate limits, 502, 503 and other server errors. Permanent errors will fail the same way every time: an invalid request, a context that is too long, an authentication problem, or a content policy refusal. Partial failures return something, but not something usable: an answer truncated by the token limit, or structured output that does not parse.

Each class has a different response. Transient errors get a retry or a fallback. Permanent errors are never retried as they are; they need a changed request, a clear message or an alert. Partial failures get one repair attempt, for example a retry with the parse error or a higher token limit, and then follow the fallback path.

Error classes and responses
ClassExamplesResponse
Transienttimeout, 429, 502, 503retry within budget, then fallback
Permanentinvalid request, context too longno retry; fix input or clear message
Permanentcontent policy refusalno retry; safe reply or human
Partialtruncated answer, invalid JSONone repair attempt, then fallback

2Retries Within a Budget, and a Circuit Breaker

Retries help with short glitches, but each retry makes the user wait and adds load to a provider that is already struggling. So retries for interactive requests are limited by a total time budget, for example 8 seconds for the whole answer, including all attempts and the fallback. One retry with backoff and jitter usually fits; more do not.

During a real outage, even one retry per request is waste. A circuit breaker per provider watches the failure rate; when, say, more than half of calls fail within 30 seconds, it opens and all calls skip that provider immediately and go to the fallback. After a cool-down it lets a few trial calls through and closes again if they succeed. The circuit turns a 30-second wait per request into an instant switch.

Properties
resilience4j.circuitbreaker.instances.primaryLlm.failure-rate-threshold=50
resilience4j.circuitbreaker.instances.primaryLlm.sliding-window-type=TIME_BASED
resilience4j.circuitbreaker.instances.primaryLlm.sliding-window-size=30 # seconds
resilience4j.circuitbreaker.instances.primaryLlm.wait-duration-in-open-state=20s
resilience4j.circuitbreaker.instances.primaryLlm.permitted-number-of-calls-in-half-open-state=5
resilience4j.circuitbreaker.instances.primaryLlm.ignore-exceptions=org.springframework.ai.retry.NonTransientAiException
# a permanent error is the request's fault, not the provider's, so it does not open the circuit

Notice the last setting. A context-too-long error says nothing about the provider's health, so it must not count towards opening the circuit.

3The Fallback Ladder

When the primary model cannot answer, we try a sequence of cheaper or simpler options, each still useful to the customer. First, a secondary provider or a smaller model, approved for the same data, which can answer most questions slightly less well. Second, cached answers: support traffic is repetitive, and the top few hundred questions often cover a large share of volume, so curated or previously generated answers can be served without any model. Third, search without generation: run the retrieval step and show the most relevant help articles, which needs only the vector store. Finally, handover to a human agent, with the conversation so far attached so the customer does not repeat themselves.

Java
Answer answer(Question q) {
if (!primaryBreaker.isOpen()) try { return Answer.generated(primary.ask(q), "primary"); } catch (TransientAiException e) { /* next */ }
if (!secondaryBreaker.isOpen()) try { return Answer.generated(secondary.ask(q), "secondary"); } catch (TransientAiException e) { /* next */ }
Optional<String> cached = faqCache.lookup(q); // similar question seen before
if (cached.isPresent()) return Answer.cached(cached.get());
List<Article> articles = search.top(q, 3); // retrieval only, no model
if (!articles.isEmpty()) return Answer.articles(articles);
return Answer.handover(agents.enqueue(q)); // human agent with context
}
// normal day: primary 97%, secondary 2%, cached 1%
// outage hour: secondary 71%, cached 14%, articles 11%, handover 4%
Step throughFallback ladder for one question
  1. Primary model available?circuit closed, within budget
    YesGenerated answerNoTry the next step
  2. Secondary provider available?approved for the same data
    YesGenerated answer, degradedNoTry the next step
  3. Similar question in the answer cache?
    YesCached answerNoTry the next step
  4. Relevant help articles found?retrieval only
    YesShow articlesNoHand over to a human agent

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

Each answer records which path served it. That label drives the UI message and the metrics.

4Queue the Work Nobody Is Waiting For

Not every AI call is interactive. The assistant may also summarise finished conversations for the agents, tag tickets by topic, or draft follow-up emails. None of this needs to happen within seconds. During an outage or a rate-limit squeeze, these calls should not compete with live customers for the remaining quota, and they should not fail either. So they go through a queue, such as a Kafka topic or a database job table, and a worker processes them at a controlled rate, pausing when the circuit is open and catching up when the provider recovers. The interactive path then gets the whole quota at peak hours.

5Tell Users, and Measure Every Path

A degraded answer should be honest about itself. If the assistant is showing help articles instead of an answer, it says so: Our assistant is having trouble right now. These articles may help, or you can talk to an agent. Customers accept a limited service when it is clearly explained; they lose trust when the assistant seems to have become stupid without explanation.

Finally, we measure the share of requests served by each path, per minute, along with error classes, circuit states and handovers. This tells operations how degraded we are during an incident, tells staffing how many extra agents to put on during an outage, and shows after the fact whether each fallback actually worked. A fallback path that has served zero requests in three months is a fallback we do not know works, so we exercise it with regular tests or a small steady share of traffic.

6Follow-up questions

How do you avoid a retry storm when the provider recovers?

Several mechanisms together. The circuit breaker's half-open state lets only a few trial calls through instead of all traffic at once. Retries use exponential backoff with jitter so instances do not retry in sync. The client-side rate limiter caps our request rate at the quota regardless of backlog. And queued background work is drained gradually at a controlled rate, after interactive traffic has recovered, rather than released all at once.

Is the cached answer safe to serve?

Only if it is still correct. Cached answers are tied to the source documents they came from and invalidated when those change, and highly personal questions, such as about a specific order, are never served from the shared cache.

Why not always use the secondary provider in parallel?

It doubles cost and quota use. Running the secondary on a small share of traffic keeps it tested without paying for every request twice.

7Conclusion

In this answer, we designed degradation for a support assistant. Errors are classified as transient, permanent or partial, and only transient ones are retried, within a total time budget and behind a circuit breaker per provider. Failures step down a fallback ladder of secondary provider or smaller model, cached answers, search results and human handover. Background work is queued and processed later, and the UI explains degraded mode while metrics show how many requests each path serves.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start by classifying errors, because each class needs a different response. Transient errors, timeouts, 429 and 5xx, can be retried. Permanent ones, invalid requests, context too long, content policy refusals, are never retried as they are.

Then, if they want more

Partial ones, truncated output or invalid JSON, get one repair attempt. Retries for interactive requests live inside a total time budget, say 8 seconds, and each provider has a circuit breaker, so during an outage we switch instantly instead of waiting on timeouts, and permanent errors do not count towards opening it.

When the primary fails, the request goes down a ladder: a secondary provider or smaller model approved for the same data, then cached answers for frequent questions, then retrieval-only results showing help articles, and finally a handover to a human agent with the conversation attached.

Background work like conversation summaries and ticket tagging goes through a queue, drained at a controlled rate, so it does not compete with live users during a squeeze. The UI tells users clearly when the assistant is degraded, and I measure the share of requests served by each path, which shows incident severity and proves the fallbacks actually work.

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 "An AI-powered support assistant must stay usable when the model provider has an outage...": https://scrivio-interview-library.netlify.app/spring-boot/spring-ai/410936b524/