AI Infrastructure & CostField engagement

Near-identical work was being recomputed on every request, and neither the prompts nor the model was what drove the bill.

Architecture and delivery lead.
48%
fewer requests to the model
44%
lower average latency
58%
lower monthly cost
60,000+
requests a day
In-memory100 to 62
Semantic62 to 44
Embedding44 to 36
Prompt prefix36 to 30
Vector30 to 25
Response25 to 20
The modelreached by what none of the six layers could answer52%
Sixty thousand requests a day descending through six cache layers. Each layer absorbs near-identical work the one above it did not recognise, and only what is left reaches the model. Optimising prompts on a system with no cache lowers the price of each redundant call without removing any of the redundancy.
What was at stake

A platform handling more than 60,000 requests a day. The accuracy was fine. The monthly bill was not. Near-identical requests were computed from scratch every time, through repeated prompts, embeddings, retrieval and reasoning, with no caching anywhere along the path. At that volume the inference bill, and not the accuracy, was what threatened the product.

How this works

Every request to a model pays for the whole computation again, unless something upstream remembers the answer.

A language model keeps no memory between requests. Each call is computed and billed in full, even when it is almost identical to one answered a moment earlier. An AI feature is also rarely a single call. A typical request passes through several expensive stages: turning text into an embedding, searching a vector index for related material, assembling a prompt, running the model, and sometimes reasoning further over the result. Each stage costs time and money, and each will happily repeat work it has only just done.

Caching is the general answer to repeated work: store a result and serve it again when the same question comes back. The subtlety with AI workloads is that the same question has several meanings. An exact cache catches byte-for-byte repeats. A semantic cache catches requests that are worded differently but mean the same thing, by comparing their meaning, and it trades a little exactness for a lot of reach. Between those sit caches for the intermediate stages: an embedding already computed for this text, a prompt whose opening section has already been processed, a vector search already run. Each catches a different shape of repetition, so layering them catches more than any one could alone.

Not all the cost of an AI system is in the model. The code that moves requests through queues, retries them and fans them out can become a bottleneck of its own at high volume, especially when it is written in a scripting language chosen for convenience. Those languages are good at orchestrating calls and poor at doing heavy work on every message at high throughput. Moving the throughput-bound parts into a compiled language, and leaving orchestration where it is, puts each job in the tool that suits it.

Request arrives
often near-identical to a recent one
Compute the embedding
text turned into a vector
Retrieve related material
a search over the vector index
Assemble and run the prompt
the expensive step, billed every time
Return the response
and then forget it
More than 60,000 requests a day, each one paying in full.
FigureThe stages a single AI request passes through, each of which costs time or money. On this platform none of them remembered anything, so a request nearly identical to one answered moments earlier paid for every stage again.
The constraint

The trouble looked like a question of accuracy or model choice, because those are the levers everyone knows. It was a question of cost architecture: nothing caught near-identical work before it reached a model. Tuning prompts on a system with no cache lowers the price of each redundant computation and leaves the redundancy exactly where it was.

measured after the cache layers landed
requests reaching the model−48%
average latency−44%
monthly cost−58%
Three separate figures rather than one, because they move for different reasons. Fewer calls cuts cost, and a cache hit returning without a model round-trip is what cuts latency.
Where it usually breaks

AI costs run away through repetition, and the usual fixes make each repeat cheaper while leaving the repeats in place.

A feature that works well in a pilot is billed per call. When usage grows, the bill grows with it in a straight line, because nothing in the design distinguishes a new question from one answered moments ago. Teams notice the bill and reach for the levers they know: shorter prompts, a smaller model, a cheaper provider. Each lowers the unit price. None reduces the number of units, and in many workloads a large share of those units are near-duplicates.

Caching brings failures of its own when it is added carelessly. A semantic cache with too loose a sense of sameness serves a confident answer to a question that differed in a way that mattered. A cache nobody measures can stop working after an unrelated change and go unnoticed, quietly sending everything to the model again. And a queue written for convenience can cap throughput long before the model does, so the system is slow for reasons that have nothing to do with AI.

01

Optimising the unit price

Prompts are shortened or models swapped. Each call is cheaper, the number of calls is unchanged, and the bill keeps growing with usage.

02

The cache with only one layer

A single exact-match cache catches byte-for-byte repeats. Requests that differ in wording, or that share only an intermediate step, still pay in full.

03

Semantic reuse applied everywhere

Requests that look alike but must be answered separately get a cached answer. The cost falls, and correctness quietly falls with it.

04

The unmeasured cache

A change upstream breaks the cache and the hit rate collapses. Without tracing, the first sign is the next invoice.

05

The queue that caps throughput

Per-message work in a scripting layer becomes the bottleneck at high volume, and the system is slow whatever the model does.

Optimise the prompts
Shorter prompts
a little cheaper per call
Every request still reaches a model
redundant work unchanged
Bill still grows with usage
savings capped by the price of a call
Optimise the architecture
Layered cache on the path
each layer catches a different repeat
Repeats turn back early
before they reach a model
Fewer calls, not cheaper calls
savings scale with the redundancy
Unit price versus number of units
The accuracy was already fine. The redundancy was where the bill lived.
FigureTwo ways to attack the same bill. Prompt tuning makes each call cheaper and leaves the number of calls alone, so cost still rises with usage. A layered cache stops near-identical work from reaching the model at all, which is where the savings compound.
The fork

The reflex, and the fix.

Road not taken

Optimise the prompts

Pull

It is the accessible lever, it needs no architectural change, and it shows an immediate improvement on every call.

Why not

It lowers the cost of work that should never have been repeated. The savings are capped by the price of a call, and the problem was the number of calls.

Road taken

Optimise the architecture around the models

Accepted

A layered cache across the request path, and a rewrite of the high-throughput queue in a compiled language.

Bought

Requests turning back at a cache layer before they ever reach a model.

Decision

Attack the redundancy and leave the unit price for later, because the redundancy is where the bill lives.

How it was built
01In-memory
›
02Semantic
›
03Embedding
›
04Prompt prefix
›
05Vector
›
06Response
01

A layered cache across the request path

In-memory, then semantic, then embedding, then prompt prefix, then vector lookup, then response. Each layer catches a different shape of near-identical work, and only what escapes all six reaches a model.

02

The queue rewritten for throughput

High-throughput queue processing moved to a compiled language. The scripting layer was kept only for inference orchestration, which is the job it is actually good at.

03

Tracing before and after

A cache that is not measured can be silently missing. A hit rate is the only evidence that the architecture is doing what it claims, so the request path was traced before the work began and again after it.

Inside the key decisions

What each choice cost, and what it bought.

AMeasuring the redundancy first

It is possible to add caches on instinct. Tracing the request path before building anything costs time up front and saves nothing by itself. It shows how much of the work is actually repeated and at which stage, and that sets the ceiling on what caching can achieve. The gains here are proportional to the near-identical work that exists, so the measurement is what made the architecture worth building.

BLayering caches along the request path

A single response cache is simpler and catches exact repeats. It misses everything else: requests worded differently, requests that share an embedding or a retrieval step, requests with a common prompt prefix. Six layers mean more moving parts and more to monitor. In return each kind of near-identical work is caught at the stage that recognises it, and only what escapes every layer reaches a model.

CChoosing semantic reuse per class of request

A semantic cache gives the largest savings and carries the largest risk, because it answers a new request with a result computed for a similar one. Turning it on everywhere would have maximised the hit rate. Choosing it deliberately for each class of request means some classes give up savings in order to stay exact. That is the trade that keeps a cost reduction from turning into a correctness problem.

DMoving the queue to a compiled language

Rewriting working code is expensive and carries risk of its own. The high-throughput queue was doing heavy per-message work in a scripting layer that suits orchestration and struggles with volume. Moving that work to a compiled language, and keeping the scripting layer for inference orchestration, put each part in the language that fits it. Together with the cache, it is what roughly doubled throughput.

In-memory cacheexact repeats, the cheapest catch
Semantic cachesame meaning, different words, chosen per request class
Embedding cachetext already turned into a vector
Prompt-prefix cachea shared opening already processed
Vector-lookup cachea search already run
Response cachea full answer already produced
Requests reaching the model fell by 48 percent.
FigureThe cache layers a request meets on its way to a model, in order. Each one catches a different shape of near-identical work, and a request that matches at any layer turns back there. Only what escapes all six is computed by a model.
How it was measured

A single headline number hides where a system fails. This work was scored on the dimensions that actually decide whether it holds in production, measured on real, held-out cases rather than the demo path.

Requests reaching the modelAverage and tail latencyMonthly inference costThroughput at fixed hardware
Fewer requests to the model48%
Lower average latency44%
Lower monthly inference cost58%
Gains scale with how much near-identical work exists, which is why it was measured first.
FigureThe measured result at more than 60,000 requests a day. Model traffic, average latency and monthly cost all fell together, because each was driven by the same redundant work. Throughput roughly doubled, and the savings paid for the project within weeks.
figures

Figures confirmed as proven. The rendered client quote associated with this engagement is deliberately not published.

What it produces
Without this discipline

Shorter prompts, a slightly cheaper call, and the same volume of redundant computation, with the bill still growing in step with usage.

This system

A layered cache across the request path plus a compiled-language rewrite of the high-throughput queue, so near-identical work is served from cache and the scripting layer is kept for inference orchestration. 48 percent fewer requests to the model, 44 percent lower average latency, 58 percent lower monthly inference cost, and roughly twice the throughput, with the savings paying for the project within weeks.

six cache layerscompiled workersscripting for orchestration onlymeasured hit rates
The operating envelope

What it owns, and what it hands to a person.

Handled with confidence
High-volume near-identical request patterns
Prompt, embedding, retrieval, and response reuse
Flagged for review
Request classes where semantic reuse is not acceptable
Out of scope by design
Workloads with genuinely unique requests
The honest limit

A semantic cache trades a small amount of exactness for a large amount of cost, and that trade has to be chosen deliberately for each class of request. Applied globally, it would be the wrong trade somewhere. The gains are proportional to how much near-identical work exists, which is why the measurement came before the architecture.

What it generalizes to

When a bill grows with usage and the accuracy is already fine, the cause is almost never the model. Measure how much of the work is repeated before optimising the price of doing it.

What to take from this

When accuracy is fine and the bill grows with usage, look for repeated work before looking at the model or the prompts.

Cheaper calls lower the unit price. Caching lowers the number of calls, and at high volume the number is usually where the money is.

Different caches catch different kinds of repetition, from exact repeats to shared intermediate steps, so layering them reaches further than any single cache.

Semantic caching trades exactness for cost. Decide per class of request where that trade is acceptable, and keep the rest exact.

A cache you do not measure can stop working without anyone noticing. Trace hit rates before and after every change.

How we engage

You have a system like this one.
Tell us where it stands.

Whether it is failing, not yet built, or about to meet a scale it has never seen, we can tell you what we see.

Start a conversation
mostafa@opulion.dev · Response within 24 hours · By inquiry