
When you use an LLM in production, many requests share identical text at the beginning (called a "prefix").
Request 1: [System Prompt - 2000 tokens] + [User Question A]
Request 2: [System Prompt - 2000 tokens] + [User Question B]
Request 3: [System Prompt - 2000 tokens] + [User Question C]
Every single request forces the model to reprocess that identical system prompt from scratch.
| Problem | Impact |
|---|---|
| Redundant computation | Wastes GPU cycles |
| Repeated processing | Increases latency |
| Extra compute = extra cost | Inflates costs |
Simple Analogy: Imagine re-reading an entire textbook every time someone asks you a question about it, instead of remembering what you already read.
A system prompt is a fixed set of instructions given to the LLM before the actual user question.
┌─────────────────────────────────────────┐
│ SYSTEM PROMPT (fixed, repeated) │
│ "You are a helpful assistant. You work │
│ in the medical domain. Always cite │
│ sources. Never give diagnoses..." │
│ [potentially thousands of tokens] │
├─────────────────────────────────────────┤
│ USER QUESTION (changes each request) │
│ "What are symptoms of diabetes?" │
└─────────────────────────────────────────┘
When an LLM processes text, it generates Key-Value (KV) pairs — intermediate mathematical representations for each token.
Text Input → Transformer Layers → KV Pairs (stored in memory)
↓
Used to generate next token
Request 1: Process [2000 token prompt] → Generate KV pairs → Answer
❌ KV pairs discarded
Request 2: Process [2000 token prompt] → Generate KV pairs → Answer
❌ KV pairs discarded again
Request 3: Process [2000 token prompt] → Generate KV pairs → Answer
❌ Discarded again...
Request 1: Process [2000 token prompt] → Generate KV pairs → Answer
✅ KV pairs SAVED in memory
Request 2: Load saved KV pairs → Process only new tokens → Answer
✅ Much faster!
Request 3: Load saved KV pairs → Process only new tokens → Answer
✅ Fast again!
Simple Analogy: Instead of solving the same math equation from scratch every time, you save your work and only solve the new part.
Prompt caching is the technique of storing the KV cache of a repeated prompt prefix so it can be reused across multiple requests.
┌──────────────────────┐
│ PROMPT CACHE │
│ (Memory Storage) │
│ │
│ [KV pairs for │
│ shared prompt] │
└──────────┬───────────┘
│ reuse
┌────────────────┼────────────────┐
↓ ↓ ↓
Request 1 Request 2 Request 3
[New tokens] [New tokens] [New tokens]
only! only! only!
| Benefit | Explanation |
|---|---|
| ⚡ Lower latency | Skip reprocessing shared tokens |
| 💰 Cost reduction | Less compute = lower cost |
| 📈 Higher throughput | More requests handled per second |
| 🎯 Better quality | Can afford longer, richer prompts |
The article says: "the compute cost of that shared prompt [is] amortized across all those queries"
WITHOUT caching:
Cost per request = Full prompt cost + Question cost
1000 requests × (2000 token cost + 50 token cost) = VERY HIGH
WITH caching:
First request = Full prompt cost + Question cost ← pay once
Next 999 requests = Only question cost ← pay small amount
Total cost spread (amortized) across all 1000 requests = MUCH LOWER
Simple Analogy: Like buying a monthly bus pass. You pay once and ride many times, making each ride cheaper than buying individual tickets.
Longer system prompt = Better quality (more context, instructions)
= BUT slower throughput (more tokens to process)
Shorter system prompt = Faster throughput
= BUT lower quality
With Prompt Caching:
Longer system prompt = Better quality ✅
= NO throughput penalty ✅ (cached!)
You get BOTH quality AND speed!
┌─────────────────────────┐ ┌─────────────────────────┐
│ PROPRIETARY MODELS │ │ OPEN-SOURCE MODELS │
│ (Closed weights) │ │ (Open weights) │
├─────────────────────────┤ ├─────────────────────────┤
│ • GPT (OpenAI) │ │ • Llama (Meta) │
│ • Gemini (Google) │ │ • Mistral │
│ • Claude (Anthropic) │ │ • DBRX (Databricks) │
└─────────────────────────┘ └─────────────────────────┘
↓ ↓
Databricks had prompt NOW ALSO has
caching ALREADY prompt caching! ✅
Company A's system prompt → cached
← Could Company B access it? ❌ NO!
Company B's system prompt → cached
┌─────────────────────────────────────────────┐
│ SECURITY PRINCIPLES │
├─────────────────────────────────────────────┤
│ 1. ISOLATED → Each customer's cache is │
│ completely separate │
│ │
│ 2. VOLATILE → Only lives in RAM │
│ (disappears when cleared) │
│ │
│ 3. NOT PERSISTED → Never written to disk │
│ or long-term storage │
└─────────────────────────────────────────────┘
Simple Analogy: Like a whiteboard in a private room — only you can see it, and it gets erased when you leave.
Explicit Caching (NOT what Databricks does):
# Developer must manually configure
response = llm.call(
prompt="...",
cache_prefix=True, # ← must remember to add this
cache_id="my_cache_123" # ← must manage cache IDs
)
Implicit Caching (Databricks approach):
# Developer just makes normal API call
response = llm.call(
prompt="..."
# That's it! Caching happens automatically ✅
)
| Aspect | Explicit | Implicit |
|---|---|---|
| Developer effort | High | Zero |
| Risk of misconfiguration | Yes | No |
| Adoption barrier | High | None |
| Consistency | Varies | Always on |
┌─────────────────────────────────────────────────────┐
│ DATABRICKS WORKLOADS │
├─────────────────┬───────────────────────────────────┤
│ Batch Inference │ Process large volumes of requests │
│ │ offline (e.g., document analysis) │
├─────────────────┼───────────────────────────────────┤
│ Pay-per-token │ Real-time API calls, pay for │
│ │ what you use │
├─────────────────┼───────────────────────────────────┤
│ Provisioned │ Reserved capacity for consistent │
│ Throughput │ high-volume workloads │
└─────────────────┴───────────────────────────────────┘
Prompt Caching
↓
Powers these services automatically:
├── Agent Bricks (AI agents)
├── Genie (data analytics AI)
└── AI Functions (SQL-integrated AI)
The article mentions measurable gains in large-scale batch inference pipelines after rolling out to GPT-OSS models:
BEFORE prompt caching:
[████████████████████] Full prompt processed every request
High latency | High cost | Lower throughput
AFTER prompt caching:
[████] Only new tokens processed
Lower latency ✅ | Lower cost ✅ | Higher throughput ✅
High benefit scenarios:
├── 🤖 Real-time chat (same system prompt, many users)
├── 📄 Batch document processing (same instructions, many docs)
└── 🔧 AI agents (long context windows, repeated tool descriptions)
THE JOURNEY OF A PROMPT WITH CACHING:
1. REQUEST ARRIVES
"System: You are an expert... [2000 tokens]
User: What is X?"
2. SYSTEM CHECKS CACHE
"Have I seen this prefix before?"
├── YES → Load KV cache, skip to user question ⚡
└── NO → Process full prompt, SAVE to cache 💾
3. GENERATE RESPONSE
Only process the new/unique tokens
4. RESULT
✅ Faster response
✅ Lower compute cost
✅ Higher throughput
✅ Better quality (can use longer prompts)
✅ Secure (isolated, volatile, not persisted)
✅ Zero configuration needed
| Concept | One-Line Summary |
|---|---|
| The Problem | Reprocessing identical prompts wastes compute |
| KV Cache | Saved mathematical representations of processed tokens |
| Prompt Caching | Reuse KV cache across requests with shared prefixes |
| Amortization | One-time compute cost shared across many requests |
| Quality-Speed | Longer prompts no longer hurt throughput |
| Security | Isolated, volatile, never persisted |
| Implicit | Automatic — zero developer configuration needed |
| Scope | Works across batch, real-time, and agent workloads |