Skip to content
aiqbenchAI & Quantum Intelligence
NewsInsightsBenchmarksSkillsAsk AILearnAbout
...Loading your session
NewsInsightsBenchmarksSkillsAsk AILearnAbout
  1. Future Jobs
  2. ›
  3. AI Inference & Efficiency Engineer
  4. ›
  5. Lesson 7 of 8

Caching, Routing and the Small-vs-Large Model Decision

Advanced¶ Read · 5 min⚑ Mission · 35 min◆ Test · 5 questions✓ Checked Nov 23, 2026

You'll be able to:

You can explain what prefix (KV) caching saves and what it cannot, structure prompts so they cache well, describe how a router decides which model answers a request and what it is optimising, and build the cost-quality argument for a cascade of small and large models without hand-waving the evaluation.

The cheapest token is the one you do not compute

After quantization, batching and hardware, the remaining large savings come from doing less work: not re-processing text the server has already seen, and not sending easy requests to expensive models. Both have sharp edges.

Prefix caching: reuse the KV cache, not the answer

Module 3 showed that PagedAttention references KV blocks through a table, so two requests can share physical blocks. Automatic prefix caching in vLLM (and the equivalents in SGLang and TensorRT-LLM) hashes each full block of prompt tokens and, when a new request begins with the same token sequence, reuses the cached blocks instead of recomputing prefill for them. What is saved is the prefill compute and TTFT for the shared prefix; decode is unchanged, and the answer is still generated fresh. Hosted APIs expose the same idea: the Claude Developer Platform's prompt caching docs describe cache breakpoints, a minimum cacheable length, a cache lifetime, and a higher price to write an entry than to read one.

The rules that follow from "hash of a token-exact prefix":

  1. Put the stable content first: system prompt, tool definitions, few-shot examples, long reference documents. Put the per-user part last.
  2. Keep the prefix byte-identical. A timestamp, a user name or a reordered tool list at the top of the prompt invalidates every block after it.
  3. Cache hits need the cache to be warm; traffic that is spread across many replicas or arrives after the entry expires pays full price. Route requests with the same prefix to the same replica if you self-host.
  4. Measure the hit rate. Servers and APIs report cached-token counts; a low rate usually means rule 2 is being broken somewhere in the prompt template.

A worked example. A prompt is 1,500 tokens of fixed context plus 200 tokens of user question, and the answer is 300 tokens. Suppose input tokens cost 1.00 per million, cached input reads cost 0.10, and output costs 5.00 per million (illustrative prices; use the real list for your vendor).

  • Uncached: 1,700 × 1.00 + 300 × 5.00 = 1,700 + 1,500 = 3,200 micro-units per request.
  • Cached prefix: 1,500 × 0.10 + 200 × 1.00 + 300 × 5.00 = 150 + 200 + 1,500 = 1,850, a 42% saving — almost all of it from the input side. Output tokens are untouched, which is why caching helps long-prompt, short-answer products most and barely helps a chatbot that writes essays from a short prompt.

Semantic caching — returning a stored answer when a new question is "similar enough" to an old one — is a different thing. It saves everything, including decode, but serves stale or wrong answers whenever similarity is not equivalence. Treat it as a product decision with an explicit error budget, not an infrastructure optimisation.

Routing: send each request to the cheapest model that can handle it

A router sits in front of two or more models and decides which one answers. Simple routers use rules (request length, task type, customer tier). Learned routers predict, from the prompt alone, whether a small model's answer would be judged acceptable. The RouteLLM paper from LMSYS trains such predictors on human preference data and reports that a large share of queries can go to the cheaper model with a modest drop in quality on their benchmarks — the exact share and drop are properties of their model pair and evaluation set, not constants you can assume. FrugalGPT's cascade is the other common design: try the cheap model first, score the answer with a verifier, and escalate to the expensive model only if the score is low. Cascades pay twice on escalations but need no predictor.

The cost-quality argument needs numbers. Say the large model costs 10 per unit of traffic and the small one 1; 60% of requests are answerable by the small model, and the router classifies 90% of each group correctly.

  • Requests sent to the small model: 60% × 0.9 (true positives) + 40% × 0.1 (mistakes) = 58%.
  • Blended cost: 0.58 × 1 + 0.42 × 10 = 4.78 versus 10 — a 52% saving.
  • Requests that get a worse answer: the 4% that needed the large model but were routed small. Whether 4% degraded answers is acceptable is the real question, and only a task-specific evaluation with real users' judgements can answer it. A router evaluated on a generic benchmark will mis-estimate both numbers on your traffic.

Small versus large: the strategic version

Routing is a tactic; the strategic question is whether to run a small specialised model at all. Small models win when the task is narrow, volume is high, latency matters and you can build an evaluation set that reflects production. Large models win when inputs are diverse, the task shifts often, or a wrong answer costs far more than a token. Mature systems often use both: a large model for labels and the tail, a distilled small model for the head, a router or cascade between them, and the evaluation set as the most carefully maintained asset.

What is still unsettled

Routing for multi-turn and agentic workloads, where a cheap wrong step compounds across many calls, is poorly understood. Cache-aware load balancing across replicas and providers is still mostly hand-rolled, and semantic caching's safety for personalised or time-sensitive content is an open product-design problem.

What to remember

  • Prefix caching reuses KV blocks for a token-exact prefix: it cuts prefill cost and TTFT, not decode. Stable content first, variable content last, byte-identical templates.
  • Caching helps long-prompt/short-answer workloads most; output tokens are never cached.
  • Routers and cascades cut cost by the share of traffic a small model can handle, at the price of the routing mistakes; both numbers come from your own evaluation set, not from a paper.
  • The durable asset in a small-vs-large strategy is the evaluation set that tells you when the small model is good enough.

Curated Materials

1.3h

The deep work happens here — the lesson is your briefing.

  • vLLM docs: Automatic Prefix CachingDocs· 20 min
  • Prompt caching (Claude Developer Platform docs)Docs· 25 min
  • RouteLLM: Learning to Route LLMs with Preference Data (Ong et al., LMSYS)Paper· 35 min

Live on aiqbench

This lesson's subject on the rest of the site, today.

In the news, last 30 days

  • GPU decoder keeps pace with a superconducting qubit clock on a continuous stream, with NVIDIA NVQLink interconnectAlice & Bob · Dec 1
  • DeepSeek Opens Source Production-Level Ascend Inference Code36Kr · Dec 1
  • NVIDIA and Cerebras Partner to Accelerate AI Agent Inference with Two-Stage Compute Architecture36Kr · Dec 1
More news on this subject →

Go further

  • Which model is worth it?Price, speed and hardware next to capability.
  • Ask AI about this lessonOpens Ask AI with a question about this lesson, answered from the news archive with sources.
  • Agent skills for this workReady-made skills for AI coding agents, checked and rated.

Test your knowledge

5 questions in 100 seconds, on a page of its own. Read everything above first.

Test your knowledge →

Module Mission

30–40 min

Take a system prompt of about 1,500 tokens plus a per-user 200-token question and a 300-token answer. Using a published price list for one API model (any vendor) and its documented cached-input discount, compute the cost per request with and without prefix caching, then the daily cost at 50,000 requests. Next, assume a small model that is one-tenth the price can answer 60% of requests acceptably and a router that is right 90% of the time: compute the blended cost and the share of requests that get a worse answer. Write the two tables and a five-sentence recommendation.

Loading your work…

← Previous lesson6. Measuring Latency and Cost HonestlyNext lesson →8. Capstone: Serve a Small Model Two Ways and Write the Report
aiqbench
AI & Quantum Intelligence© aiqbench. All rights reserved.

Feeds:RSS·JSON Feed

LanguageEnglish·Românăbeta
NewsAI & TechQuantumInsights
ExploreBenchmarksLearn
CompanyAboutTrustLegal noticeTerms of ServicePrivacy PolicyCopyright noticesData erasureReport content

The aiqbench take, the insights, the daily digest and Ask answers are written by AI models from the sources shown, without editorial review before publication. They may contain errors — check the source. How the model is used →

  • News
  • Insights
  • Ask AI
  • Benchmarks
  • Account