Module 4 · 5 lessons

Reliability: fallbacks, timeouts and guardrails

What to do when the model is slow, down or wrong: fallbacks, timeouts, safe retries and output checks.

Before you start

From this track: Modules 0 to 3. Each module uses only ideas from the ones before it.

Builds on: Timeouts, retries and idempotency, Circuit breakers and bulkheads

Already know these? Start with the first lesson below.

1. A timeout on every model call

The picture

Stop waiting, start plan B

A first-token timeout cancels a call that has sent nothing, so the user gets a fallback instead of a spinner.

Scene 1 of 4 · A healthy call

A healthy call sends its first words after 0.6 s, so the user sees text almost at once.

Calls side by side (made-up timings)

Healthy call

  1. Request sent at 0 s
  2. Words reach the user at 0.6 s, first words
First-token limit
not shown yet
Whole-answer limit
not shown yet
  1. A healthy call. A healthy call sends its first words after 0.6 s, so the user sees text almost at once.
  2. An overloaded provider. When the provider is overloaded, nothing comes back; with no timeout, the user could wait 45 s.
  3. Cancel at 3 s. With a 3 s first-token limit, the stuck call is cancelled and the small model answers by 3.4 s.
  4. A longer whole limit. The whole answer gets a longer limit, 20 s, since a stream that started well can still stall.
  5. Now you try. Set the first-token limit, and see what happens to an overloaded call and to a slow but healthy one. For example: The overloaded call's user gets the fallback at 1.4 s; the slowest healthy call (2.5 s) is cancelled too. Too short a limit cancels calls that were working, wasting them and adding load from fallbacks.

Scene 1 of 4: A healthy call. A healthy call sends its first words after 0.6 s, so the user sees text almost at once.

Key points

  1. A healthy call usually starts sending words within a second or two.
  2. With no timeout, an overloaded provider can keep the user waiting a long time.
  3. A short first-token limit catches that early and hands over to plan B.
  4. A longer limit on the whole answer catches a stream that stalls.

A model call can take seconds even when all is well, and much longer when a provider is overloaded. Without a , users wait as long as the slowest call.

Pick a timeout from what users will put up with, such as a few seconds for a chat reply. A call that runs past it counts as failed.

Streaming helps: set a short limit for the first , since a fast start usually means the call is healthy. Keep a longer limit for the whole answer, since a stream can stall.

Example. Illustrative: a support chat gives the model 3 s to send its first token. A call that has sent nothing by then is cancelled, and the next plan takes over.

In system design: Every model call needs a timeout, chosen from the user's patience, not from how long the model might need.

Where it goes wrong

  • One timeout for every call is too short for long answers and too long for short ones. Set limits for each feature.
  • A cancelled call may still be billed for the tokens it already used, so a retry can pay twice.

In an interview

  • Give two limits, a short one for the first token and a longer one for the whole answer, and say what happens at each.

Check yourself

How should you choose a model call's timeout?

Two harder questions

The first uses the idea on a new case. The second asks you to judge a design.

Apply it

A streamed reply has a 3 s limit for the first token and a 30 s limit for the whole answer. The first token comes at 1 s, then the stream stalls. What happens?

Judge a design

A team uses one 60 s timeout for every model call, including a short autocomplete. What is wrong?

Sources and further reading (2)

First-hand sources to check this lesson against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.

  • Engineering guideTimeouts, retries, and backoff with jitterAmazon Builders’ LibraryHow Amazon picks a timeout from measured latency, so slow calls fail instead of piling up.
  • Official docsErrorsAnthropic docs (one provider)The errors one provider returns, such as overloaded and rate limited, and what each means.

Open this lesson on its own page

2. Retrying safely

The picture

One retry, then plan B

Retry a brief error once after a short, jittered wait, then fall back; do not repeat a step that changes something without checking first.

Scene 1 of 4 · A brief error

The call fails after 0.3 s with "busy, try again": a brief error that a retry often fixes.

Retries over time, in seconds (made-up timings)

One request

  1. Call or retry at 0 s, call
  2. "Busy" error at 0.3 s, busy
  1. A brief error. The call fails after 0.3 s with "busy, try again": a brief error that a retry often fixes.
  2. Wait, then retry once. The app waits about 1 s, retries once, and gets "busy" again.
  3. Then fall back. It stops retrying and moves on to its fallback, instead of keeping the user waiting longer.
  4. Spread the retries. Without jitter, every client retries at the same moment; with jitter, the retries spread out.
  5. Now you try. A call failed. Pick what went wrong, and see whether to retry. For example: Do not retry blindly. The email may already have gone, so a blind retry could send it twice; check first.

Scene 1 of 4: A brief error. The call fails after 0.3 s with "busy, try again": a brief error that a retry often fixes.

Key points

  1. A "busy" error is often gone a second later.
  2. Retry it once or twice, with backoff, then fall back.
  3. Jitter spreads many clients' retries apart.
  4. A step that sends or books something must never be retried blindly.

Go deeper in the Retries, backoff & jitter lab →

Many model errors are brief, such as a provider saying it is busy, so one retry with often works. The Retries lab shows backoff and at work.

But a retry after a timeout may pay for the tokens again, and retrying an action, such as sending an email, may do it twice. Retry only what is safe to repeat.

Cap the retries, and spread them with jitter, so many clients do not hit a struggling provider at the same moment.

Example. A call fails with "busy, try again". The app waits about 1 s and retries once. If that fails too, it moves on to its instead of retrying again.
Try it yourselfRetries, backoff & jitterOpen the lab →

In system design: Retry brief errors once or twice with backoff and jitter, and never blindly retry a step that changes something.

Where it goes wrong

  • Many clients retrying at once can keep a busy provider busy. Use growing waits, a random spread and a cap.
  • Retrying a call that changed something, such as sending an email, can do it twice. Send an id the receiver can use to spot repeats, or check first.

In an interview

  • Say which errors you retry, how many times and how far apart, and which calls are never retried.

Check yourself

Which call should you not retry blindly after a timeout?

Two harder questions

The first uses the idea on a new case. The second asks you to judge a design.

Apply it

1,000 clients all retry exactly 1 s after the same failure. What does that do to the provider?

Judge a design

A team retries every failed model call up to 10 times, with no wait between tries. What is wrong with this design?

Sources and further reading (2)

First-hand sources to check this lesson against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.

Open this lesson on its own page

3. Provider rate limits and batch jobs

The picture

How the job sends its requests
Nightly job, 600 ticketsNightly job600 ticketsModel API, 60,000 tokens a minute, NOWModel API60,000 tokens a minute600 arrive at onceNOW
  • Nightly job — 600 tickets — healthy
  • Model API — 60,000 tokens a minute — healthy — NOW — 600 arrive at once
  • Requests
  • Refused: 429
Step 1 of 3

Step 1 of 3 · Model API

Done: The job sends all 600 requests at once

What happens
Each request asks for one ticket summary, and all of them start together.
Why
60,000 tokens a minute ÷ 2,000 tokens a request = 30 requests a minute.
What changes
Only 30 fit in this minute.
Next
570 come back as "429 Too Many Requests"

Event log

2 more to go. Press a line to go back to that step.

Summaries done
0 of 600
Refused calls
0
Time to finish
–
Cost
–
example price

Each minute: answered, and refused with 429

No minute has run yet.

Step 1 of 3: Model API. The job sends all 600 requests at once. Each request asks for one ticket summary, and all of them start together.

What this simplifies. The limit, the request size and the price ($3 per million tokens) are examples, and so is the half price for batch work. Real limits are often set per minute for both requests and tokens, and they differ by provider and account.

Model providers limit how much each account may send, usually per minute: a number of requests and a number of tokens. A call over the limit is refused with status 429, "Too Many Requests", often with a Retry-After header that says how long to wait.

Retrying refused calls straight away only adds more refused calls. Instead, count your own tokens and pace the calls a little under the limit, with one limiter that every caller of the key shares. Then a 429 becomes rare, and each one waits as told.

Work nobody is waiting for, such as nightly summaries, can go to a batch API. You send one file of many requests, and the results come back within a set time, often up to 24 hours. Some providers charge much less for it.

Never batch a request a person is waiting on. Keep live chat on the normal API. Move bulk jobs out of its way, so they do not use up the limit that live users need.

Example. In the picture, 600 requests of 2,000 tokens meet a limit of 60,000 tokens a minute, so 30 fit each minute. Sending all at once wastes 5,700 refused calls, pacing wastes none, and the batch costs half.

In system design: Pace calls under the provider limit with one shared limiter, honour Retry-After, and send bulk work that nobody waits for to a batch API.

Where it goes wrong

  • If each server paces itself alone, the total can still go over the account limit. Share one limiter for each key.
  • Retrying at once and ignoring Retry-After turns a short limit into a long outage.

In an interview

  • Work out how many requests a minute fit under a token limit, and how you keep room for live users.

Check yourself

A nightly job and a live chat share one API key. Each night, chat users start getting 429 errors. What should you change first?

Two harder questions

The first uses the idea on a new case. The second asks you to judge a design.

Apply it

The limit is 90,000 tokens a minute, and each request uses 3,000 tokens. How many requests fit each minute?

Judge a design

Four servers share one API key, and each one paces itself to the full account limit. What goes wrong?

Sources and further reading (3)

First-hand sources to check this lesson against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.

  • StandardRFC 6585: Additional HTTP Status CodesIETFDefines 429 Too Many Requests and the Retry-After header.
  • Official docsRate limitsAnthropic docs (one provider)Real limits on requests and tokens per minute, and the headers that report what is left.
  • Official docsBatch processingAnthropic docs (one provider)Sending many requests as one job that finishes later, at a lower price.

Open this lesson on its own page

4. Falling back when the model fails

The picture

What goes wrong?

Predict first: which model or saved answer replies, and how long does the user wait? Step through to check.

User, NOWUserNOWApplication, timer and fallbacksApplicationtimer and fallbacksLarge model, best answersLarge modelbest answersSmall model, faster and simplerSmall modelfaster and simplerAnswer cache, answers saved earlierAnswer cacheanswers saved earlier
  • User — healthy — NOW
  • Application — timer and fallbacks — healthy
  • Large model — best answers — healthy
  • Small model — faster and simpler — healthy
  • Answer cache — answers saved earlier — healthy
  • Request
  • Error or timeout
  • Fallback
  • Streamed answer
Step 1 of 8

Step 1 of 8 · User

Done: The user sends a chat message

What happens
A user sends a message and waits for the reply.
Why
Every second of waiting counts from here, whatever happens behind the application.
What changes
The application has the message. The clock for this reply starts at 0 s.
Next
Build the request and start a 3 s timer

Event log

7 more to go. Press a line to go back to that step.

Clock for this reply
0s
Model calls made
0
Timeouts and errors
0
Answered by
–

Step 1 of 8: User. The user sends a chat message. A user sends a message and waits for the reply.

The whole chain at a glance

  1. Large model timed out, 3 s
  2. Small model answered, 0.4 s
  3. Cached answer not needed
  4. Try-again message not needed

The small model answers after about 3.4 s in all, so the user gets a shorter, simpler answer.

The large model gets a 3 s timeout. What this simplifies. The timings are made up to show the idea. Real timeouts depend on what users will wait for. A circuit breaker would skip a provider that keeps failing, so later users reach the fallback faster. On a "too many requests" error this app moves on at once. Another app might wait and try the same model again.

A fallback is a plan B: when the main model times out or fails, the app answers another way instead of showing an error.

A common chain is a smaller model, then a cached answer from earlier, then an honest message asking the user to try again.

When a provider fails again and again, a stops calling it for a while, so users go straight to the fallback. The Circuit breaker lab shows this.

Example. Pick "The large model is slow" above. The app waits for the 3 s timeout, then the small model answers 0.4 s later: about 3.4 s in all.
Try it yourselfCircuit breakerOpen the lab →

In system design: Design the fallback chain on purpose, and tell users when they get a simpler or older answer.

Where it goes wrong

  • A fallback that is never tried fails on the day it is needed. Test the whole chain on purpose.
  • A smaller fallback model can answer worse with nobody told. Mark answers that came from a fallback, and measure them.

In an interview

  • Lay out the chain in order, and say what the user sees at each step.

Check yourself

The large model times out after 3 s. What does a planned fallback chain do next?

Two harder questions

The first uses the idea on a new case. The second asks you to judge a design.

Apply it

The main model has a 2 s timeout. It hangs, and the small model then answers 0.5 s later. How long does the user wait?

Judge a design

A team built a fallback to cached answers, but has never tried it. What is the risk?

Sources and further reading (2)

First-hand sources to check this lesson against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.

  • Engineering guideAvoiding fallback in distributed systemsAmazon Builders’ LibraryAmazon’s case that a fallback path can fail when it is needed, and how to test it.
  • Official docsErrorsAnthropic docs (one provider)Which failures a fallback must handle: overload, rate limits and server errors.

Open this lesson on its own page

5. Checking the answer before it is shown

The picture

Check before you show

Plain code checks every answer before the user sees it, and a failed check has a planned next step.

Scene 1 of 4 · The model answers

The page needs the answer in JSON, a strict data format; this time the model sends broken JSON.

Language modelLanguage modelAnswer checksAnswer checkscheckingUserUser
  • Language model — healthy
  • Answer checks — healthy — checking
  • User — healthy
Checks on this answer
Code check
Valid JSON
No phone number but the support line
Under 200 words
  1. The model answers. The page needs the answer in JSON, a strict data format; this time the model sends broken JSON.
  2. Code checks it. Plain code runs 3 checks: valid JSON, no phone number but the support line, and under 200 words.
  3. Ask once more. The JSON check failed, so the app sends the request to the model again rather than show a broken page.
  4. Then show it. The second answer passes every check, and only then does the user see it.
  5. Now you try. Pick an answer the model sent, and see which check catches it. For example: "No phone number but the support line" fails, so the app will block the answer and show a safe message. The response to each failure is decided in advance, so an answer that fails a check does not reach the page.

Scene 1 of 4: The model answers. The page needs the answer in JSON, a strict data format; this time the model sends broken JSON.

Key points

  1. Checks run between the model and the user.
  2. Code checks are fast and cheap: format, private data, length.
  3. Each failed check has a planned response.
  4. A model-based check can add more, but keep the code checks too.

A model can write something false, unsafe or in the wrong format. are checks that run on the answer before the user sees it.

Some are plain code: is the answer valid , does it include a phone number it should not, is it under the length limit?

Others use a second model to look for problems. That is slower and can itself be wrong, so keep the code checks too. A check catches only what it was written for, so some bad answers still get through.

Example. A bot that must answer in JSON sends back broken JSON. A code check catches it, and the app asks the model once more instead of breaking the page.

In system design: Put cheap code checks on every answer, and decide in advance what happens when a check fails.

Where it goes wrong

  • A check that blocks too much frustrates users and hides good answers. Measure how often each check fires, and why.
  • A check run by a model can be fooled by the same tricks as the main model, so it should never be the only guard.

In an interview

  • Say which checks run on every answer, which use code and which use a model, and what happens when one fails.

Check yourself

Why keep plain code checks even when a second model also checks answers?

Two harder questions

The first uses the idea on a new case. The second asks you to judge a design.

Apply it

An answer must be under 500 characters and must not include a phone number. Which kind of check fits?

Judge a design

A check blocks 1 answer in 5, and users complain that good answers vanish. What should the team do first?

Sources and further reading (2)

First-hand sources to check this lesson against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.

Open this lesson on its own page