Skip to the page

Cost, speed and serving · mid

Prompt caching, routing, rate limits and batch jobs

Cut cost and survive limits with a stable prompt prefix for caching, routing easy requests to smaller models, careful retries, and batch processing for jobs that can wait.

The notes

What you must know

  • Prompt caching: the server keeps the processed prefix of recent prompts. A request that starts with exactly the same tokens reuses it, giving lower TTFT and a discount on cached input tokens. Rules differ by provider.
  • The match is token for token from the start. Put stable content first (tools, instructions, examples, shared documents) and per-request content last. A timestamp or a reordered tool list breaks the cache.
  • Model routing: send simple intents to a small fast model and hard work to a large one. Use a rule, a classifier or a small model as the router, and measure it.
  • Move a category to the small model only when evals pass, then check with a shadow test. A cascade retries on the large model when validation fails.
  • Other levers: shorter prompts, compact tool results, an output cap, answer caching for repeated questions, batch APIs and removing unneeded calls.
  • Rate limits are usually requests per minute and tokens per minute. Long prompts use the token limit fast.
  • Retries: honour retry-after, use exponential backoff with jitter, keep a retry budget, retry only once or twice on the user path, and use a circuit breaker.
  • During overload shed load by priority, use a tested fallback model, and show a graceful fallback instead of an error.
  • Batch APIs return results within a window at a discount for jobs that do not need answers soon. Plan checkpoints, keys per item and retries only for failed items.

The red pen

Common traps: mistake → fix

  • Mistake: Retrying faster fixes a 429

    Fix: immediate retries add load; use backoff and a budget.

  • Mistake: Use the biggest model for everything to be safe

    Fix: route by difficulty and prove it with evals.

  • Mistake: Caching works whatever the prompt order

    Fix: only an identical prefix hits.

Easy to hard

Questions interviewers ask, easy to hard

  1. How does prompt caching work and how do you get hits?
  2. How would you halve the bill without hurting quality?
  3. 15 percent of requests get 429 during a sale. What do you do?
  4. Real-time calls, batch API or self-hosting for a nightly job of 5 lakh tickets?

Practise

Practise with these questions

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview