Introduction
Hello! In our last lesson, we explored "hallucination cost," quantifying the indirect business risks of an AI making a critical error. We used the concept of Expected Value to understand that even infrequent failures can carry a significant, predictable cost (Expected Cost = Probability × Impact).
Today, we pivot from managing these probabilistic, indirect costs back to managing the direct, operational costs of running an AI feature. Your goal for this lesson is to explain how response caching and request deduplication can reduce AI operational costs.
The core idea is simple and should resonate with your engineering background: avoid redundant work. For every user query that is a rephrasing of a previous one, a call to the LLM is a waste of money and time. As an architect, designing a system that intelligently avoids these redundant calls is one of the most powerful levers you have for building economically sustainable and performant AI products.
1. The Caching Principle and Its Limitation
In traditional software, caching is a standard technique. If a system receives the same request multiple times, it stores the result of the first request and serves it directly for all subsequent identical requests, skipping the expensive computation.

However, with Large Language Models, this traditional, exact-match caching is often ineffective. Why? Because human language is fluid. Consider a user wanting to reset their password. They might ask:
- "How do I reset my password?"
- "I forgot my password"
- "Can't log in, need password help"
To a traditional cache, these are three unique strings, resulting in three separate, expensive calls to the LLM to get what is essentially the same answer. This is where a more intelligent approach is needed.
2. Semantic Caching: Caching by Meaning
The solution is semantic caching: a technique that matches queries based on their meaning (semantics), not their exact wording.
To get a quick overview of how this works, please watch this short video from Redis.
This video provides a concise and clear explanation of what semantic caching is, the problem it solves, and the high-level mechanics behind it.
Watch the video from the beginning until 01:15. Focus on the core concepts of 'cache hit' vs. 'cache miss' in a semantic context.
As the video explained, the process relies on converting text into numerical representations called vector embeddings. The system can then mathematically compare these vectors to see how "close" they are in meaning.
This diagram illustrates the architectural flow:

Now, let's dive into the practical impact and architectural considerations of implementing this.
Reduce Costs by 40-80% and Speed up by 250x Semantic Caching ...
The article 'Semantic Caching for LLM Apps' by Percona provides excellent, concrete details on the benefits and key configuration parameters of this technique. This will give you the architectural-level details you need.
Please read the following sections: 'What is Semantic Caching?': This section clearly contrasts traditional vs. semantic caching and outlines the high-level process. 'Why do you need this?': Focus on the quantified benefits under 'Cost savings' and 'Speed Improvements'. This is crucial for making a business case as an architect. 'Configuration: important levers': This is the most critical section for your role. Understand the trade-offs involved in setting the 'Similarity Threshold' and 'Time-to-Live (TTL)'.
From an architect's perspective, the key takeaways from this reading are:
- Significant Cost & Latency Reduction: Semantic caching can eliminate 40-70% of LLM calls, leading to massive cost savings and drastically lower response times for users—a huge win for UX.
- Tunable Parameters: You don't just "turn on" caching. You must make deliberate design choices.
- Similarity Threshold: A higher threshold (e.g., 0.95) means higher accuracy but fewer cache hits. A lower threshold (e.g., 0.80) increases hits but risks returning irrelevant answers. Your choice depends on the application's tolerance for error.
- Time-to-Live (TTL): This determines how long a cached response is valid. For rapidly changing information (stock prices), the TTL might be minutes. For stable content (company policies), it could be hours or days. This ties directly into the data freshness principles we'll discuss later in the course.
3. Request Deduplication: The Underlying Strategy
"Semantic Caching" is a specific implementation of a broader architectural strategy often called Semantic Deduplication. The goal is the same: reduce redundant requests by identifying semantic duplicates.
Let's read a short section from an article that frames this from a systems-scaling perspective.
The Hard Reality of Scaling AI Projects - DEV Community
This article, 'The Hard Reality of Scaling AI Projects,' frames deduplication as a fundamental strategy for building efficient AI systems. This perspective is perfect for the 'Architect Track'.
Read the section titled '1️⃣ Semantic Deduplication'. It succinctly covers the problem, the solution, the architectural flow, and the pros and cons of this approach.
This article reinforces the concept and highlights a key insight: efficient AI is achieved by reducing unnecessary calls. This principle is a cornerstone of good AI system architecture.
4. An Important Nuance: Output vs. Prompt Caching
So far, we've discussed caching the final output of an LLM call. This is known as output caching. However, there's another powerful technique an architect should be aware of: prompt caching.
Prompt caching doesn't store the final answer. Instead, it stores the LLM's internal, pre-processed understanding of the input prompt. This is extremely useful when a large part of your prompt is static.
Imagine a user uploading a 50-page document and then asking multiple questions about it.
- Query 1:
[50-page document] + "Summarize this." - Query 2:
[50-page document] + "What are the key risks mentioned?"
With prompt caching, the expensive process of reading and understanding the 50-page document only happens once. For the second query, the system retrieves the cached understanding of the document and only needs to process the new question, saving significant time and cost.
This video from IBM Technology explains the distinction clearly.
What is Prompt Caching? Optimize LLM Latency with AI Transformers
This video clearly distinguishes between output caching and prompt caching, a crucial concept for an architect designing complex AI interactions.
Please watch these three segments: 00:00 - 03:36: This part defines prompt caching by explaining what it is not (output caching) and detailing how it caches the LLM's internal state (KV pairs). 03:36 - 04:59: This segment shows a practical example of how prompt caching saves work when querying a large document. 06:05 - 07:52: This is a key architectural insight. It explains why prompt structure (placing static content first) is critical for effective prompt caching.
Understanding both output caching (for handling repetitive, semantically similar queries) and prompt caching (for handling repetitive context with varying questions) gives you a more complete toolkit for optimizing AI economic performance.
Conclusion
In this lesson, we've established caching and deduplication as fundamental strategies for controlling the direct operational costs of AI. By intelligently avoiding redundant work, we can build systems that are not only cheaper to run but also faster and more responsive for the user.
Key Takeaways:
- Semantic Caching / Request Deduplication is a critical technique that uses vector embeddings to identify and reuse answers to semantically similar queries, dramatically reducing LLM API costs and latency.
- As an architect, you must configure key parameters like the similarity threshold (balancing accuracy and hit rate) and Time-to-Live (TTL) (ensuring data freshness).
- The choice of caching strategy depends on the use case. Output caching is ideal for high-volume, repetitive questions (like in an FAQ bot). Prompt caching is powerful for scenarios involving a large, static context with multiple follow-up questions.
- The guiding principle is to shift from a "call the LLM for every request" model to one where only truly unique requests incur the full cost of inference.
Next Steps
We've now learned how to avoid making unnecessary calls to the LLM. But what about the calls that are truly unique and necessary? How can we make those individual calls more efficient? In our next lesson, we will explore batch inference, a technique for grouping multiple requests into a single operation to improve throughput and further optimize costs.